Skip to content

Commit

Permalink
MONGOID-5027 Rails 6.1 support (#4938)
Browse files Browse the repository at this point in the history
* Update mongoid.gemspec

Hi,
I use rails 6.1 and mongoid and i get error when i run bundle. So i update the dependency to activemodel <= 6.1 .

* allow everything less than 6.2

* test on Rails 6.1 and 6.0

* Update halted_callback_hook to take the name argument added in Rails 6.1.

See Rails commit 06dd162fb3ae67f202a0a59da1ce94317d0a3e22

* MONGOID-4731 use Errors#copy! to properly copy errors for Rails 6.1 (and also earlier versions)

* update compat tables for Rails 6.1

* bundle exec rake

Co-authored-by: Francel <[email protected]>
Co-authored-by: Oleg Pudeyev <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2020
1 parent 95c8fe5 commit 07c544a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ axes:
display_name: "Rails 5.2"
variables:
RAILS: "52"
- id: "60"
display_name: "Rails 6.0"
variables:
RAILS: "60"
- id: "i18n"
display_name: I18n version
values:
Expand Down Expand Up @@ -767,6 +771,18 @@ buildvariants:
- rhel70-small
tasks:
- name: "test"
- matrix_name: "rails-60"
matrix_spec:
driver: "current"
ruby: "ruby-2.7"
mongodb-version: "4.4"
topology: "standalone"
rails: '60'
display_name: "${rails}, ${driver}, ${mongodb-version}"
run_on:
- rhel70-small
tasks:
- name: "test"
#- matrix_name: "rails-master"
# matrix_spec: { driver: "current", ruby: "ruby-2.6", mongodb-version: "4.0", topology: "standalone", rails: 'master' }
# display_name: "${rails}, ${driver}, ${mongodb-version}"
Expand Down
18 changes: 18 additions & 0 deletions docs/tutorials/mongoid-installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,48 +227,63 @@ are supported by Mongoid.
:class: compatibility-large no-padding

* - Mongoid
- Rails 6.1
- Rails 6.0
- Rails 5.2
- Rails 5.1
- Rails 5.0
- Rails 4.2

* - 7.3
- |checkmark|
- |checkmark|
- |checkmark|
- |checkmark|
-
-

* - 7.2
- |checkmark| [#rails-6.1]_
- |checkmark|
- |checkmark|
- |checkmark|
-
-

* - 7.1
- |checkmark| [#rails-6.1]_
- |checkmark|
- |checkmark|
- |checkmark|
-
-

* - 7.0
- |checkmark| [#rails-6.1]_
- |checkmark| [#rails-6]_
- |checkmark|
- |checkmark|
-
-

* - 6.4
-
-
- |checkmark|
- |checkmark|
-
-

* - 6.3
-
-
- |checkmark|
- |checkmark|
-
-

* - 6.2
-
-
- |checkmark|
- |checkmark|
Expand Down Expand Up @@ -305,4 +320,7 @@ are supported by Mongoid.

.. [#rails-6] Rails 6.0 requires Mongoid 7.0.5 or later.

.. [#rails-6.1] Rails 6.1 requires Mongoid 7.0.12, 7.1.7 or 7.2.1 in the
respective 7.0, 7.1 and 7.2 stable branches.

.. include:: /includes/unicode-checkmark.rst
30 changes: 30 additions & 0 deletions gemfiles/rails_60.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
source 'https://rubygems.org'

gem 'rake'
gem 'actionpack', '~> 6.0.0'
gem 'activemodel', '~> 6.0.0'

group :development do
gem 'yard'
end

group :development, :test do
gem 'rspec-core', '~> 3.7'
end

group :test do
gem 'timecop'
gem 'rspec-retry'
gem 'benchmark-ips'
gem 'rspec-expectations', '~> 3.7', '>= 3.8.4'
gem 'rspec-mocks-diag', '~> 3.0'
gem 'fuubar'
gem 'rfc'
gem 'childprocess'
platforms :mri do
gem 'timeout-interrupt'
gem 'byebug'
end
end

gemspec path: '..'
5 changes: 3 additions & 2 deletions lib/mongoid/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ def becomes(klass)
became = klass.new(clone_document)
became._id = _id
became.instance_variable_set(:@changed_attributes, changed_attributes)
became.instance_variable_set(:@errors, ActiveModel::Errors.new(became))
became.errors.instance_variable_set(:@messages, errors.instance_variable_get(:@messages))
new_errors = ActiveModel::Errors.new(became)
new_errors.copy!(errors)
became.instance_variable_set(:@errors, new_errors)
became.instance_variable_set(:@new_record, new_record?)
became.instance_variable_set(:@destroyed, destroyed?)
became.changed_attributes[klass.discriminator_key] = self.class.discriminator_value
Expand Down
4 changes: 3 additions & 1 deletion lib/mongoid/interceptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ def child_callback_type(kind, child)
# document.halted_callback_hook(filter)
#
# @param [ Symbol ] filter The callback that halted.
# @param [ Symbol ] name The name of the callback that was halted
# (requires Rails 6.1+)
#
# @since 3.0.3
def halted_callback_hook(filter)
def halted_callback_hook(filter, name = nil)
@before_callback_halted = true
end

Expand Down
2 changes: 1 addition & 1 deletion mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.3"
s.required_rubygems_version = ">= 1.3.6"

s.add_dependency("activemodel", [">= 5.1", "<6.1"])
s.add_dependency("activemodel", [">= 5.1", "<6.2"])
s.add_dependency("mongo", ['>=2.10.5', '<3.0.0'])

s.add_development_dependency("bson", ['>=4.9.4', '<5.0.0'])
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
end
index.should be nil

Mrss::ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
Mrss::ChildProcessHelper.check_call(%w(bundle exec rake db:mongoid:create_indexes),
cwd: APP_PATH, env: env)

index = client['posts'].indexes.detect do |index|
Expand Down

0 comments on commit 07c544a

Please sign in to comment.