diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1092fc61b..42a71459f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,20 +25,10 @@ jobs: ruby: '2.7' # Rails > 7.1 supports Ruby >= 3.1 - gemfile: gemfiles/Gemfile-rails-main ruby: '3.0' # Rails > 7.1 supports Ruby >= 3.1 - - gemfile: Gemfile - env: DEVISE_ORM=mongoid - - gemfile: gemfiles/Gemfile-rails-main - env: DEVISE_ORM=mongoid - - gemfile: gemfiles/Gemfile-rails-7-0 - env: DEVISE_ORM=mongoid - - gemfile: gemfiles/Gemfile-rails-6-1 - env: DEVISE_ORM=mongoid - gemfile: gemfiles/Gemfile-rails-6-0 ruby: '3.2' - gemfile: gemfiles/Gemfile-rails-6-0 ruby: '3.1' - - gemfile: gemfiles/Gemfile-rails-6-0 - env: DEVISE_ORM=mongoid runs-on: ubuntu-latest env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ matrix.gemfile }} @@ -48,6 +38,6 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs bundle install and caches installed gems automatically - - uses: supercharge/mongodb-github-action@1.9.0 + - uses: supercharge/mongodb-github-action@1.10.0 if: ${{ matrix.env == 'DEVISE_ORM=mongoid' }} - run: bundle exec rake diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c9b55e3..dd4398a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * enhancements * Removed deprecations warning output for `Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION` (@soartec-lab) + * Reenable Mongoid test suite across all Rails 6+ versions, to ensure we continue supporting it. Changes to dirty tracking to support Mongoid 8.0+. [#5568](https://github.com/heartcombo/devise/pull/5568) Please check [4-stable](https://github.com/heartcombo/devise/blob/4-stable/CHANGELOG.md) for previous changes. diff --git a/Gemfile b/Gemfile index 722eb59a0..5d860d517 100644 --- a/Gemfile +++ b/Gemfile @@ -23,16 +23,9 @@ group :test do end platforms :ruby do - gem "sqlite3", "~> 1.4" + gem "sqlite3" end -# platforms :jruby do -# gem "activerecord-jdbc-adapter" -# gem "activerecord-jdbcsqlite3-adapter" -# gem "jruby-openssl" -# end - -# TODO: -# group :mongoid do -# gem "mongoid", "~> 4.0.0" -# end +group :mongoid do + gem "mongoid", "~> 8.1" +end diff --git a/Gemfile.lock b/Gemfile.lock index 92779c4c3..e351c7c6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,70 +20,71 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.1.0) - actionpack (= 7.1.0) - activesupport (= 7.1.0) + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.0) - actionpack (= 7.1.0) - activejob (= 7.1.0) - activerecord (= 7.1.0) - activestorage (= 7.1.0) - activesupport (= 7.1.0) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.0) - actionpack (= 7.1.0) - actionview (= 7.1.0) - activejob (= 7.1.0) - activesupport (= 7.1.0) + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.0) - actionview (= 7.1.0) - activesupport (= 7.1.0) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) nokogiri (>= 1.8.5) + racc rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.0) - actionpack (= 7.1.0) - activerecord (= 7.1.0) - activestorage (= 7.1.0) - activesupport (= 7.1.0) + actiontext (7.1.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.0) - activesupport (= 7.1.0) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.0) - activesupport (= 7.1.0) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (7.1.0) - activesupport (= 7.1.0) - activerecord (7.1.0) - activemodel (= 7.1.0) - activesupport (= 7.1.0) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) timeout (>= 0.4.0) - activestorage (7.1.0) - actionpack (= 7.1.0) - activejob (= 7.1.0) - activerecord (= 7.1.0) - activesupport (= 7.1.0) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) marcel (~> 1.0) - activesupport (7.1.0) + activesupport (7.1.3.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) @@ -93,16 +94,16 @@ GEM minitest (>= 5.1) mutex_m tzinfo (~> 2.0) - base64 (0.1.1) + base64 (0.2.0) bcrypt (3.1.19) - bigdecimal (3.1.4) + bigdecimal (3.1.7) + bson (5.0.0) builder (3.2.4) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - drb (2.1.1) - ruby2_keywords + date (3.3.4) + drb (2.2.1) erubi (1.12.0) faraday (2.7.11) base64 @@ -112,14 +113,14 @@ GEM globalid (1.2.1) activesupport (>= 6.1) hashie (5.0.0) - i18n (1.14.1) + i18n (1.14.4) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.8.1) + io-console (0.7.2) + irb (1.12.0) rdoc - reline (>= 0.3.8) + reline (>= 0.4.2) jwt (2.7.1) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -127,25 +128,32 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.20.0) + mini_portile2 (2.8.5) + minitest (5.22.3) mocha (2.1.0) ruby2_keywords (>= 0.0.5) + mongo (2.20.0) + bson (>= 4.14.1, < 6.0.0) + mongoid (8.1.5) + activemodel (>= 5.1, < 7.2, != 7.0.0) + concurrent-ruby (>= 1.0.5, < 2.0) + mongo (>= 2.18.0, < 3.0.0) + ruby2_keywords (~> 0.0.5) multi_xml (0.6.0) - mutex_m (0.1.2) - net-imap (0.4.1) + mutex_m (0.2.0) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4) + nio4r (2.7.1) + nokogiri (1.15.6) mini_portile2 (~> 2.8.2) racc (~> 1.4) oauth2 (2.0.9) @@ -168,36 +176,36 @@ GEM omniauth (>= 1.0, < 3.0) rack-openid (~> 1.4.0) orm_adapter (0.5.0) - psych (5.1.0) + psych (5.1.2) stringio - racc (1.7.1) - rack (2.2.8) + racc (1.7.3) + rack (3.0.10) rack-openid (1.4.2) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-protection (3.1.0) - rack (~> 2.2, >= 2.2.4) - rack-session (1.0.1) - rack (< 3) + rack-protection (3.0.6) + rack + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) - rack (< 3) - webrick - rails (7.1.0) - actioncable (= 7.1.0) - actionmailbox (= 7.1.0) - actionmailer (= 7.1.0) - actionpack (= 7.1.0) - actiontext (= 7.1.0) - actionview (= 7.1.0) - activejob (= 7.1.0) - activemodel (= 7.1.0) - activerecord (= 7.1.0) - activestorage (= 7.1.0) - activesupport (= 7.1.0) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) bundler (>= 1.15.0) - railties (= 7.1.0) + railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -205,20 +213,20 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.0) - actionpack (= 7.1.0) - activesupport (= 7.1.0) + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) irb rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) - rake (13.0.6) - rdoc (6.5.0) + rake (13.2.1) + rdoc (6.6.3.1) psych (>= 4.0.0) - reline (0.3.9) + reline (0.5.1) io-console (~> 0.5) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) @@ -227,12 +235,12 @@ GEM snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) - sqlite3 (1.6.6) + sqlite3 (1.6.7) mini_portile2 (~> 2.8.0) - stringio (3.0.8) - thor (1.2.2) + stringio (3.1.0) + thor (1.3.1) timecop (0.9.8) - timeout (0.4.0) + timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) version_gem (1.1.3) @@ -246,7 +254,7 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.12) + zeitwerk (2.6.13) PLATFORMS ruby @@ -254,6 +262,7 @@ PLATFORMS DEPENDENCIES devise! mocha (~> 2.1) + mongoid (~> 8.1) omniauth omniauth-facebook omniauth-oauth2 @@ -263,9 +272,9 @@ DEPENDENCIES rdoc responders (~> 3.1) rexml - sqlite3 (~> 1.4) + sqlite3 timecop webrat (= 0.7.3) BUNDLED WITH - 2.4.5 + 2.4.22 diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index b6afb6723..f42e3bf83 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -21,5 +21,9 @@ group :test do end platforms :ruby do - gem "sqlite3", "~> 1.4" + gem "sqlite3" +end + +group :mongoid do + gem "mongoid", "~> 7.5" end diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index bdebe1a76..34a3ab506 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -27,5 +27,9 @@ group :test do end platforms :ruby do - gem "sqlite3", "~> 1.4" + gem "sqlite3" +end + +group :mongoid do + gem "mongoid", "~> 7.5" end diff --git a/gemfiles/Gemfile-rails-7-0 b/gemfiles/Gemfile-rails-7-0 index ee474728e..6e0f47dff 100644 --- a/gemfiles/Gemfile-rails-7-0 +++ b/gemfiles/Gemfile-rails-7-0 @@ -23,16 +23,9 @@ group :test do end platforms :ruby do - gem "sqlite3", "~> 1.4" + gem "sqlite3" end -# platforms :jruby do -# gem "activerecord-jdbc-adapter" -# gem "activerecord-jdbcsqlite3-adapter" -# gem "jruby-openssl" -# end - -# TODO: -# group :mongoid do -# gem "mongoid", "~> 4.0.0" -# end +group :mongoid do + gem "mongoid", "~> 7.5" +end diff --git a/gemfiles/Gemfile-rails-main b/gemfiles/Gemfile-rails-main index 12930653e..eac553709 100644 --- a/gemfiles/Gemfile-rails-main +++ b/gemfiles/Gemfile-rails-main @@ -21,5 +21,9 @@ group :test do end platforms :ruby do - gem "sqlite3", "~> 1.4" + gem "sqlite3" +end + +group :mongoid do + gem "mongoid", "~> 8.1" end diff --git a/lib/devise/orm.rb b/lib/devise/orm.rb index 3e9852cd3..4c3cd6f49 100644 --- a/lib/devise/orm.rb +++ b/lib/devise/orm.rb @@ -5,10 +5,14 @@ def self.active_record?(model) end def self.included(model) - model.include DirtyTrackingMethods + if Devise::Orm.active_record?(model) + model.include DirtyTrackingActiveRecordMethods + else + model.include DirtyTrackingMongoidMethods + end end - module DirtyTrackingMethods + module DirtyTrackingActiveRecordMethods def devise_email_before_last_save email_before_last_save end @@ -33,5 +37,31 @@ def devise_respond_to_and_will_save_change_to_attribute?(attribute) respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?") end end + + module DirtyTrackingMongoidMethods + def devise_email_before_last_save + respond_to?(:email_previously_was) ? email_previously_was : email_was + end + + def devise_email_in_database + email_was + end + + def devise_saved_change_to_email? + respond_to?(:email_previously_changed?) ? email_previously_changed? : email_changed? + end + + def devise_saved_change_to_encrypted_password? + respond_to?(:encrypted_password_previously_changed?) ? encrypted_password_previously_changed? : encrypted_password_changed? + end + + def devise_will_save_change_to_email? + email_changed? + end + + def devise_respond_to_and_will_save_change_to_attribute?(attribute) + respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?") + end + end end end diff --git a/test/orm/mongoid.rb b/test/orm/mongoid.rb index d31bc4d21..5b8807f1f 100644 --- a/test/orm/mongoid.rb +++ b/test/orm/mongoid.rb @@ -10,6 +10,6 @@ class ActiveSupport::TestCase setup do - Mongoid.default_session.drop + Mongoid::Config.purge! end end diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index cb333819c..249126067 100644 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -39,8 +39,10 @@ class Application < Rails::Application Devise::SessionsController.layout "application" end - if Devise::Test.rails70? - config.active_record.legacy_connection_handling = false + if DEVISE_ORM == :active_record + if Devise::Test.rails70? + config.active_record.legacy_connection_handling = false + end end if Devise::Test.rails70_and_up?