title: How to test controller with Rspec - #show action
body: <p>I have a Batch model that <code>belongs_to</code> a User. User should only see their own Batches instances.</p>
  <p>For the <code>index</code> action, here is what I did:</p>
  <h3><code>Batch#index</code></h3>
  <pre><code>context &quot;GET index&quot; do
  
    it &quot;should get only users batches&quot; do
      FactoryGirl.create(:batch)
      batch = FactoryGirl.create(:batch)
      batch2 = FactoryGirl.create(:batch)            
      subject.current_user.batches &lt;&lt; batch
      get &quot;index&quot;
      assigns(:batches).should == subject.current_user.batches
      assigns(:batches).should_not include(batch2) 
    end
  
  end
  </code></pre>
  <p>For the <code>create</code> action, here is what I did:</p>
  <h3><code>Batch#create</code></h3>
  <pre><code>context &quot;POST create&quot; do
  
    it &quot;should save a users batch into current_user&quot; do
      batch = subject.current_user.batches.build(name: 'bla')
      put :create, batch
      subject.current_user.batches.should include(batch)
    end
  
    it &quot;should save a batch from other user into current_user&quot; do
      batch = subject.current_user.batches.build(name: 'bla')
      batch2 = FactoryGirl.create(:batch)
      put :create, batch
      subject.current_user.batches.should_not include(batch2)
    end
  
  end
  </code></pre>
  <p>However, I'm not sure how to test this behaviour in the <code>show</code> action. Here is what I'm doing:</p>
  <h3><code>Batch#show</code></h3>
  <pre><code>context &quot;GET show/:id&quot; do
  
    it &quot;should show batches from user&quot; do
      batch_params = FactoryGirl.build(:batch)
      batch = subject.current_user.batches.create(batch_params)
      get :show, id: batch.id
      response.should redirect_to(batch)
    end
  
    it &quot;should not show batches from other users&quot; do
      batch = subject.current_user.batches.create(name: 'bla')
      batch2 = FactoryGirl.create(:batch)
      get :show, id: batch2.id
      response.should redirect_to(:batches)
    end
  
  end
  </code></pre>
  <p>I'm getting the following failures:</p>
  <pre><code>Failures:
  
    1) BatchesController GET show/:id should not show batches from other users
       Failure/Error: response.should redirect_to(:batches)
         Expected response to be a &lt;:redirect&gt;, but was &lt;200&gt;
       # ./spec/controllers/batches_controller_spec.rb:66:in `block (3 levels) in &lt;top (required)&gt;'
  
    2) BatchesController GET show/:id should show batches from user
       Failure/Error: batch = subject.current_user.batches.create(batch_params)
       NoMethodError:
         undefined method `stringify_keys' for #&lt;Batch:0x00000005d0ef80&gt;
       # ./spec/controllers/batches_controller_spec.rb:58:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  <p>What am I doing wrong? How should I test this behaviour of <code>view</code> action?</p>