Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve this "positional arguments in functional tests has been deprecated" warning?

Rails 5 introduced some deprecation messages in my tests

DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.

Deprecated style:
get :show, { id: 1 }, nil, { notice: "This is a flash message" }

New keyword style:
get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
  session: nil # Can safely be omitted.

For this most part, these have been easy to resolve. The instructions are pretty clear in the message.

But I'm still getting these warnings for controller specs that test strong params.

How should the following be rewritten to prepare for Rails 5.1?

let(:user) { create :user }
it { is_expected.to permit( :name, :email ).for(:update, params: { id: user.to_param, user: valid_attributes } ).on(:user) }
like image 873
Andy Harvey Avatar asked Dec 20 '25 11:12

Andy Harvey


1 Answers

Try:

for(:update, params: { params: { id: user.to_param, user: valid_attributes } })  

It's ugly, but that worked for me.

Update: found my workaround and fix number here https://github.com/thoughtbot/shoulda-matchers/issues/867

like image 164
mate89 Avatar answered Dec 23 '25 00:12

mate89