Note that there are some explanatory texts on larger screens.

plurals
  1. PORSpec referencing child record in request spec
    primarykey
    data
    text
    <p>I'm new to RSpec and something I'm continuously having trouble with is understanding what records are in/out of scope. See below for an example. I'm creating a series of records via FactoryGirl. For example, I create a user and then in the before block I sign_in with that user. This always seems to work fine. But whenever I start trying to use records that are children of previously created records I seem to get into trouble. For example with group. Group requires a user and a group_type. Whenever I try to do something with these kind of records I hit a "Called id for nil" error. I've tried "puts group.name" and I can see that the group is being created but for some reason once the "visit group_path(group)" line executes the record no longer exists. I know I'm missing something pretty fundamental here. Appreciate any help as this has been driving me crazy.</p> <pre><code>describe "activities page" do let(:user) { FactoryGirl.create(:user) } let!(:group_type) { FactoryGirl.create(:group_type) } let!(:group) { FactoryGirl.create(:group, user: user, group_type: group_type) } before do sign_in user visit group_path(group) click_button "Check In" end </code></pre> <p>Error:</p> <pre><code>1) Activity pages activities page Failure/Error: visit group_path(group) RuntimeError: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id </code></pre> <p>Adding Group show method:</p> <pre><code>def show @group = Group.find(params[:id]) @members = @group.members.paginate(page: params[:page]) cookies[:group_id] = @group.id # Set Pusher chat @chat = Chat.find_by_group_id(@group.id) @user = current_user @messages = Message.find(:all, :conditions =&gt; ["chat_id = ?", @chat.id.to_s]) end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload