Forum: Ruby on Rails Factory girl associations and rspec

Posted by Shaban K. (shaban_k)
on 2012-11-12 11:01
Attachment: status_spec.rb (727 Bytes)
Attachment: factories.rb (287 Bytes)
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
Posted by akalyaev (Guest)
on 2012-11-13 10:48
(Received via mailing list)
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 :
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.