title: How to test controller with nested route?
body: <p>Please help solve this problem. I need a testing render template for the index action.</p>
  
  <p>routes.rb:</p>
  
  <pre><code>resources :users do
    resources :albums
  end
  </code></pre>
  
  <p>rake routes:</p>
  
  <pre><code>user_albums GET    /users/:user_id/albums(.:format)             albums#index
  </code></pre>
  
  <p>albums controller:</p>
  
  <pre><code>class AlbumsController &lt; ApplicationController
    before_action :set_album, only: [:show, :edit, :update, :destroy, :get_album_data]
  
    def index
      @user = User.find(params[:user_id])
      @albums = @user.albums.paginate(page: params[:page], :per_page =&gt; 6).order(created_at: :DESC)
      @album = Album.new
    end
  
    .........
    .........
  
    private
      def set_album
        @album = Album.find(params[:id])
      end
  
      def album_params
        params.require(:album).permit(:title, :description)
      end   
  end
  </code></pre>
  
  <p>albums_controller_spec.rb:</p>
  
  <pre><code>require 'spec_helper'
  
      describe AlbumsController do
        describe 'index action' do
          it 'render index template if user is found' do
            user = FactoryGirl.create(:user)
            get :index, { user_id: user.id }
            response.should render_template('index')
          end
        end
      end
  </code></pre>
  
  <p>factories:</p>
  
  <pre><code>FactoryGirl.define do
    factory :user do
      name 'qqq'
      sequence(:email){ |i| "use#{i}@ad.ad" }
      password 'qwerty'
      password_confirmation{ |u| u.password } 
    end
  end
  </code></pre>
  
  <p>I run it in the console:</p>
  
  <pre><code>rake db:reset RAILS_ENV=test
  rspec spec
  </code></pre>
  
  <p>Console displays the following error messages:</p>
  
  <pre><code>F.
  
  Failures:
  
    1) AlbumsController index action render index template if user is found
       Failure/Error: get :index, { user_id: user.id }
       NoMethodError:
         undefined method `get' for #&lt;RSpec::ExampleGroups::AlbumsController::IndexAction:0x000000067fc668&gt;
       # ./spec/controllers/albums_controller_spec.rb:7:in `block (3 levels) in &lt;top (required)&gt;'
  
  
  Finished in 0.13261 seconds (files took 1.91 seconds to load)
  2 examples, 1 failure
  
  Failed examples:
  
  rspec ./spec/controllers/albums_controller_spec.rb:5 # AlbumsController index action render index template if user is found
  </code></pre>
  
  <p>Please help me with the 'index' testing action</p>