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/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Akalyaev at Nov 13, 2012 at 9:47 am
    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 написал:
    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/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/FywsMksI6OEJ.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 12, '12 at 10:02a
activeNov 13, '12 at 9:47a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Shaban K.: 1 post Akalyaev: 1 post

People

Translate

site design / logo © 2021 Grokbase