2016-08-31 16 views
1

RSpecとスコープのルートに問題があります。ルートは、このRspec:スコープ化されたAPIルートの "No route matches"

 namespace :api do 
    scope module: :v1, constrains: ApiConstraints.new(version: 1, default: true) do 
     resources :users, except:[:new] 
    end 
end 

と仕様(スペック/コントローラ/ API/V1/users_controller_spec.rb)のように見えますが、次のようになります

ActionController::UrlGenerationError: 
    No route matches {:action=>"/api/users/57c6a615fd32bd11444f792f", :controller=>"api/v1/users"} 
:私はこのエラーを取得してい

RSpec.describe Api::V1::UsersController, type: :controller do 
    let(:current_user) { FactoryGirl.create(:user) } 

    before do 
    allow(controller).to receive(:authenticate_request!).and_return(true) 
    end 

    describe 'GET #show' do 
    it 'should show user details' do 
     get api_user_path(current_user.id.to_s), nil, { 'Accept' => 'application/app.com; version=1' } 
     expect(response).to have_http_status(:success) 
    end 
    end 
end 

私は "api_user_url"、:showなどを試しましたが、問題がその範囲にあると思います。マイルートを次のようになります。

   api_users GET  /api/users(.:format)    api/v1/users#index {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
        POST  /api/users(.:format)    api/v1/users#create {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
     edit_api_user GET  /api/users/:id/edit(.:format)  api/v1/users#edit {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
      api_user GET  /api/users/:id(.:format)   api/v1/users#show {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
        PATCH /api/users/:id(.:format)   api/v1/users#update {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
        PUT  /api/users/:id(.:format)   api/v1/users#update {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
        DELETE /api/users/:id(.:format)   api/v1/users#destroy {:constrains=>#<ApiConstraints:0x007fe6824dce50 @version=1, @default=true>} 
+0

何 '' api_user_path(CURRENT_USER)を取得についてすべきですか? –

+0

いいえ、それは "それ以外の"部分です。実際、それは私の最初のアプローチでした。あまりにも漠然として申し訳ありません! –

答えて

0

問題はタイプミスしていたルートに '制約'

cope module: :v1, constrains: ApiConstraints.new(version: 1, default: true) do 

をファイル '制約'

関連する問題