Skip to content

Commit

Permalink
Reenable tests with mongoid on Rails 5 and up
Browse files Browse the repository at this point in the history
Devise hasn't been tested with Mongoid since Rails version 5, only 4.x
was still running those tests.

This enables the tests again on all currently supported Rails versions,
with their respective mongoid supported versions. There were a couple of
minor tweaks to make it happen, namely:

* The way we were dropping the session before doesn't work in later
  versions so I changed back to calling `purge!` which appears to
  work fine. We used to call `Mongoid.purge!` but that changed in #4686.
* Some of the configs in the Rails test app were setting Active Record
  values when outside of the AR ORM tests, updated those to make sure
  they are not set when running mongoid ORM tests.
* The validations added to the shared admin code in tests were only
  checking for Rails version 5.1, but we need to use the same check for
  AR 5.1 that is used in code, otherwise it will try to use methods not
  available in mongoid there.

I also had to lock the sqlite3 gem on Rails 6 versions to 1.5.x, due to
it dropping support to Ruby 2.6 on v1.6+ now, and those Rails 6 versions
need to support that Ruby version.

Finally, I locked mongoid to v7.5+ but not allowing v8+ yet, there seems
to be some change to dirty attributes that I need to look into which is
making a handful of tests fail. For now, this should hopefully get us to
green as step 1.
  • Loading branch information
carlosantoniodasilva committed Apr 9, 2024
1 parent 21deb5c commit 58f7765
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 99 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* 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)
Expand Down
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ group :test do
end

platforms :ruby do
gem "sqlite3", "~> 1.4"
gem "sqlite3"
end

# platforms :jruby do
Expand All @@ -32,7 +32,7 @@ end
# gem "jruby-openssl"
# end

# TODO:
# group :mongoid do
# gem "mongoid", "~> 4.0.0"
# end
group :mongoid do
# gem "mongoid", "~> 8.1"
gem "mongoid", github: "mongodb/mongoid", branch: "8.1-stable"
end
149 changes: 82 additions & 67 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/mongodb/mongoid.git
revision: c12a285f78b291e4c62256aee0cc767f83fdc080
branch: 8.1-stable
specs:
mongoid (8.1.2)
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)

GIT
remote: https://github.com/rails/rails-controller-testing.git
revision: c203673f8011a7cdc2a8edf995ae6b3eec3417ca
Expand All @@ -20,70 +31,70 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.0)
actionpack (= 7.1.0)
activesupport (= 7.1.0)
actioncable (7.1.1)
actionpack (= 7.1.1)
activesupport (= 7.1.1)
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.1)
actionpack (= 7.1.1)
activejob (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
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.1)
actionpack (= 7.1.1)
actionview (= 7.1.1)
activejob (= 7.1.1)
activesupport (= 7.1.1)
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.1)
actionview (= 7.1.1)
activesupport (= 7.1.1)
nokogiri (>= 1.8.5)
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.1)
actionpack (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.0)
activesupport (= 7.1.0)
actionview (7.1.1)
activesupport (= 7.1.1)
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.1)
activesupport (= 7.1.1)
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.1)
activesupport (= 7.1.1)
activerecord (7.1.1)
activemodel (= 7.1.1)
activesupport (= 7.1.1)
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.1)
actionpack (= 7.1.1)
activejob (= 7.1.1)
activerecord (= 7.1.1)
activesupport (= 7.1.1)
marcel (~> 1.0)
activesupport (7.1.0)
activesupport (7.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -96,6 +107,7 @@ GEM
base64 (0.1.1)
bcrypt (3.1.19)
bigdecimal (3.1.4)
bson (4.15.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
Expand All @@ -115,11 +127,11 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
irb (1.8.1)
irb (1.8.2)
rdoc
reline (>= 0.3.8)
jwt (2.7.1)
loofah (2.21.3)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -133,6 +145,8 @@ GEM
minitest (5.20.0)
mocha (2.1.0)
ruby2_keywords (>= 0.0.5)
mongo (2.19.1)
bson (>= 4.14.1, < 5.0.0)
multi_xml (0.6.0)
mutex_m (0.1.2)
net-imap (0.4.1)
Expand Down Expand Up @@ -168,46 +182,46 @@ GEM
omniauth (>= 1.0, < 3.0)
rack-openid (~> 1.4.0)
orm_adapter (0.5.0)
psych (5.1.0)
psych (5.1.1)
stringio
racc (1.7.1)
rack (2.2.8)
rack (3.0.8)
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.1)
actioncable (= 7.1.1)
actionmailbox (= 7.1.1)
actionmailer (= 7.1.1)
actionpack (= 7.1.1)
actiontext (= 7.1.1)
actionview (= 7.1.1)
activejob (= 7.1.1)
activemodel (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
bundler (>= 1.15.0)
railties (= 7.1.0)
railties (= 7.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
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.1)
actionpack (= 7.1.1)
activesupport (= 7.1.1)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
Expand All @@ -218,7 +232,7 @@ GEM
psych (>= 4.0.0)
reline (0.3.9)
io-console (~> 0.5)
responders (3.1.0)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
Expand All @@ -227,7 +241,7 @@ 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)
Expand All @@ -254,6 +268,7 @@ PLATFORMS
DEPENDENCIES
devise!
mocha (~> 2.1)
mongoid!
omniauth
omniauth-facebook
omniauth-oauth2
Expand All @@ -263,7 +278,7 @@ DEPENDENCIES
rdoc
responders (~> 3.1)
rexml
sqlite3 (~> 1.4)
sqlite3
timecop
webrat (= 0.7.3)

Expand Down
6 changes: 5 additions & 1 deletion gemfiles/Gemfile-rails-6-0
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion gemfiles/Gemfile-rails-6-1
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 4 additions & 11 deletions gemfiles/Gemfile-rails-7-0
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions gemfiles/Gemfile-rails-main
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ end
platforms :ruby do
gem "sqlite3", "~> 1.4"
end

group :mongoid do
gem "mongoid", "~> 7.5"
end
2 changes: 1 addition & 1 deletion test/orm/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

class ActiveSupport::TestCase
setup do
Mongoid.default_session.drop
Mongoid::Config.purge!
end
end
6 changes: 4 additions & 2 deletions test/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 58f7765

Please sign in to comment.