[rspec-users] testing sessions

S Ahmed sahmed1020 at gmail.com
Sun Mar 4 13:40:57 UTC 2012


I want to test if my sessions logic works.

Session:
 id
 user_id

When I create a new session, if there was a previous session row in the db
with user_id = xxx, it should delete it first, then create a new row.

How could I test this scenerio?

So far I have:

require 'spec_helper'

describe Session do
  let(:session) { FactoryGirl.create(:session) }
  subject { session }
  it { should be_valid }

  describe "a new session" do
    s1 = FactoryGirl.build(:session)
    s2 = FactoryGirl.build(:session)
    user = FactoryGirl.create(:user)

    s1.user_id = user.id
    s1.save!
    #should change(Session, :count).by(1)
  end
end

I can't seem to figure out how to use the "should change Session count by
1".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120304/17372ba1/attachment.html>


More information about the rspec-users mailing list