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: 'bob@home.com',
time_zone: 'Melbourne'}}
end
test 'Update' do
patch(:update, update_attributes)
assert_equal 'bob@home.com', 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"=>"john@home.com",
"time_zone"=>"Sydney"}}
So the test assertions fail.
What am I doing wrong?