Skip to content

Commit

Permalink
Fix keyword arguments warnings on Ruby 2.7 (Sorcery#241)
Browse files Browse the repository at this point in the history
* CI against Ruby 2.7

* Fix keyword arguments warnings on Ruby 2.7

It fixes codes to match method signatures in rails and bcrypt.

## See also

- https://github.com/rails/rails/blob/v6.0.3/activerecord/lib/active_record/persistence.rb#L469
- https://github.com/rails/rails/blob/v6.0.3/activemodel/lib/active_model/callbacks.rb
- https://github.com/codahale/bcrypt-ruby/blob/v3.1.13/lib/bcrypt/password.rb#L43

* Update CHANGELOG.md

Co-authored-by: Josh Buker <[email protected]>
  • Loading branch information
sinsoku and joshbuker authored Jun 16, 2020
1 parent 65065ef commit f2c4fcf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rvm:
- 2.4.9
- 2.5.7
- 2.6.5
- 2.7.1

gemfile:
- Gemfile
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
## HEAD

* Fix ruby 2.7 deprecation warnings [#241](https://github.com/Sorcery/sorcery/pull/241)

## 0.15.0

* Fix brute force vuln due to callbacks no being ran [#235](https://github.com/Sorcery/sorcery/pull/235)
Expand Down
4 changes: 2 additions & 2 deletions lib/sorcery/adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def update_attributes(attrs)

def save(options = {})
mthd = options.delete(:raise_on_failure) ? :save! : :save
@model.send(mthd, options)
@model.send(mthd, **options)
end

def increment(field)
Expand All @@ -35,7 +35,7 @@ def define_field(name, type, options = {})
end

def define_callback(time, event, method_name, options = {})
@klass.send "#{time}_#{event}", method_name, options.slice(:if, :on)
@klass.send "#{time}_#{event}", method_name, **options.slice(:if, :on)
end

def find_by_oauth_credentials(provider, uid)
Expand Down
4 changes: 2 additions & 2 deletions spec/shared_examples/user_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def self.matches?(crypted, *tokens)

# password comparison is done using BCrypt::Password#==(raw_token), not String#==
bcrypt_password = BCrypt::Password.new(user.crypted_password)
allow(::BCrypt::Password).to receive(:create) do |token, cost:|
allow(::BCrypt::Password).to receive(:create) do |token, options = {}|
# need to use common BCrypt's salt when genarating BCrypt::Password objects
# so that any generated password hashes can be compared each other
::BCrypt::Engine.hash_secret(token, bcrypt_password.salt)
Expand All @@ -535,7 +535,7 @@ def self.matches?(crypted, *tokens)

# password comparison is done using BCrypt::Password#==(raw_token), not String#==
bcrypt_password = BCrypt::Password.new(user.crypted_password)
allow(::BCrypt::Password).to receive(:create) do |token, cost:|
allow(::BCrypt::Password).to receive(:create) do |token, options = {}|
# need to use common BCrypt's salt when genarating BCrypt::Password objects
# so that any generated password hashes can be compared each other
::BCrypt::Engine.hash_secret(token, bcrypt_password.salt)
Expand Down

0 comments on commit f2c4fcf

Please sign in to comment.