New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix can use options argument at DatabaseAuthenticatable#update_with_password #4935
Fix can use options argument at DatabaseAuthenticatable#update_with_password #4935
Conversation
Hello @ihatov08, thanks for the pull request. Would you mind to explain what issue this is solving? |
@tegon before [2] pry(main)> User.first.update_with_password({current_password: 'password'}, password: 'new_password')
ArgumentError: wrong number of arguments (given 2, expected 1)
from /usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/persistence.rb:423:in `update' after [2] pry(main)> User.first.update_with_password({current_password: 'password'}, password: 'new_password')
=> true |
Could you add a test for this change? We could add it closest to this one https://github.com/plataformatec/devise/blob/master/test/models/database_authenticatable_test.rb#L155 |
@ihatov08 Sorry for taking so long to reply to you. params.merge(options) Which for the code example you sent User.first.update_with_password({current_password: 'password'}, password: 'new_password') It will became a single hash: params.merge(options)
=> {current_password: 'password', password: 'new_password'} So, in the end, it's the same as if we pass one argument only: User.first.update_with_password(current_password: 'password', password: 'new_password') I thought this was weird so I took a look at the code history, and the Since we're supporting only Rails 4 and up, I think we can remove the WDYT? |
@tegon
I think it is better to remove the options argument as well as you. I think the second plan is good.
|
@ihatov08 Great! Do you want to change this PR to add the deprecation warning? def update_with_password(params, **options)
if options.present?
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
[Devise] The second argument of `DatabaseAuthenticatable#update_with_password`
(`options`) is deprecated and it will be removed in the next major version.
It was added to support a feature deprecated in Rails 4, so you can safely remove it
from your code.
DEPRECATION
end
...
end |
@tegon OK! |
@tegon Done! |
@ihatov08 Thanks! I just noticed that there's another method doing a similar thing below: -def update_with_password(params, **options)
+def update_with_password(params, *options) -update(params.merge(options))
+update(params, *options) -assign_attributes(params.merge(options))
+assign_attributes(params, *options) |
6a18c4b
to
a48e0e7
Compare
…able#update_with_password,#update_without_password
a48e0e7
to
06f03fa
Compare
@tegon Fixed! |
Thanks! |
No description provided.