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 Mar 30, 2023
1 parent 506eaf4 commit f0fad81
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 40 deletions.
16 changes: 1 addition & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ jobs:
ruby: '2.2'
- gemfile: Gemfile
ruby: '2.1'
- gemfile: Gemfile
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-main
ruby: '2.6'
- gemfile: gemfiles/Gemfile-rails-main
Expand All @@ -56,8 +54,6 @@ jobs:
ruby: '2.2'
- gemfile: gemfiles/Gemfile-rails-main
ruby: '2.1'
- gemfile: gemfiles/Gemfile-rails-main
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-6-1
ruby: '2.4'
- gemfile: gemfiles/Gemfile-rails-6-1
Expand All @@ -66,8 +62,6 @@ jobs:
ruby: '2.2'
- gemfile: gemfiles/Gemfile-rails-6-1
ruby: '2.1'
- 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
Expand All @@ -80,8 +74,6 @@ jobs:
ruby: '2.2'
- gemfile: gemfiles/Gemfile-rails-6-0
ruby: '2.1'
- gemfile: gemfiles/Gemfile-rails-6-0
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-5-2
ruby: '3.2'
- gemfile: gemfiles/Gemfile-rails-5-2
Expand All @@ -94,8 +86,6 @@ jobs:
ruby: '2.2'
- gemfile: gemfiles/Gemfile-rails-5-2
ruby: '2.1'
- gemfile: gemfiles/Gemfile-rails-5-2
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-5-1
ruby: '3.2'
- gemfile: gemfiles/Gemfile-rails-5-1
Expand All @@ -106,8 +96,6 @@ jobs:
ruby: '2.7'
- gemfile: gemfiles/Gemfile-rails-5-1
ruby: '2.1'
- gemfile: gemfiles/Gemfile-rails-5-1
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-5-0
ruby: '3.2'
- gemfile: gemfiles/Gemfile-rails-5-0
Expand All @@ -118,8 +106,6 @@ jobs:
ruby: '2.7'
- gemfile: gemfiles/Gemfile-rails-5-0
ruby: '2.1'
- gemfile: gemfiles/Gemfile-rails-5-0
env: DEVISE_ORM=mongoid
- gemfile: gemfiles/Gemfile-rails-4-2
ruby: '3.2'
- gemfile: gemfiles/Gemfile-rails-4-2
Expand Down Expand Up @@ -164,6 +150,6 @@ jobs:
bundler-cache: true # runs bundle install and caches installed gems automatically
bundler: ${{ env.BUNDLER_VERSION || 'default' }}
rubygems: ${{ env.RUBYGEMS_VERSION || 'latest' }}
- uses: supercharge/mongodb-github-action@1.3.0
- uses: supercharge/mongodb-github-action@1.9.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 @@ -4,6 +4,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
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ end
# gem "jruby-openssl"
# end

# TODO:
# group :mongoid do
# gem "mongoid", "~> 4.0.0"
# end
group :mongoid do
gem "mongoid", "~> 7.5"
end
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
bcrypt (3.1.18)
bson (4.15.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
crass (1.0.6)
Expand Down Expand Up @@ -115,6 +116,12 @@ GEM
mini_portile2 (2.8.1)
minitest (5.18.0)
mocha (1.16.1)
mongo (2.18.2)
bson (>= 4.14.1, < 5.0.0)
mongoid (7.5.2)
activemodel (>= 5.1, < 7.1, != 7.0.0)
mongo (>= 2.10.5, < 3.0.0)
ruby2_keywords (~> 0.0.5)
multi_xml (0.6.0)
net-imap (0.3.4)
date
Expand Down Expand Up @@ -224,6 +231,7 @@ PLATFORMS
DEPENDENCIES
devise!
mocha (~> 1.1)
mongoid (~> 7.5)
omniauth
omniauth-facebook
omniauth-oauth2
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile-rails-4-1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ platforms :ruby do
end

group :mongoid do
gem "mongoid", "~> 4.0"
gem "mongoid", "~> 5.0"
end

if RUBY_VERSION < "2.3.0"
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile-rails-4-2
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ platforms :ruby do
end

group :mongoid do
gem "mongoid", "~> 4.0"
gem "mongoid", "~> 5.0"
end

if RUBY_VERSION < "2.3.0"
Expand Down
7 changes: 3 additions & 4 deletions gemfiles/Gemfile-rails-5-0
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ platforms :ruby do
gem "sqlite3", "~> 1.3.6"
end

# TODO:
# group :mongoid do
# gem "mongoid", "~> 4.0.0"
# end
group :mongoid do
gem "mongoid", "~> 6.0"
end

if RUBY_VERSION < "2.3.0"
# We're getting version 2.2.0 which doesn't play nice with Ruby 2.2, using
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/Gemfile-rails-5-1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ platforms :ruby do
gem "sqlite3", "~> 1.3.6"
end

group :mongoid do
gem "mongoid", "~> 6.0"
end

if RUBY_VERSION < "2.3.0"
# We're getting version 2.2.0 which doesn't play nice with Ruby 2.2, using
# `Object.deprecate_constant` which isn't available.
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/Gemfile-rails-5-2
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ end
platforms :ruby do
gem "sqlite3", "~> 1.3.6"
end

group :mongoid do
gem "mongoid", "~> 6.0"
end
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", "~> 1.5.4"
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", "~> 1.5.4"
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
26 changes: 14 additions & 12 deletions test/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ class Application < Rails::Application
# config.assets.enabled = false

config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
rails_version = Gem::Version.new(Rails.version)
if DEVISE_ORM == :active_record &&
rails_version >= Gem::Version.new('4.2.0') &&
rails_version < Gem::Version.new('5.1.0')
config.active_record.raise_in_transactional_callbacks = true
end

# This was used to break devise in some situations
config.to_prepare do
Devise::SessionsController.layout "application"
end

# Remove the first check once Rails 5.0 support is removed.
if Devise::Test.rails52_and_up? && !Devise::Test.rails6_and_up?
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
end
if DEVISE_ORM == :active_record
rails_version = Gem::Version.new(Rails.version)

if rails_version >= Gem::Version.new('4.2.0') && rails_version < Gem::Version.new('5.1.0')
config.active_record.raise_in_transactional_callbacks = true
end

# Remove the first check once Rails 5.0 support is removed.
if Devise::Test.rails52_and_up? && !Devise::Test.rails6_and_up?
config.active_record.sqlite3.represent_boolean_as_integer = true
end

if Devise::Test.rails70?
config.active_record.legacy_connection_handling = false
if Devise::Test.rails70?
config.active_record.legacy_connection_handling = false
end
end
end
end

0 comments on commit f0fad81

Please sign in to comment.