0

I am trying to test, updating a User with devise strong params.

Strong params are set in the application controller:

devise_parameter_sanitizer.for(:account_update) do |u|
  u.permit(:email, :password, :password_confirmation, :current_password,
           :time_zone)
  end

The Registrations Controller update action is:

def update
  user_update_params = devise_parameter_sanitizer.sanitize(:account_update)
  ....
  @user = User.find(current_user.id)
  ....
  @user.update(user_update_params)
  ...
end

In my test I am passing update attributes:

def update_attributes
  {user: {email: '[email protected]',
  time_zone: 'Melbourne'}}
end

test 'Update' do
  patch(:update, update_attributes)
  assert_equal '[email protected]', assigns(:user).email
  assert_equal 'false', assigns(:user).use_weighted_rates
end

The problem is the Devise::ParameterSanitizer object @params reflects the @user attributes, not the update_attributes:

@params=
  {"user"=>
    {"email"=>"[email protected]",
     "time_zone"=>"Sydney"}}

So the test assertions fail.

What am I doing wrong?

1 Answers1

1

The problem was the user was not signed in. I was creating a user using: get(:create) to create a user on the create action of the controller. I changed this is to sign_in create(:user) using a user factory and all good.