Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5818 Support Rails 8 #5876

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
42 changes: 36 additions & 6 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -586,6 +586,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
Expand Down Expand Up @@ -727,6 +731,32 @@ buildvariants:
tasks:
- name: "test"

- matrix_name: "rails-8"
matrix_spec:
ruby: ["ruby-3.2"]
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-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: "bson-min"
matrix_spec:
driver: [bson-min]
Expand Down Expand Up @@ -776,12 +806,12 @@ buildvariants:

- matrix_name: app-tests-rails-7
matrix_spec:
ruby: ["ruby-3.1", "ruby-3.2"]
ruby: ["ruby-3.2"]
driver: ["current"]
mongodb-version: '6.0'
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-20.04
display_name: "app tests ${driver}, ${ruby}, ${rails}"
tasks:
Expand All @@ -794,7 +824,7 @@ buildvariants:
mongodb-version: '5.0'
topology: standalone
app-tests: yes
rails: ['6.0']
rails: ['6.0', '6.1']
os: rhel80
display_name: "app tests ${driver}, ${ruby}, ${rails}"
tasks:
Expand Down
4 changes: 4 additions & 0 deletions .evergreen/config/axes.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,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
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/config/commands.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 30 additions & 4 deletions .evergreen/config/variants.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ buildvariants:
tasks:
- name: "test"

- matrix_name: "rails-8"
matrix_spec:
ruby: ["ruby-3.2"]
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-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: "bson-min"
matrix_spec:
driver: [bson-min]
Expand Down Expand Up @@ -160,12 +186,12 @@ buildvariants:

- matrix_name: app-tests-rails-7
matrix_spec:
ruby: ["ruby-3.1", "ruby-3.2"]
ruby: ["ruby-3.2"]
driver: ["current"]
mongodb-version: '6.0'
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-20.04
display_name: "app tests ${driver}, ${ruby}, ${rails}"
tasks:
Expand All @@ -178,7 +204,7 @@ buildvariants:
mongodb-version: '5.0'
topology: standalone
app-tests: yes
rails: ['6.0']
rails: ['6.0', '6.1']
os: rhel80
display_name: "app tests ${driver}, ${ruby}, ${rails}"
tasks:
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ examples
.env
.env.private*
build
rspec.xml
4 changes: 4 additions & 0 deletions gemfiles/rails-6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails-6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails-7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails-7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails-7.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 14 additions & 0 deletions gemfiles/rails-8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# rubocop:todo all
source 'https://rubygems.org'

gem 'actionpack', '8.0.0.beta1'
gem 'activemodel', '8.0.0.beta1'

group :test do
gem 'activejob', '8.0.0.beta1'
end
gemspec path: '..'

require_relative './standard'

standard_dependencies
4 changes: 4 additions & 0 deletions gemfiles/rails-master.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def standard_dependencies
end

group :test do
gem 'activejob'
gem 'timecop'
gem 'rspec-retry'
gem 'benchmark-ips'
Expand Down
2 changes: 1 addition & 1 deletion mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down
44 changes: 24 additions & 20 deletions spec/integration/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 18 additions & 12 deletions spec/mongoid/railties/bson_object_id_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading