Skip to content

Commit 94c6d5f

Browse files
committed
Remove deprecation on _changed? methods
1 parent 0fe308e commit 94c6d5f

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed

lib/devise/models/confirmable.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,26 @@ def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
261261
generate_confirmation_token
262262
end
263263

264-
def postpone_email_change?
265-
postpone = self.class.reconfirmable &&
266-
email_changed? &&
267-
!@bypass_confirmation_postpone &&
268-
self.email.present? &&
269-
(!@skip_reconfirmation_in_callback || !self.email_was.nil?)
270-
@bypass_confirmation_postpone = false
271-
postpone
264+
if Devise.rails51?
265+
def postpone_email_change?
266+
postpone = self.class.reconfirmable &&
267+
will_save_change_to_email? &&
268+
!@bypass_confirmation_postpone &&
269+
self.email.present? &&
270+
(!@skip_reconfirmation_in_callback || !self.email_in_database.nil?)
271+
@bypass_confirmation_postpone = false
272+
postpone
273+
end
274+
else
275+
def postpone_email_change?
276+
postpone = self.class.reconfirmable &&
277+
email_changed? &&
278+
!@bypass_confirmation_postpone &&
279+
self.email.present? &&
280+
(!@skip_reconfirmation_in_callback || !self.email_was.nil?)
281+
@bypass_confirmation_postpone = false
282+
postpone
283+
end
272284
end
273285

274286
def reconfirmation_required?

lib/devise/models/database_authenticatable.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,24 @@ def password_digest(password)
165165
Devise::Encryptor.digest(self.class, password)
166166
end
167167

168-
def send_email_changed_notification?
169-
self.class.send_email_changed_notification && email_changed?
168+
if Devise.rails51?
169+
def send_email_changed_notification?
170+
self.class.send_email_changed_notification && saved_change_to_email?
171+
end
172+
else
173+
def send_email_changed_notification?
174+
self.class.send_email_changed_notification && email_changed?
175+
end
170176
end
171177

172-
def send_password_change_notification?
173-
self.class.send_password_change_notification && encrypted_password_changed?
178+
if Devise.rails51?
179+
def send_password_change_notification?
180+
self.class.send_password_change_notification && saved_change_to_encrypted_password?
181+
end
182+
else
183+
def send_password_change_notification?
184+
self.class.send_password_change_notification && encrypted_password_changed?
185+
end
174186
end
175187

176188
module ClassMethods

lib/devise/models/recoverable.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,24 @@ def send_reset_password_instructions_notification(token)
9797
send_devise_notification(:reset_password_instructions, token, {})
9898
end
9999

100-
def clear_reset_password_token?
101-
encrypted_password_changed = respond_to?(:encrypted_password_changed?) && encrypted_password_changed?
102-
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
103-
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
100+
if Devise.rails51?
101+
def clear_reset_password_token?
102+
encrypted_password_changed = respond_to?(:will_save_change_to_encrypted_password?) && will_save_change_to_encrypted_password?
103+
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
104+
respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?")
105+
end
106+
107+
authentication_keys_changed || encrypted_password_changed
104108
end
109+
else
110+
def clear_reset_password_token?
111+
encrypted_password_changed = respond_to?(:encrypted_password_changed?) && encrypted_password_changed?
112+
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
113+
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
114+
end
105115

106-
authentication_keys_changed || encrypted_password_changed
116+
authentication_keys_changed || encrypted_password_changed
117+
end
107118
end
108119

109120
module ClassMethods

lib/devise/models/validatable.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ def self.included(base)
2727

2828
base.class_eval do
2929
validates_presence_of :email, if: :email_required?
30-
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
31-
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
30+
if Devise.rails51?
31+
validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
32+
validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email?
33+
else
34+
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
35+
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
36+
end
3237

3338
validates_presence_of :password, if: :password_required?
3439
validates_confirmation_of :password, if: :password_required?

test/rails_app/lib/shared_admin.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ module SharedAdmin
88
allow_unconfirmed_access_for: 2.weeks, reconfirmable: true
99

1010
validates_length_of :reset_password_token, minimum: 3, allow_blank: true
11-
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
11+
if Devise.rails51?
12+
validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
13+
else
14+
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
15+
end
1216
end
1317

1418
def raw_confirmation_token

0 commit comments

Comments
 (0)