Skip to content

Commit

Permalink
fix: Adjust usage of has_secure_token without a token attr
Browse files Browse the repository at this point in the history
The behaviour of this method was changed in Rails 7.1, and now
it'll search for a `token` attr in the initialization of the record
instead of the creation. To stay with the same behaviour as before
it's necessary to pass a new argument `on: : create` to the method.
  • Loading branch information
matsales28 committed Oct 27, 2023
1 parent 4cb1dab commit d2b2d55
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@

it 'does not match when missing a token column' do
create_table(:users)
invalid_model = define_model_class(:User) { has_secure_token }
invalid_model = if rails_version >= 7.1
define_model_class(:User) { has_secure_token(on: :create) }
else
define_model_class(:User) { has_secure_token }
end

expected_message =
'Expected User to have :token as a secure token but the following ' \
Expand Down Expand Up @@ -125,9 +129,11 @@

it 'does not match when missing a column for a custom attribute' do
create_table(:users)
invalid_model = define_model_class(:User) do
has_secure_token(:auth_token)
end
invalid_model = if rails_version >= 7.1
define_model_class(:User) { has_secure_token(:auth_token, on: :create) }
else
define_model_class(:User) { has_secure_token(:auth_token) }
end

expected_message =
'Expected User to have :auth_token as a secure token but the ' \
Expand Down

0 comments on commit d2b2d55

Please sign in to comment.