diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 099260abd8..e05fb5acf9 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -259,7 +259,7 @@ functions: "upload test results": - command: attach.xunit_results params: - file: ./src/tmp/rspec.xml + file: ./src/rspec.xml "run tests": - command: shell.exec @@ -308,7 +308,7 @@ post: # Removed, causing timeouts # - func: "upload working dir" - func: "upload mo artifacts" - #- func: "upload test results" + # - func: "upload test results" - func: "upload test results to s3" task_groups: @@ -596,6 +596,10 @@ axes: display_name: "Rails 7.2" variables: RAILS: "7.2" + - id: "8.0" + display_name: "Rails 8.0" + variables: + RAILS: "8.0" - id: "test-i18n-fallbacks" display_name: Test i18n fallbacks @@ -735,19 +739,6 @@ buildvariants: tasks: - name: "test" -- matrix_name: "rails-7" - matrix_spec: - ruby: ["ruby-3.3"] - driver: ["current"] - mongodb-version: "6.0" - topology: "standalone" - rails: ['7.0', '7.1', '7.2'] - os: ubuntu-22.04 - fle: helper - display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" - tasks: - - name: "test" - - matrix_name: "bson-min" matrix_spec: driver: [bson-min] @@ -770,6 +761,44 @@ buildvariants: tasks: - name: "test" +- matrix_name: "rails-master" + matrix_spec: + ruby: ["ruby-3.2"] + driver: ["current"] + mongodb-version: "7.0" + topology: "standalone" + rails: ['master'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" + +- matrix_name: "rails-8" + matrix_spec: + ruby: ["ruby-3.3"] + driver: ["current"] + mongodb-version: "7.0" + topology: "standalone" + rails: ['8.0'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" + +- matrix_name: "rails-7" + matrix_spec: + ruby: ["ruby-3.3"] + driver: ["current"] + mongodb-version: "6.0" + topology: "standalone" + rails: ['7.0', '7.1', '7.2'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" - matrix_name: "rails-6" matrix_spec: @@ -795,27 +824,40 @@ buildvariants: tasks: - name: "test" +- matrix_name: app-tests-rails-8 + matrix_spec: + ruby: ["ruby-3.2", "ruby-3.3"] + driver: ["current"] + mongodb-version: '7.0' + topology: standalone + app-tests: yes + rails: ['8.0'] + os: ubuntu-22.04 + display_name: "app tests ${driver}, ${ruby}, ${rails}" + tasks: + - name: "test" + - matrix_name: app-tests-rails-7 matrix_spec: - ruby: ["ruby-3.1", "ruby-3.2", "ruby-3.3"] + ruby: ["ruby-3.2", "ruby-3.3"] driver: ["current"] mongodb-version: '7.0' topology: standalone app-tests: yes - rails: ['6.1', '7.0', '7.1', '7.2'] + rails: ['7.0', '7.1', '7.2'] os: ubuntu-22.04 display_name: "app tests ${driver}, ${ruby}, ${rails}" tasks: - name: "test" -- matrix_name: app-tests-rails-6-0 +- matrix_name: app-tests-rails-6 matrix_spec: - ruby: ["ruby-3.0"] + ruby: ["ruby-2.7"] driver: ["current"] mongodb-version: '5.0' topology: standalone app-tests: yes - rails: ['6.0'] + rails: ['6.0', '6.1'] os: ubuntu-20.04 display_name: "app tests ${driver}, ${ruby}, ${rails}" tasks: diff --git a/.evergreen/config/axes.yml.erb b/.evergreen/config/axes.yml.erb index aca37995b5..708b312362 100644 --- a/.evergreen/config/axes.yml.erb +++ b/.evergreen/config/axes.yml.erb @@ -223,6 +223,10 @@ axes: display_name: "Rails 7.2" variables: RAILS: "7.2" + - id: "8.0" + display_name: "Rails 8.0" + variables: + RAILS: "8.0" - id: "test-i18n-fallbacks" display_name: Test i18n fallbacks diff --git a/.evergreen/config/commands.yml.erb b/.evergreen/config/commands.yml.erb index 1410abdd8f..e9e45448b7 100644 --- a/.evergreen/config/commands.yml.erb +++ b/.evergreen/config/commands.yml.erb @@ -233,7 +233,7 @@ functions: "upload test results": - command: attach.xunit_results params: - file: ./src/tmp/rspec.xml + file: ./src/rspec.xml "run tests": - command: shell.exec @@ -282,7 +282,7 @@ post: # Removed, causing timeouts # - func: "upload working dir" - func: "upload mo artifacts" - #- func: "upload test results" + # - func: "upload test results" - func: "upload test results to s3" task_groups: diff --git a/.evergreen/config/variants.yml.erb b/.evergreen/config/variants.yml.erb index a6848736c1..5d72b4a631 100644 --- a/.evergreen/config/variants.yml.erb +++ b/.evergreen/config/variants.yml.erb @@ -109,19 +109,6 @@ buildvariants: tasks: - name: "test" -- matrix_name: "rails-7" - matrix_spec: - ruby: ["ruby-3.3"] - driver: ["current"] - mongodb-version: "6.0" - topology: "standalone" - rails: ['7.0', '7.1', '7.2'] - os: ubuntu-22.04 - fle: helper - display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" - tasks: - - name: "test" - - matrix_name: "bson-min" matrix_spec: driver: [bson-min] @@ -144,6 +131,44 @@ buildvariants: tasks: - name: "test" +- matrix_name: "rails-master" + matrix_spec: + ruby: ["ruby-3.2"] + driver: ["current"] + mongodb-version: "7.0" + topology: "standalone" + rails: ['master'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" + +- matrix_name: "rails-8" + matrix_spec: + ruby: ["ruby-3.3"] + driver: ["current"] + mongodb-version: "7.0" + topology: "standalone" + rails: ['8.0'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" + +- matrix_name: "rails-7" + matrix_spec: + ruby: ["ruby-3.3"] + driver: ["current"] + mongodb-version: "6.0" + topology: "standalone" + rails: ['7.0', '7.1', '7.2'] + os: ubuntu-22.04 + fle: helper + display_name: "${rails}, ${driver}, ${mongodb-version} (FLE ${fle})" + tasks: + - name: "test" - matrix_name: "rails-6" matrix_spec: @@ -169,27 +194,40 @@ buildvariants: tasks: - name: "test" +- matrix_name: app-tests-rails-8 + matrix_spec: + ruby: ["ruby-3.2", "ruby-3.3"] + driver: ["current"] + mongodb-version: '7.0' + topology: standalone + app-tests: yes + rails: ['8.0'] + os: ubuntu-22.04 + display_name: "app tests ${driver}, ${ruby}, ${rails}" + tasks: + - name: "test" + - matrix_name: app-tests-rails-7 matrix_spec: - ruby: ["ruby-3.1", "ruby-3.2", "ruby-3.3"] + ruby: ["ruby-3.2", "ruby-3.3"] driver: ["current"] mongodb-version: '7.0' topology: standalone app-tests: yes - rails: ['6.1', '7.0', '7.1', '7.2'] + rails: ['7.0', '7.1', '7.2'] os: ubuntu-22.04 display_name: "app tests ${driver}, ${ruby}, ${rails}" tasks: - name: "test" -- matrix_name: app-tests-rails-6-0 +- matrix_name: app-tests-rails-6 matrix_spec: - ruby: ["ruby-3.0"] + ruby: ["ruby-2.7"] driver: ["current"] mongodb-version: '5.0' topology: standalone app-tests: yes - rails: ['6.0'] + rails: ['6.0', '6.1'] os: ubuntu-20.04 display_name: "app tests ${driver}, ${ruby}, ${rails}" tasks: diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index b48d881f40..ce5db1a1cb 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -118,6 +118,6 @@ if test -f tmp/rspec-all.json; then mv tmp/rspec-all.json tmp/rspec.json fi -python3 -m mtools.mlaunch.mlaunch stop --dir "$dbdir" +python3 -m mtools.mlaunch.mlaunch stop --dir "$dbdir" || true exit ${test_status} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 401792de6d..73b62b7f3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,28 +50,38 @@ jobs: driver: stable gemfile: gemfiles/driver_stable.gemfile experimental: false - - mongodb: '6.0' - ruby: ruby-3.1 + - mongodb: '7.0' + ruby: ruby-3.3 + topology: server + os: ubuntu-22.04 + task: test + driver: current + rails: '8.0' + fle: helper + gemfile: gemfiles/rails-8.0.gemfile + experimental: false + - mongodb: '7.0' + ruby: ruby-3.2 topology: server os: ubuntu-20.04 task: test driver: current - rails: '7.0' + rails: '7.2' fle: helper - gemfile: gemfiles/rails-7.0.gemfile + gemfile: gemfiles/rails-7.2.gemfile experimental: false - - mongodb: '6.0' - ruby: ruby-3.1 + - mongodb: '7.0' + ruby: ruby-3.2 topology: server os: ubuntu-20.04 task: test driver: current - rails: '6.1' + rails: '7.1' fle: helper - gemfile: gemfiles/rails-6.1.gemfile + gemfile: gemfiles/rails-7.1.gemfile experimental: false - - mongodb: '6.0' - ruby: ruby-3.0 + - mongodb: '7.0' + ruby: ruby-3.1 topology: server os: ubuntu-20.04 task: test @@ -80,6 +90,16 @@ jobs: fle: helper gemfile: gemfiles/rails-7.0.gemfile experimental: false + - mongodb: '6.0' + ruby: ruby-3.1 + topology: server + os: ubuntu-20.04 + task: test + driver: current + rails: '6.1' + fle: helper + gemfile: gemfiles/rails-6.1.gemfile + experimental: false - mongodb: '6.0' ruby: ruby-3.0 topology: server @@ -126,22 +146,6 @@ jobs: driver: current gemfile: Gemfile experimental: false - - mongodb: '4.0' - ruby: ruby-2.7 - topology: replica_set - os: ubuntu-20.04 - task: test - driver: current - gemfile: Gemfile - experimental: false - - mongodb: '3.6' - ruby: ruby-2.7 - topology: replica_set - os: ubuntu-20.04 - task: test - driver: current - gemfile: Gemfile - experimental: false steps: - name: repo checkout diff --git a/.gitignore b/.gitignore index 1eed0ec2d8..fed26118c1 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ examples .env .env.private* build +rspec.xml diff --git a/gemfiles/rails-6.0.gemfile b/gemfiles/rails-6.0.gemfile index c8962320a3..35923a605f 100644 --- a/gemfiles/rails-6.0.gemfile +++ b/gemfiles/rails-6.0.gemfile @@ -4,6 +4,10 @@ source 'https://rubygems.org' gem 'actionpack', '~> 6.0' gem 'activemodel', '~> 6.0' +group :test do + gem 'activejob', '~> 6.0' +end + gemspec path: '..' require_relative './standard' diff --git a/gemfiles/rails-6.1.gemfile b/gemfiles/rails-6.1.gemfile index 06a654ecd8..8e5a896766 100644 --- a/gemfiles/rails-6.1.gemfile +++ b/gemfiles/rails-6.1.gemfile @@ -4,6 +4,9 @@ source 'https://rubygems.org' gem 'actionpack', '~> 6.1' gem 'activemodel', '~> 6.1' +group :test do + gem 'activejob', '~> 6.1' +end gemspec path: '..' require_relative './standard' diff --git a/gemfiles/rails-7.0.gemfile b/gemfiles/rails-7.0.gemfile index c5bf14c395..5afbe8c57a 100644 --- a/gemfiles/rails-7.0.gemfile +++ b/gemfiles/rails-7.0.gemfile @@ -4,6 +4,9 @@ source 'https://rubygems.org' gem 'actionpack', '~> 7.0' gem 'activemodel', '~> 7.0' +group :test do + gem 'activejob', '~> 7.0' +end gemspec path: '..' require_relative './standard' diff --git a/gemfiles/rails-7.1.gemfile b/gemfiles/rails-7.1.gemfile index 3b6debf9ec..3019a83ef3 100644 --- a/gemfiles/rails-7.1.gemfile +++ b/gemfiles/rails-7.1.gemfile @@ -4,6 +4,9 @@ source 'https://rubygems.org' gem 'actionpack', '~> 7.1' gem 'activemodel', '~> 7.1' +group :test do + gem 'activejob', '~> 7.1' +end gemspec path: '..' require_relative './standard' diff --git a/gemfiles/rails-7.2.gemfile b/gemfiles/rails-7.2.gemfile index bdc1062ec6..8319573653 100644 --- a/gemfiles/rails-7.2.gemfile +++ b/gemfiles/rails-7.2.gemfile @@ -4,6 +4,9 @@ source 'https://rubygems.org' gem 'actionpack', '~> 7.2' gem 'activemodel', '~> 7.2' +group :test do + gem 'activejob', '~> 7.2' +end gemspec path: '..' require_relative './standard' diff --git a/gemfiles/rails-8.0.gemfile b/gemfiles/rails-8.0.gemfile new file mode 100644 index 0000000000..8ae63613bc --- /dev/null +++ b/gemfiles/rails-8.0.gemfile @@ -0,0 +1,14 @@ +# rubocop:todo all +source 'https://rubygems.org' + +gem 'actionpack', '8.0.0.rc2' +gem 'activemodel', '8.0.0.rc2' + +group :test do + gem 'activejob', '8.0.0.rc2' +end +gemspec path: '..' + +require_relative './standard' + +standard_dependencies diff --git a/gemfiles/rails-master.gemfile b/gemfiles/rails-master.gemfile index 3dc51cbd13..e3a93d9c04 100644 --- a/gemfiles/rails-master.gemfile +++ b/gemfiles/rails-master.gemfile @@ -4,6 +4,10 @@ source 'https://rubygems.org' gem 'actionpack', git: 'https://github.com/rails/rails' gem 'activemodel', git: 'https://github.com/rails/rails' +group :test do + gem 'activejob', git: 'https://github.com/rails/rails' +end + gemspec path: '..' require_relative './standard' diff --git a/gemfiles/standard.rb b/gemfiles/standard.rb index e89e2ae899..0285630e2e 100644 --- a/gemfiles/standard.rb +++ b/gemfiles/standard.rb @@ -36,7 +36,6 @@ def standard_dependencies end group :test do - gem 'activejob' gem 'timecop' gem 'rspec-retry' gem 'benchmark-ips' diff --git a/lib/mongoid/serializable.rb b/lib/mongoid/serializable.rb index 1e14ea8e67..d1c115b7ca 100644 --- a/lib/mongoid/serializable.rb +++ b/lib/mongoid/serializable.rb @@ -13,13 +13,13 @@ module Serializable included do class << self - # Note that this intentionally only delegates :include_root_in_json - # and not :include_root_in_json? - delegating the latter produces - # wrong behavior. - # Also note that this intentionally uses the ActiveSupport delegation - # functionality and not the Ruby standard library one. - # See https://jira.mongodb.org/browse/MONGOID-4849. - delegate :include_root_in_json, to: ::Mongoid + def include_root_in_json + @include_root_in_json.nil? ? ::Mongoid.include_root_in_json : @include_root_in_json + end + + def include_root_in_json=(new_value) + @include_root_in_json = new_value + end end end diff --git a/lib/mongoid/traversable.rb b/lib/mongoid/traversable.rb index e53bfe164c..fbcaeee622 100644 --- a/lib/mongoid/traversable.rb +++ b/lib/mongoid/traversable.rb @@ -105,7 +105,11 @@ def discriminator_key=(value) if value Mongoid::Fields::Validators::Macro.validate_field_name(self, value) value = value.to_s - super + if defined?(::ActiveSupport::ClassAttribute) + ::ActiveSupport::ClassAttribute.redefine(self, 'discriminator_key', value) + else + super + end else # When discriminator key is set to nil, replace the class's definition # of the discriminator key reader (provided by class_attribute earlier) @@ -119,7 +123,7 @@ class << self # an existing field. # This condition also checks if the class has any descendants, because # if it doesn't then it doesn't need a discriminator key. - return unless !fields.key?(discriminator_key) && !descendants.empty? + return if fields.key?(discriminator_key) || descendants.empty? default_proc = -> { self.class.discriminator_value } field(discriminator_key, default: default_proc, type: String) diff --git a/mongoid.gemspec b/mongoid.gemspec index 91eab31938..0c8fb6b4e9 100644 --- a/mongoid.gemspec +++ b/mongoid.gemspec @@ -38,7 +38,7 @@ Gem::Specification.new do |s| # Ruby 3.0 requires ActiveModel 6.0 or higher. # activemodel 7.0.0 cannot be used due to Class#descendants issue # See: https://github.com/rails/rails/pull/43951 - s.add_dependency("activemodel", ['>=5.1', '<7.3', '!= 7.0.0']) + s.add_dependency("activemodel", ['>=5.1', '<8.1', '!= 7.0.0']) s.add_dependency("mongo", ['>=2.18.0', '<3.0.0']) s.add_dependency("concurrent-ruby", ['>= 1.0.5', '< 2.0']) diff --git a/spec/integration/active_job_spec.rb b/spec/integration/active_job_spec.rb index 462e5cb336..8488c7abae 100644 --- a/spec/integration/active_job_spec.rb +++ b/spec/integration/active_job_spec.rb @@ -2,31 +2,35 @@ # rubocop:todo all require 'spec_helper' -require 'active_job' -require 'mongoid/railties/bson_object_id_serializer' +begin + require 'active_job' + require 'mongoid/railties/bson_object_id_serializer' -describe 'ActiveJob Serialization' do - skip unless defined?(ActiveJob) + describe 'ActiveJob Serialization' do + skip unless defined?(ActiveJob) - class TestBsonObjectIdSerializerJob < ActiveJob::Base - def perform(*args) - args + class TestBsonObjectIdSerializerJob < ActiveJob::Base + def perform(*args) + args + end end - end - let(:band) do - Band.create! - end + let(:band) do + Band.create! + end - before do - ActiveJob::Serializers.add_serializers( - [::Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer] - ) - end + before do + ActiveJob::Serializers.add_serializers( + [::Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer] + ) + end - it 'serializes and deserializes BSON::ObjectId' do - expect do - TestBsonObjectIdSerializerJob.perform_later(band.id) - end.not_to raise_error + it 'serializes and deserializes BSON::ObjectId' do + expect do + TestBsonObjectIdSerializerJob.perform_later(band.id) + end.not_to raise_error + end end +rescue LoadError + RSpec.context.skip 'This test requires active_job' end diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index ca67b44cd7..127763fecf 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -36,6 +36,8 @@ def insert_rails_gem_version(cmd) context 'demo application' do context 'sinatra' do it 'runs' do + skip 'https://jira.mongodb.org/browse/MONGOID-5826' + clone_application( 'https://github.com/mongoid/mongoid-demo', subdir: 'sinatra-minimal', @@ -55,6 +57,8 @@ def insert_rails_gem_version(cmd) context 'rails-api' do it 'runs' do + skip 'https://jira.mongodb.org/browse/MONGOID-5826' + clone_application( 'https://github.com/mongoid/mongoid-demo', subdir: 'rails-api', @@ -172,7 +176,7 @@ def install_rails if (rails_version = SpecConfig.instance.rails_version) == 'master' else check_call(%w(gem list)) - check_call(%w(gem install rails --no-document -v) + ["~> #{rails_version}.0"]) + check_call(%w(gem install rails --no-document --force -v) + ["~> #{rails_version}.0"]) end end @@ -319,6 +323,10 @@ def adjust_app_gemfile(rails_version: SpecConfig.instance.rails_version) end def adjust_rails_defaults(rails_version: SpecConfig.instance.rails_version) + if !rails_version.match?(/^\d+\.\d+$/) + # This must be pre-release version, we trim it + rails_version = rails_version.split('.')[0..1].join('.') + end if File.exist?('config/application.rb') lines = IO.readlines('config/application.rb') lines.each do |line| diff --git a/spec/mongoid/railties/bson_object_id_serializer_spec.rb b/spec/mongoid/railties/bson_object_id_serializer_spec.rb index 694e14232c..d90e0577ef 100644 --- a/spec/mongoid/railties/bson_object_id_serializer_spec.rb +++ b/spec/mongoid/railties/bson_object_id_serializer_spec.rb @@ -2,23 +2,29 @@ # rubocop:todo all require 'spec_helper' -require 'active_job' -require 'mongoid/railties/bson_object_id_serializer' -describe 'Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer' do +begin + require 'active_job' + require 'mongoid/railties/bson_object_id_serializer' - let(:serializer) { Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer.instance } - let(:object_id) { BSON::ObjectId.new } - describe '#serialize' do - it 'serializes BSON::ObjectId' do - expect(serializer.serialize(object_id)).to be_a(String) + describe 'Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer' do + + let(:serializer) { Mongoid::Railties::ActiveJobSerializers::BsonObjectIdSerializer.instance } + let(:object_id) { BSON::ObjectId.new } + + describe '#serialize' do + it 'serializes BSON::ObjectId' do + expect(serializer.serialize(object_id)).to be_a(String) + end end - end - describe '#deserialize' do - it 'deserializes BSON::ObjectId' do - expect(serializer.deserialize(serializer.serialize(object_id))).to eq(object_id) + describe '#deserialize' do + it 'deserializes BSON::ObjectId' do + expect(serializer.deserialize(serializer.serialize(object_id))).to eq(object_id) + end end end +rescue LoadError + RSpec.context.skip 'This test requires active_job' end