I am trying to write a controller specification (crash) for a parameter containing a slash:
it "accepts parameters with a forward slash" do
get :show, id: 'foo/bar'
expect(response).to be_success
expect(response).to render_template('show')
end
This should fail because there is no corresponding route for "/ products / foo / bar":
resources :products, only: [:index, :show]
However, it passes because the parameter foo/baris encoded by the URL before the request sends it to the controller:
# products_controller.rb
def show
Rails.logger.debug(request.env['PATH_INFO'])
end
gives this in test.log:
I, [2015-05-13T13:33:16.410943 #12962] INFO -- : Processing by ProductsController#show as HTML
I, [2015-05-13T13:33:16.411029 #12962] INFO -- : Parameters: {"id"=>"foo/bar"}
...
D, [2015-05-13T13:33:16.412717 #12962] DEBUG -- : /products/foo%2Fbar/
I, [2015-05-13T13:33:16.413885 #12962] INFO -- : Completed 200 OK in 3ms (Views: 0.9ms | ActiveRecord: 0.2ms)
Note the URL encoded %2Finstead /in the raw request. If you do not finish the request object, how can I make an rspec request getwithout encoding it for the request parameter for me?
Thilo source
share