Factory girl associations and rspec

41 views
Skip to first unread message

Shaban K.

unread,
Nov 12, 2012, 5:01:55 AM11/12/12
to rubyonra...@googlegroups.com
Hi,

I am trying to test factory girl associations basically I have a user
model and status model , what is supposed to happen is a user has many
statuses and a status belongs to a user. I have tried to model this in
factory girl as you can see in the files. When I try to execute the test
I get
Failure/Error: visit("/users/#{user.id}/statuses/#{status.id}")
ActiveRecord::RecordNotFound:
Couldn't find Status with id=2 [WHERE `statuses`.`user_id` = 1]
when I run the request spec for statuses. What should I change to get
this test to pass.

Shaban

Attachments:
http://www.ruby-forum.com/attachment/7873/status_spec.rb
http://www.ruby-forum.com/attachment/7874/factories.rb


--
Posted via http://www.ruby-forum.com/.

akalyaev

unread,
Nov 13, 2012, 4:47:32 AM11/13/12
to rubyonra...@googlegroups.com
That's because users are actually different. To fix this you need to pass a user record into the FactoryGirl's create method.

let(:user) {FactoryGirl.create(:user)}
let(:status) {FactoryGirl.create(:status, user: user)}

Regards,
Anton

понедельник, 12 ноября 2012 г., 14:03:19 UTC+4 пользователь Ruby-Forum.com User написал:
Reply all
Reply to author
Forward
0 new messages