mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-08 22:37:57 -05:00
Fix added tests for sign_in_after_reset_password per resource class
We can't just "swap" those model properties, as that sets instance vars on the classes that get reverted to their "previous" value, which ends up leaving the instance vars set as `nil`. However, our logic for those model/class properties actually checks for `defined?` as a way to override them, and delegates up to `Devise` global config if they are not defined, so leaving instance vars back with `nil` values isn't enough, we need to actually remove them. This introduces a new test helper specifically for overriding those model configs so that we can do proper cleanup.
This commit is contained in:
@@ -223,7 +223,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
end
|
||||
|
||||
test 'does not sign in user automatically after changing its password if resource_class.sign_in_after_reset_password is false' do
|
||||
swap User, sign_in_after_reset_password: false do
|
||||
swap_model_config User, sign_in_after_reset_password: false do
|
||||
create_user
|
||||
request_forgot_password
|
||||
reset_password
|
||||
@@ -237,7 +237,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
|
||||
test 'sign in user automatically after changing its password if resource_class.sign_in_after_reset_password is true' do
|
||||
swap Devise, sign_in_after_reset_password: false do
|
||||
swap User, sign_in_after_reset_password: true do
|
||||
swap_model_config User, sign_in_after_reset_password: true do
|
||||
create_user
|
||||
request_forgot_password
|
||||
reset_password
|
||||
|
||||
@@ -73,6 +73,17 @@ class ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def swap_model_config(model, new_values)
|
||||
new_values.each do |key, value|
|
||||
model.send :"#{key}=", value
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
new_values.each_key do |key|
|
||||
model.remove_instance_variable :"@#{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def clear_cached_variables(options)
|
||||
if options.key?(:case_insensitive_keys) || options.key?(:strip_whitespace_keys)
|
||||
Devise.mappings.each do |_, mapping|
|
||||
|
||||
Reference in New Issue
Block a user