Add `Devise.activerecord51?`
Active Record changed it's public API, so we should check against its version instead of Rails as it is possible to use Rails 5.1 with Mongoid, which still has the older Dirty API. However, this patch does not fixes a scenario where an app has both Active Record and Mongoid loaded. It should be fixed by either normalizing the Mongoid/ActiveRecord API or replacing the conditional method definitions with a shim layer that abstracts this away.
This commit is contained in:
parent
399774af69
commit
3e1c9e343c
|
@ -294,6 +294,10 @@ module Devise
|
|||
Rails.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
def self.activerecord51? # :nodoc:
|
||||
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
# Default way to set up Devise. Run rails generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
|
|
|
@ -253,7 +253,7 @@ module Devise
|
|||
generate_confirmation_token && save(validate: false)
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
|
@ -271,7 +271,7 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable &&
|
||||
will_save_change_to_email? &&
|
||||
|
|
|
@ -137,7 +137,7 @@ module Devise
|
|||
encrypted_password[0,29] if encrypted_password
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
# Send notification to user when email changes.
|
||||
def send_email_changed_notification
|
||||
send_devise_notification(:email_changed, to: email_before_last_save)
|
||||
|
@ -165,7 +165,7 @@ module Devise
|
|||
Devise::Encryptor.digest(self.class, password)
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
def send_email_changed_notification?
|
||||
self.class.send_email_changed_notification && saved_change_to_email?
|
||||
end
|
||||
|
@ -175,7 +175,7 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
def send_password_change_notification?
|
||||
self.class.send_password_change_notification && saved_change_to_encrypted_password?
|
||||
end
|
||||
|
|
|
@ -97,7 +97,7 @@ module Devise
|
|||
send_devise_notification(:reset_password_instructions, token, {})
|
||||
end
|
||||
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
def clear_reset_password_token?
|
||||
encrypted_password_changed = respond_to?(:will_save_change_to_encrypted_password?) && will_save_change_to_encrypted_password?
|
||||
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
||||
|
|
|
@ -27,7 +27,7 @@ module Devise
|
|||
|
||||
base.class_eval do
|
||||
validates_presence_of :email, if: :email_required?
|
||||
if Devise.rails51?
|
||||
if Devise.activerecord51?
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
|
||||
validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email?
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue