ruby-on-railsrspecruby-on-rails-5high-voltage

DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only keyword arguments in future Rails versions


I am getting deprecation warning for my tests but I do not understand how should I refactor my tests in order to be compliant with future rails versions. I get this from multiple tests so attached the most simple example testing that hight_voltage static pages exist.

Here is my test >

describe HighVoltage::PagesController, '#show' do
  %w(about conditions).each do |page|
    context "on GET to /pages/#{page}" do
      before do
        get :show, id: page
      end

      it { should respond_with(:success) }
      it { should render_template(page) }
    end
  end
end

And here is the deprecation warning.

*DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only
keyword arguments in future Rails versions.

Examples:

get :show, params: { id: 1 }, session: { user_id: 1 }
process :update, method: :post, params: { id: 1 }
 (called from block (4 levels) in <top (required)> at /Users/kimmo/Documents/care-city/spec/controllers/pages_controller_spec.rb:5)
DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only
keyword arguments in future Rails versions.

Solution

  • You have to add "params: " for your params

    get :show, params: {id: page}
    

    you can pass more keywords for headers and other config for the request

    EDIT: notice that the actual error you copypasted already tells you to do that

    "Examples:

    get :show, params: { id: 1 }, session: { user_id: 1 }

    process :update, method: :post, params: { id: 1 }"