File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Clear secure password cache if password is set to ` nil `
2
+
3
+ Before:
4
+
5
+ user.password = 'something'
6
+ user.password = nil
7
+
8
+ user.password # => 'something'
9
+
10
+ Now:
11
+
12
+ user.password = 'something'
13
+ user.password = nil
14
+
15
+ user.password # => nil
16
+
17
+ * Markus Doits*
18
+
1
19
## Rails 7.0.0.alpha2 (September 15, 2021) ##
2
20
3
21
* No changes.
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ def initialize(attribute)
94
94
95
95
define_method ( "#{ attribute } =" ) do |unencrypted_password |
96
96
if unencrypted_password . nil?
97
+ instance_variable_set ( "@#{ attribute } " , nil )
97
98
self . public_send ( "#{ attribute } _digest=" , nil )
98
99
elsif !unencrypted_password . empty?
99
100
instance_variable_set ( "@#{ attribute } " , unencrypted_password )
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ class SecurePasswordTest < ActiveModel::TestCase
91
91
assert_equal [ "doesn't match Password" ] , @user . errors [ :password_confirmation ]
92
92
end
93
93
94
+ test "resetting password to nil clears the password cache" do
95
+ @user . password = "password"
96
+ @user . password = nil
97
+ assert_nil @user . password
98
+ end
99
+
94
100
test "update an existing user with validation and no change in password" do
95
101
assert @existing_user . valid? ( :update ) , "user should be valid"
96
102
end
You can’t perform that action at this time.
0 commit comments