2
我對我的用戶資源有以下路由,並且在我的規範中出現錯誤,指出路由不存在。子域約束提高在規格中找不到的路由
更新:測試似乎通過時,我自己運行規範。但是,當我運行整個套件時不行。
規格:
describe 'POST #create' do
let(:perform_request) do
post :create, user: FactoryGirl.attributes_for(:user), subdomain: 'api', format: :json
end
it 'should be successful' do
perform_request
response.should be_a_success
end
it 'should create the user' do
expect { perform_request }.to change { User.count }
end
it 'should assign the device to the user' do
expect { perform_request }.to change { controller.send(:current_device).reload.user }
end
end
途徑:
Server::Application.routes.draw do
scope module: :api, constraints: { subdomain: 'api' }, as: :api, defaults: { format: :json } do
resource :user do
resource :emergency_contact, controller: :contacts, only: [:create, :show, :update, :destroy]
resources :activities, only: [:create, :show, :update, :destroy, :index]
end
get '/*path' => 'application#invalid_url'
end
end
錯誤:
1) Api::UsersController POST #create should be successful
Failure/Error: post :create, user: FactoryGirl.attributes_for(:user), subdomain: 'api', format: :json
ActionController::RoutingError:
No route matches {:user=>{:first_name=>"Josh", :last_name=>"Stokes", :phone_number=>"(555) 555-1003", :password=>"qwertyuiop", :password_confirmation=>"qwertyuiop"}, :subdomain=>"api", :format=>:json, :controller=>"api/users", :action=>"create"}
# ./spec/controllers/api/users_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
# ./spec/controllers/api/users_controller_spec.rb:14:in `block (3 levels) in <top (required)>'