From 09b6b46ea4374f0204a12043038d0fb88af93f09 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 31 Mar 2023 11:41:23 -0300 Subject: [PATCH] Update dirty tracking to support Mongoid 8.0+ It appears Mongoid 8.0+ slightly [changed dirty tracking] behavior to more closely match Active Model/Record, however they haven't yet introduced the [new methods] that match the latest API, that seems to be coming on Mongoid 8.1 only. The changes here try to accommodate for that by determining which "attribute_changed?" method to call depending on whether the "*_previously_*" version exists. Newer versions of AR (5.1+) will continue to use the new API / methods, whereas previous versions and Mongoid 8.0+ will use these tweaked versions. No behavior should change for AR, but it will hopefully support Mongoid 8.0+ now. [changed dirty tracking] https://github.com/mongodb/mongoid/pull/5092 [new methods] https://github.com/mongodb/mongoid/pull/5440 --- CHANGELOG.md | 4 ++-- Gemfile | 2 +- Gemfile.lock | 6 +++--- gemfiles/Gemfile-rails-main | 2 +- lib/devise/orm.rb | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2861cdb6f..4428f0485b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### Unreleased - +* enhancements + * Reenable Mongoid test suite across all Rails 5+ versions, to ensure we continue supporting it. Changes to dirty tracking to support Mongoid 8.0+. [#5568](https://github.com/heartcombo/devise/pull/5568) ### 4.9.1 - 2023-03-31 @@ -8,7 +9,6 @@ * Allow resource class scopes to override the global configuration for `sign_in_after_reset_password` behaviour. [#5429](https://github.com/heartcombo/devise/pull/5429) [@mattr](https://github.com/mattr) * Refactor conditional dirty tracking logic to a centralized module to simplify usage throughout the codebase. [#5575](https://github.com/heartcombo/devise/pull/5575) * Improve support for Devise in apps with Active Record and Mongoid ORMs loaded, so it does not incorrectly uses new Active Record dirty tracking APIs with a Mongoid Devise model. [#5576](https://github.com/heartcombo/devise/pull/5576) - * Reenable Mongoid test suite across all Rails 5+ versions, to ensure we continue supporting it. (Note: testing support with Mongoid up to 7.x, not 8 yet.) [#5568](https://github.com/heartcombo/devise/pull/5568) * bug fixes * Failure app will respond with configured `redirect_status` instead of `error_status` if the recall app returns a redirect status (300..399) [#5573](https://github.com/heartcombo/devise/pull/5573) diff --git a/Gemfile b/Gemfile index d3750442f7..926b1ad064 100644 --- a/Gemfile +++ b/Gemfile @@ -33,5 +33,5 @@ end # end group :mongoid do - gem "mongoid", "~> 7.5" + gem "mongoid", "~> 8.0" end diff --git a/Gemfile.lock b/Gemfile.lock index ecb7e44b20..7fc5fe25eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,9 +118,9 @@ GEM mocha (1.16.1) mongo (2.18.2) bson (>= 4.14.1, < 5.0.0) - mongoid (7.5.2) + mongoid (8.0.3) activemodel (>= 5.1, < 7.1, != 7.0.0) - mongo (>= 2.10.5, < 3.0.0) + mongo (>= 2.18.0, < 3.0.0) ruby2_keywords (~> 0.0.5) multi_xml (0.6.0) net-imap (0.3.4) @@ -231,7 +231,7 @@ PLATFORMS DEPENDENCIES devise! mocha (~> 1.1) - mongoid (~> 7.5) + mongoid (~> 8.0) omniauth omniauth-facebook omniauth-oauth2 diff --git a/gemfiles/Gemfile-rails-main b/gemfiles/Gemfile-rails-main index 857631a462..48189bc7d3 100644 --- a/gemfiles/Gemfile-rails-main +++ b/gemfiles/Gemfile-rails-main @@ -25,5 +25,5 @@ platforms :ruby do end group :mongoid do - gem "mongoid", "~> 7.5" + gem "mongoid", "~> 8.0" end diff --git a/lib/devise/orm.rb b/lib/devise/orm.rb index 75baf2be50..ae586c4bbb 100644 --- a/lib/devise/orm.rb +++ b/lib/devise/orm.rb @@ -44,7 +44,7 @@ def devise_respond_to_and_will_save_change_to_attribute?(attribute) module DirtyTrackingOldMethods def devise_email_before_last_save - email_was + respond_to?(:email_previously_was) ? email_previously_was : email_was end def devise_email_in_database @@ -52,11 +52,11 @@ def devise_email_in_database end def devise_saved_change_to_email? - email_changed? + respond_to?(:email_previously_changed?) ? email_previously_changed? : email_changed? end def devise_saved_change_to_encrypted_password? - encrypted_password_changed? + respond_to?(:encrypted_password_previously_changed?) ? encrypted_password_previously_changed? : encrypted_password_changed? end def devise_will_save_change_to_email?