Compliance with user restrictions? the method was never called
I tried to restrict some routing to Ajax only, and write routes.rb
and lib/constraints/only_ajax_request.rb
like below.
routes.rb
resources :orders, except: [:destroy] do
collection do
post 'login_or_sign_up', to: 'orders#login_or_sign_up', constraints: OnlyAjaxRequest.new
end
end
Library / restrictions / only_ajax_request.rb
class OnlyAjaxRequest
def matches?(request)
request.xhr?
end
end
but this specification failed.
specs / controllers / orders_controllers_spec.rb
describe 'POST #login_or_sign_up' do
let(:user) { create(:login_user) }
it 'only ajax' do
post :login_or_sign_up, user: { email: user.email,
password: user.password }
expect(response.status).to eq(404)
end
end
I have set a breakpoint in OnlyAjaxRequest,
Class OnlyAjaxRequest
def matches?(request)
binding.pry
request.xhr?
end
end
but it was never called.
how to set restrictions for mail routing?
+3
source to share
No one has answered this question yet
Check out similar questions: