2014-08-05 6 views
0

각 컨트롤러에 대한 요청을 테스트하지 않아도되는 응용 프로그램 (API)이 있습니다. items_controller_spec.rb에서RSpec 중첩 된 경로와 일치하는 경로가 없습니다.

resources :items do 
    resources :offers, only: [:index, :create, :destroy, :update] do 
     put :accept, on: :member 
    end 
    end 

다음 작품 잘 :

require 'spec_helper' 

describe ItemsController do 
    user = FactoryGirl.create(:user) 
    item = user.items.create() 


    context "GET #index" do 

    it 'returns unauthorised - 401 when not logged in' do 
     get :index 
     # test for the 401 unauthorised 
     expect(response.status).to eq(401) 
    end 

    it 'returns 200 and users items when logged in' do 
     get :index , { access_token: user.token } 

     expect(response.status).to eq(200) 
    end 

    end 
end 

같은 코드가 작동하고 다음과 같은 오류 발생하지 않습니다 offers_controller_spec.rb에서 :

을 나는 다음과 같은 경로를 가지고
1) OffersController GET #index shows something 
    Failure/Error: get :index 
    ActionController::UrlGenerationError: 
     No route matches {:action=>"index", :controller=>"offers"} 
    # ./spec/controllers/offers_controller_spec.rb:8:in `block (3 levels) in <top (required)>' 

경로가 중첩되어 있기 때문에 요청을 다른 방식으로 테스트해야합니까? 여러 가지 시도를했지만 아무 것도 작동하지 않는 것 같습니다. 모든 포인터 크게 감사하겠습니다.

답변

1

중첩되어 있기 때문에 특정 항목에 대한 쿠폰을 받아야합니다.

그래서 당신은

get :index, :item_id => Item.first.id 

(또는 Item.first 대신에, 일부 특정 항목의 기록은 당신이에 대해 테스트 할)

을 할 필요가