From 63cf3be1f967e7aaafa9fd0fd1d87885e9d31def Mon Sep 17 00:00:00 2001 From: Daniel Ferraz Date: Wed, 24 Jun 2020 17:07:40 -0300 Subject: [PATCH 01/11] Updates to make it mongoid v6 compatible. - In Mongoid v6, the Mongoid::Relations::Options::COMMON const is now frozen. So we cannot include the :versioned option in it anymore. This commit hacks the :validate! method to remove the :versioned from the list of options being validated. - It also updates the usage of Mongoid::Clients::Options#with method due to interface change. --- lib/mongoid/core_ext/relations/options.rb | 7 ++++++- lib/mongoid/core_ext/versioning.rb | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/mongoid/core_ext/relations/options.rb b/lib/mongoid/core_ext/relations/options.rb index 46753e5..f2e5730 100644 --- a/lib/mongoid/core_ext/relations/options.rb +++ b/lib/mongoid/core_ext/relations/options.rb @@ -1,7 +1,12 @@ module Mongoid module Relations module Options - COMMON << :versioned + alias_method :validate_without_versioned!, :validate! + + def validate!(options) + options_without_versioned = options.except(:versioned) + validate_without_versioned!(options_without_versioned) + end end end end diff --git a/lib/mongoid/core_ext/versioning.rb b/lib/mongoid/core_ext/versioning.rb index 3e07ba6..8837af8 100644 --- a/lib/mongoid/core_ext/versioning.rb +++ b/lib/mongoid/core_ext/versioning.rb @@ -139,10 +139,11 @@ def previous_revision mongo_session.options _loading_revision do - self.class.unscoped - .with(options) - .where(_id: id) - .any_of({ version: version }, version: nil).first + self.class.with(options) do |m| + m.unscoped + .where(_id: id) + .any_of({ version: version }, version: nil).first + end end end From 61583620f11ead7d3917f663b9ce31379805fec7 Mon Sep 17 00:00:00 2001 From: Rodrigo RA Date: Sat, 16 Jul 2022 10:50:58 -0300 Subject: [PATCH 02/11] Add GH actions against multiple ruby/mongoid --- .github/workflows/build.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c0baf54 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build +on: [push, pull_request] +jobs: + test: + strategy: + fail-fast: false + matrix: + ruby: ['2.7'] + mongoid: ['4', '5', '6'] + mongodb: ['4.4', '5.0'] + + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} / Mongo ${{ matrix.mongodb }} / Mongoid ${{ matrix.mongoid }} + + steps: + - uses: actions/checkout@v3 + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.7.0 + with: + mongodb-version: ${{ matrix.mongodb }} + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Install gems + env: + MATRIX_MONGOID_VERSION: ${{ matrix.mongoid }} + run: | + export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/Mongoid_${MATRIX_MONGOID_VERSION}.gemfile" + gem install bundler + bundle install --jobs 4 --retry 3 + + - run: bundle exec rspec From b84bff03604a0037738f84dd3a207b3af4f34dbf Mon Sep 17 00:00:00 2001 From: Rodrigo RA Date: Sat, 16 Jul 2022 10:50:58 -0300 Subject: [PATCH 03/11] Run tests for mongoid 5 | Add link to branches --- .github/workflows/build.yml | 5 ++--- README.md | 14 ++++++++++++-- gemfiles/Mongoid_6.gemfile | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0baf54..65f106e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,8 +5,8 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7'] - mongoid: ['4', '5', '6'] + ruby: ['2.5', '2.6'] + mongoid: ['5'] mongodb: ['4.4', '5.0'] runs-on: ubuntu-latest @@ -28,7 +28,6 @@ jobs: MATRIX_MONGOID_VERSION: ${{ matrix.mongoid }} run: | export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/Mongoid_${MATRIX_MONGOID_VERSION}.gemfile" - gem install bundler bundle install --jobs 4 --retry 3 - run: bundle exec rspec diff --git a/README.md b/README.md index aee9948..5d725e2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# mongoid-versioning [![Build Status](https://travis-ci.org/haihappen/mongoid-versioning.png)](https://travis-ci.org/haihappen/mongoid-versioning) +# mongoid-versioning ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=master) **Important:** This gem is an extraction of [Mongoid::Versioning](http://mongoid.github.io/en/mongoid/docs/extras.html#versioning) from the official [mongoid](http://mongoid.org) gem. Since Mongoid::Versioning was removed in the `4.0.0` release of Mongoid, this gem re-enables the functionality of versioned documents. @@ -11,10 +11,20 @@ Mongoid supports simple versioning through inclusion of the `Mongoid::Versioning ## Installation +### Mongoid/Ruby compatibility + +This fork has additional changes to support the following mongoid/ruby versions: + +| | branch | mongoid-paranoid support | Tested ruby version(s) | +|-----------------|-----------------------------------------------------------------------------------|--------------------------|------------------------| +| mongoid <5 | [master](https://github.com/fullhealthmedical/mongoid-versioning/tree/master) | Yes | 2.5, 2.6 | +| mongoid 6 | [mongoid6](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid6) | No | 2.7 | +| mongoid >= 7.0 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid7) | No | 2.7 | + In your Gemfile: ```ruby -gem 'mongoid-versioning' +gem 'mongoid-versioning', git: 'https://github.com/fullhealthmedical/mongoid-versioning', branch: 'master' ``` ## Usage diff --git a/gemfiles/Mongoid_6.gemfile b/gemfiles/Mongoid_6.gemfile index 210252d..3a67adf 100644 --- a/gemfiles/Mongoid_6.gemfile +++ b/gemfiles/Mongoid_6.gemfile @@ -2,5 +2,5 @@ source 'https://rubygems.org' gemspec path: '../' gem 'activesupport', '~> 5.0' -gem 'mongoid-paranoia', github: 'ream88/mongoid-paranoia' # Fix chicken or the egg +# gem 'mongoid-paranoia', github: 'ream88/mongoid-paranoia' # Fix chicken or the egg gem 'mongoid', '~> 6.0' From 8222f6b4c8bbe21d37d80f1aa70128de6a2d0dc4 Mon Sep 17 00:00:00 2001 From: Rodrigo R Aquino Date: Sat, 17 Sep 2022 13:14:00 -0300 Subject: [PATCH 04/11] Add build badge to readme --- .tool-versions | 1 + README.md | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..974865f --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.7.6 diff --git a/README.md b/README.md index 5d725e2..f07d791 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ Mongoid supports simple versioning through inclusion of the `Mongoid::Versioning This fork has additional changes to support the following mongoid/ruby versions: -| | branch | mongoid-paranoid support | Tested ruby version(s) | -|-----------------|-----------------------------------------------------------------------------------|--------------------------|------------------------| -| mongoid <5 | [master](https://github.com/fullhealthmedical/mongoid-versioning/tree/master) | Yes | 2.5, 2.6 | -| mongoid 6 | [mongoid6](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid6) | No | 2.7 | -| mongoid >= 7.0 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid7) | No | 2.7 | +| | branch | mongoid-paranoid support | Tested ruby version(s) | Build | +|-----------------|-----------------------------------------------------------------------------------|--------------------------|------------------------|-------| +| mongoid <5 | [master](https://github.com/fullhealthmedical/mongoid-versioning/tree/master) | Yes | 2.5, 2.6 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=master) | +| mongoid 6 | [mongoid6](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid6) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid6) | +| mongoid >= 7.0 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid7) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid7) | In your Gemfile: From 871616012779b8d40eb7ce8a8bd9df2d0f3d84b4 Mon Sep 17 00:00:00 2001 From: Rodrigo R Aquino Date: Sat, 11 Jun 2022 16:00:51 -0300 Subject: [PATCH 05/11] Drop mongoid-paranoid depedency --- .gitignore | 1 + gemfiles/Mongoid_6.gemfile | 1 - lib/mongoid/core_ext/versioning.rb | 12 ++-------- mongoid-versioning.gemspec | 1 - spec/app/models/author.rb | 2 -- spec/app/models/paranoid_post.rb | 38 ------------------------------ spec/mongoid/versioning_spec.rb | 20 ---------------- 7 files changed, 3 insertions(+), 72 deletions(-) delete mode 100644 spec/app/models/paranoid_post.rb diff --git a/.gitignore b/.gitignore index e12ddcc..b920c30 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ spec/reports test/tmp test/version_tmp tmp +.tool-versions # YARD artifacts .yardoc diff --git a/gemfiles/Mongoid_6.gemfile b/gemfiles/Mongoid_6.gemfile index 3a67adf..800cdf1 100644 --- a/gemfiles/Mongoid_6.gemfile +++ b/gemfiles/Mongoid_6.gemfile @@ -2,5 +2,4 @@ source 'https://rubygems.org' gemspec path: '../' gem 'activesupport', '~> 5.0' -# gem 'mongoid-paranoia', github: 'ream88/mongoid-paranoia' # Fix chicken or the egg gem 'mongoid', '~> 6.0' diff --git a/lib/mongoid/core_ext/versioning.rb b/lib/mongoid/core_ext/versioning.rb index 8837af8..237d949 100644 --- a/lib/mongoid/core_ext/versioning.rb +++ b/lib/mongoid/core_ext/versioning.rb @@ -43,16 +43,8 @@ def revise if version_max.present? && versions.length > version_max to_delete = versions.first version_to_delete = to_delete.version - if to_delete.respond_to?(:paranoid?) && to_delete.paranoid? - versions.delete_one(to_delete) - - query = collection.find(atomic_selector) - query.respond_to?(:update_one) ? - query.update_one('$pull' => { 'versions' => { 'version' => version_to_delete } }) : - query.update('$pull' => { 'versions' => { 'version' => version_to_delete } }) - else - versions.where(version: version_to_delete).delete_all - end + + versions.where(version: version_to_delete).delete_all end self.version = (version || 1) + 1 end diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index 121a493..1da0bf5 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'activesupport', '>= 4.0' gem.add_dependency 'mongoid', '>= 4.0.0', '< 7.0.0' - gem.add_development_dependency 'mongoid-paranoia', '>= 1.1.0', '< 3.0.0' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end diff --git a/spec/app/models/author.rb b/spec/app/models/author.rb index 9144111..8da12f4 100644 --- a/spec/app/models/author.rb +++ b/spec/app/models/author.rb @@ -1,6 +1,4 @@ class Author include Mongoid::Document field :name, type: String - - belongs_to :paranoid_post end diff --git a/spec/app/models/paranoid_post.rb b/spec/app/models/paranoid_post.rb deleted file mode 100644 index 823e985..0000000 --- a/spec/app/models/paranoid_post.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'mongoid/paranoia' - -class ParanoidPost - include Mongoid::Document - include Mongoid::Versioning - include Mongoid::Paranoia - - max_versions 2 - - field :title, type: String - - attr_accessor :after_destroy_called, :before_destroy_called - - belongs_to :person - - has_and_belongs_to_many :tags - has_many :authors, dependent: :delete - has_many :titles, dependent: :restrict - - scope :recent, -> { where(created_at: { '$lt' => Time.now, '$gt' => 30.days.ago }) } - - before_destroy :before_destroy_stub - after_destroy :after_destroy_stub - - def before_destroy_stub - self.before_destroy_called = true - end - - def after_destroy_stub - self.after_destroy_called = true - end - - class << self - def old - where(created_at: { '$lt' => 30.days.ago }) - end - end -end diff --git a/spec/mongoid/versioning_spec.rb b/spec/mongoid/versioning_spec.rb index 039b062..3348157 100644 --- a/spec/mongoid/versioning_spec.rb +++ b/spec/mongoid/versioning_spec.rb @@ -323,26 +323,6 @@ class WikiPage end context 'when saving over the number of maximum versions' do - context 'when the document is paranoid' do - let!(:post) do - ParanoidPost.create(title: 'test') - end - - before do - 3.times do |n| - post.update_attribute(:title, n.to_s) - end - end - - it 'only versions the maximum amount' do - expect(post.versions.target.size).to eq(2) - end - - it 'persists the changes' do - expect(post.reload.versions.target.size).to eq(2) - end - end - context 'when saving in succession' do before do 10.times do |n| From 6e7ea9529571ac60ca480783e76eee865a9e599b Mon Sep 17 00:00:00 2001 From: Rodrigo R Aquino Date: Sat, 16 Jul 2022 11:47:44 -0300 Subject: [PATCH 06/11] Update tests setup for mongoid 6 --- spec/app/models/comment.rb | 4 ++-- spec/app/models/wiki_page.rb | 4 ++-- spec/mongoid/versioning_spec.rb | 33 +++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/spec/app/models/comment.rb b/spec/app/models/comment.rb index 3da7c8d..21f1901 100644 --- a/spec/app/models/comment.rb +++ b/spec/app/models/comment.rb @@ -7,9 +7,9 @@ class Comment # belongs_to :account # belongs_to :movie # belongs_to :rating - belongs_to :wiki_page + # belongs_to :wiki_page - belongs_to :commentable, polymorphic: true + belongs_to :commentable, polymorphic: true # wiki_page validates :title, presence: true # validates :movie, :rating, associated: true diff --git a/spec/app/models/wiki_page.rb b/spec/app/models/wiki_page.rb index a010da7..f10c169 100644 --- a/spec/app/models/wiki_page.rb +++ b/spec/app/models/wiki_page.rb @@ -9,7 +9,7 @@ class WikiPage field :description, type: String, localize: true max_versions 5 - has_many :comments, dependent: :destroy, validate: false + has_many :comments, dependent: :destroy, as: :commentable, validate: false has_many :child_pages, class_name: 'WikiPage', dependent: :delete, inverse_of: :parent_pages - belongs_to :parent_pages, class_name: 'WikiPage', inverse_of: :child_pages + belongs_to :parent_pages, class_name: 'WikiPage', inverse_of: :child_pages, optional: true end diff --git a/spec/mongoid/versioning_spec.rb b/spec/mongoid/versioning_spec.rb index 3348157..f25ef03 100644 --- a/spec/mongoid/versioning_spec.rb +++ b/spec/mongoid/versioning_spec.rb @@ -174,7 +174,11 @@ class WikiPage let(:title) { 'my new wiki' } let!(:page) do - WikiPage.with(database: database_id_alt).create!(description: '1', title: title) + WikiPage.new(description: '1', title: title).tap do |page| + page.with(database: database_id_alt) do |page_alt| + page_alt.save! + end + end end context 'when the document is persisted once' do @@ -189,21 +193,28 @@ class WikiPage end it 'persists to specified database' do - expect(WikiPage.with(database: database_id_alt).find_by(title: title)).not_to be_nil + expect(WikiPage.with(database: database_id_alt) { |w| w.find_by(title: title) }).not_to be_nil end end context 'when the document is persisted more than once' do before do - 3.times { |n| page.with(database: database_id_alt).update_attribute(:description, n.to_s) } + skip "Mongoid 6 bug: https://jira.mongodb.org/browse/MONGOID-5379" + 3.times do |n| + page.with(database: database_id_alt) do |page_alt| + page_alt.update_attribute(:description, n.to_s) + end + end end it 'returns the number of versions' do - expect(page.version).to eq(4) + page.with(database: database_id_alt) do |page_alt| + expect(page_alt.version).to eq(4) + end end it 'persists to specified database' do - expect(WikiPage.with(database: database_id_alt).find_by(title: title)).not_to be_nil + expect(WikiPage.with(database: database_id_alt) { |w| w.find_by(title: title) }).not_to be_nil end it 'persists the versions to specified database' do @@ -212,7 +223,9 @@ class WikiPage end after do - WikiPage.with(database: database_id_alt).delete_all + WikiPage.with(database: database_id_alt) do |wiki_clazz| + wiki_clazz.delete_all + end end end end @@ -382,10 +395,6 @@ class WikiPage Comment.new(title: "Don't delete me!") end - let!(:orphaned) do - Comment.create(title: 'Annie') - end - before do page.comments << comment page.update_attribute(:title, '5') @@ -404,10 +413,6 @@ class WikiPage expect(from_db).to eq(comment) end - it 'does not delete related orphans' do - expect(Comment.find(orphaned.id)).to eq(orphaned) - end - it 'deletes the version' do expect(page.versions).to be_empty end From 0041479390716225cad01440b36a70d171e3f11a Mon Sep 17 00:00:00 2001 From: Rodrigo R Aquino Date: Sat, 16 Jul 2022 12:06:30 -0300 Subject: [PATCH 07/11] Drop mongoid 4/5 support --- .github/workflows/build.yml | 4 ++-- README.md | 2 +- gemfiles/Mongoid_4.gemfile | 4 ---- gemfiles/Mongoid_5.gemfile | 4 ---- lib/mongoid/core_ext/versioning.rb | 6 +----- mongoid-versioning.gemspec | 2 +- 6 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 gemfiles/Mongoid_4.gemfile delete mode 100644 gemfiles/Mongoid_5.gemfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65f106e..1b1151b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,8 +5,8 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.5', '2.6'] - mongoid: ['5'] + ruby: ['2.7'] + mongoid: ['6'] mongodb: ['4.4', '5.0'] runs-on: ubuntu-latest diff --git a/README.md b/README.md index f07d791..934caf7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# mongoid-versioning ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=master) +# mongoid-versioning ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid6) **Important:** This gem is an extraction of [Mongoid::Versioning](http://mongoid.github.io/en/mongoid/docs/extras.html#versioning) from the official [mongoid](http://mongoid.org) gem. Since Mongoid::Versioning was removed in the `4.0.0` release of Mongoid, this gem re-enables the functionality of versioned documents. diff --git a/gemfiles/Mongoid_4.gemfile b/gemfiles/Mongoid_4.gemfile deleted file mode 100644 index 55c894a..0000000 --- a/gemfiles/Mongoid_4.gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' -gemspec path: '../' - -gem 'mongoid', '~> 4.0' diff --git a/gemfiles/Mongoid_5.gemfile b/gemfiles/Mongoid_5.gemfile deleted file mode 100644 index dca0e76..0000000 --- a/gemfiles/Mongoid_5.gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' -gemspec path: '../' - -gem 'mongoid', '~> 5.0' diff --git a/lib/mongoid/core_ext/versioning.rb b/lib/mongoid/core_ext/versioning.rb index 237d949..f1eede9 100644 --- a/lib/mongoid/core_ext/versioning.rb +++ b/lib/mongoid/core_ext/versioning.rb @@ -31,7 +31,6 @@ module Versioning # @example Revise the document. # person.revise # - # @todo Remove Mongoid 4 support. # @since 1.0.0 def revise previous = previous_revision @@ -123,12 +122,9 @@ def versionless # # @return [ Document, nil ] The previously saved document. # - # @todo Remove Mongoid 4 support. # @since 2.0.0 def previous_revision - options = respond_to?(:mongo_client) ? - mongo_client.options.symbolize_keys : - mongo_session.options + options = mongo_client.options.symbolize_keys _loading_revision do self.class.with(options) do |m| diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index 1da0bf5..666c0a5 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_path = 'lib' gem.add_dependency 'activesupport', '>= 4.0' - gem.add_dependency 'mongoid', '>= 4.0.0', '< 7.0.0' + gem.add_dependency 'mongoid', '>= 6.0.0', '< 7.0.0' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end From 8e1a8c978e4c0cc91c216724cd827d393af10fe1 Mon Sep 17 00:00:00 2001 From: Rodrigo RA Date: Fri, 22 Jul 2022 11:20:31 -0300 Subject: [PATCH 08/11] Add support to mongoid 7 | drop support mongoid 6 Works with mongoid 7.0.x --- .github/workflows/build.yml | 8 +-- .vscode/settings.json | 3 + Gemfile | 2 + gemfiles/Mongoid_6.gemfile | 5 -- gemfiles/Mongoid_7.gemfile | 4 ++ .../{relations => association}/cascading.rb | 2 +- .../embedded/batchable.rb | 10 +-- .../embedded/embeds_many/binding.rb} | 14 +++-- .../embedded/many.rb | 4 +- lib/mongoid/core_ext/association/macros.rb | 16 +++++ lib/mongoid/core_ext/association/options.rb | 17 +++++ lib/mongoid/core_ext/association/relatable.rb | 30 +++++++++ lib/mongoid/core_ext/relations/macros.rb | 39 ------------ lib/mongoid/core_ext/relations/metadata.rb | 63 ------------------- lib/mongoid/core_ext/relations/options.rb | 12 ---- lib/mongoid/versioning.rb | 14 ++--- mongoid-versioning.code-workspace | 13 ++++ mongoid-versioning.gemspec | 2 +- spec/app/models/wiki_page.rb | 2 +- .../{relations => association}/macros_spec.rb | 2 +- spec/mongoid/association/relatable_spec.rb | 46 ++++++++++++++ spec/mongoid/relations/metadata_spec.rb | 46 -------------- spec/mongoid/versioning_spec.rb | 7 ++- spec/spec_helper.rb | 2 +- 24 files changed, 165 insertions(+), 198 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 gemfiles/Mongoid_6.gemfile create mode 100644 gemfiles/Mongoid_7.gemfile rename lib/mongoid/core_ext/{relations => association}/cascading.rb (96%) rename lib/mongoid/core_ext/{relations => association}/embedded/batchable.rb (82%) rename lib/mongoid/core_ext/{relations/bindings/embedded/many.rb => association/embedded/embeds_many/binding.rb} (77%) rename lib/mongoid/core_ext/{relations => association}/embedded/many.rb (90%) create mode 100755 lib/mongoid/core_ext/association/macros.rb create mode 100644 lib/mongoid/core_ext/association/options.rb create mode 100644 lib/mongoid/core_ext/association/relatable.rb delete mode 100755 lib/mongoid/core_ext/relations/macros.rb delete mode 100755 lib/mongoid/core_ext/relations/metadata.rb delete mode 100644 lib/mongoid/core_ext/relations/options.rb create mode 100644 mongoid-versioning.code-workspace rename spec/mongoid/{relations => association}/macros_spec.rb (90%) create mode 100755 spec/mongoid/association/relatable_spec.rb delete mode 100755 spec/mongoid/relations/metadata_spec.rb diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b1151b..7fefaa7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: fail-fast: false matrix: ruby: ['2.7'] - mongoid: ['6'] + mongoid: ['7'] mongodb: ['4.4', '5.0'] runs-on: ubuntu-latest @@ -24,10 +24,8 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Install gems - env: - MATRIX_MONGOID_VERSION: ${{ matrix.mongoid }} run: | - export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/Mongoid_${MATRIX_MONGOID_VERSION}.gemfile" + export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/Mongoid_${{ matrix.mongoid }}.gemfile" bundle install --jobs 4 --retry 3 - - run: bundle exec rspec + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..781fd4e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ruby.rubocop.onSave": false +} diff --git a/Gemfile b/Gemfile index 851fabc..2af579f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,4 @@ source 'https://rubygems.org' gemspec + +gem 'mongoid' diff --git a/gemfiles/Mongoid_6.gemfile b/gemfiles/Mongoid_6.gemfile deleted file mode 100644 index 800cdf1..0000000 --- a/gemfiles/Mongoid_6.gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' -gemspec path: '../' - -gem 'activesupport', '~> 5.0' -gem 'mongoid', '~> 6.0' diff --git a/gemfiles/Mongoid_7.gemfile b/gemfiles/Mongoid_7.gemfile new file mode 100644 index 0000000..02acc83 --- /dev/null +++ b/gemfiles/Mongoid_7.gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +gemspec path: '../' + +gem 'mongoid', '~> 7.0' diff --git a/lib/mongoid/core_ext/relations/cascading.rb b/lib/mongoid/core_ext/association/cascading.rb similarity index 96% rename from lib/mongoid/core_ext/relations/cascading.rb rename to lib/mongoid/core_ext/association/cascading.rb index 86042fe..3bbb546 100755 --- a/lib/mongoid/core_ext/relations/cascading.rb +++ b/lib/mongoid/core_ext/association/cascading.rb @@ -1,5 +1,5 @@ module Mongoid - module Relations + module Association module Cascading # Perform all cascading deletes, destroys, or nullifies. Will delegate to # the appropriate strategy to perform the operation. diff --git a/lib/mongoid/core_ext/relations/embedded/batchable.rb b/lib/mongoid/core_ext/association/embedded/batchable.rb similarity index 82% rename from lib/mongoid/core_ext/relations/embedded/batchable.rb rename to lib/mongoid/core_ext/association/embedded/batchable.rb index 2387b82..8a97a0a 100755 --- a/lib/mongoid/core_ext/relations/embedded/batchable.rb +++ b/lib/mongoid/core_ext/association/embedded/batchable.rb @@ -1,5 +1,5 @@ module Mongoid - module Relations + module Association module Embedded module Batchable # Pre process the batch removal. @@ -19,15 +19,15 @@ def pre_process_batch_remove(docs, method) docs.map do |doc| self.path = doc.atomic_path unless path execute_callback :before_remove, doc - if !_assigning? && !metadata.versioned? - doc.cascade! + if !_assigning? && !association.versioned? + doc.apply_delete_dependencies! doc.run_before_callbacks(:destroy) if method == :destroy end - target.delete_one(doc) + _target.delete_one(doc) _unscoped.delete_one(doc) unbind_one(doc) execute_callback :after_remove, doc - doc.as_document + doc.send(:as_attributes) end end end diff --git a/lib/mongoid/core_ext/relations/bindings/embedded/many.rb b/lib/mongoid/core_ext/association/embedded/embeds_many/binding.rb similarity index 77% rename from lib/mongoid/core_ext/relations/bindings/embedded/many.rb rename to lib/mongoid/core_ext/association/embedded/embeds_many/binding.rb index c18bcc0..4757988 100755 --- a/lib/mongoid/core_ext/relations/bindings/embedded/many.rb +++ b/lib/mongoid/core_ext/association/embedded/embeds_many/binding.rb @@ -1,8 +1,10 @@ module Mongoid - module Relations - module Bindings - module Embedded - class Many < Binding + module Association + module Embedded + class EmbedMany + class Binding + include Bindable + # Binds a single document with the inverse relation. Used # specifically when appending to the proxy. # @@ -17,10 +19,10 @@ class Many < Binding # # @since 2.0.0.rc.1 def bind_one(doc) - doc.parentize(base) + doc.parentize(_base) binding do unless metadata.versioned? - doc.do_or_do_not(metadata.inverse_setter(target), base) + doc.do_or_do_not(_association.inverse_setter(_target), base) end end end diff --git a/lib/mongoid/core_ext/relations/embedded/many.rb b/lib/mongoid/core_ext/association/embedded/many.rb similarity index 90% rename from lib/mongoid/core_ext/relations/embedded/many.rb rename to lib/mongoid/core_ext/association/embedded/many.rb index cacd94a..49ab0a0 100755 --- a/lib/mongoid/core_ext/relations/embedded/many.rb +++ b/lib/mongoid/core_ext/association/embedded/many.rb @@ -1,7 +1,7 @@ module Mongoid - module Relations + module Association module Embedded - class Many < Relations::Many + class Many < Association::Many class << self # Get the valid options allowed with this relation. # diff --git a/lib/mongoid/core_ext/association/macros.rb b/lib/mongoid/core_ext/association/macros.rb new file mode 100755 index 0000000..77f8776 --- /dev/null +++ b/lib/mongoid/core_ext/association/macros.rb @@ -0,0 +1,16 @@ +module Mongoid + module Association + module Macros + module ClassMethods + alias_method :embedded_in_without_versioning_validation, :embedded_in + + def embedded_in(name, options = {}, &block) + if ancestors.include?(Mongoid::Versioning) + raise Errors::VersioningNotOnRoot, self + end + define_association!(__method__, name, options, &block) + end + end + end + end +end diff --git a/lib/mongoid/core_ext/association/options.rb b/lib/mongoid/core_ext/association/options.rb new file mode 100644 index 0000000..00a86e6 --- /dev/null +++ b/lib/mongoid/core_ext/association/options.rb @@ -0,0 +1,17 @@ +module Mongoid + module Association + module Options + # Is this relation using Mongoid's internal versioning system? + # + # @example Is this relation versioned? + # association.versioned? + # + # @return [ true, false ] If the relation uses Mongoid versioning. + # + # @since 2.1.0 + def versioned? + !!self[:versioned] + end + end + end +end diff --git a/lib/mongoid/core_ext/association/relatable.rb b/lib/mongoid/core_ext/association/relatable.rb new file mode 100644 index 0000000..49d2384 --- /dev/null +++ b/lib/mongoid/core_ext/association/relatable.rb @@ -0,0 +1,30 @@ +module Mongoid + module Association + module Relatable + alias_method :validate_without_versioned!, :validate! + + # Monkey patching the validate method to removes the :versioned option + # from the options hash. + # + # @param [ Hash ] options The options to validate. + def validate! + @orginal_options = @options.dup + @options = @options.except(:versioned) + validate_without_versioned! + @options = @orginal_options + end + + # Is this relation using Mongoid's internal versioning system? + # + # @example Is this relation versioned? + # metadata.versioned? + # + # @return [ true, false ] If the relation uses Mongoid versioning. + # + # @since 2.1.0 + def versioned? + !!@options[:versioned] + end + end + end +end diff --git a/lib/mongoid/core_ext/relations/macros.rb b/lib/mongoid/core_ext/relations/macros.rb deleted file mode 100755 index 34c45a5..0000000 --- a/lib/mongoid/core_ext/relations/macros.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Mongoid - module Relations - module Macros - module ClassMethods - # Adds the relation back to the parent document. This macro is - # necessary to set the references from the child back to the parent - # document. If a child does not define this relation calling - # persistence methods on the child object will cause a save to fail. - # - # @example Define the relation. - # - # class Person - # include Mongoid::Document - # embeds_many :addresses - # end - # - # class Address - # include Mongoid::Document - # embedded_in :person - # end - # - # @param [ Symbol ] name The name of the relation. - # @param [ Hash ] options The relation options. - # @param [ Proc ] block Optional block for defining extensions. - def embedded_in(name, options = {}, &block) - if ancestors.include?(Mongoid::Versioning) - raise Errors::VersioningNotOnRoot, self - end - meta = characterize(name, Embedded::In, options, &block) - self.embedded = true - relate(name, meta) - builder(name, meta).creator(name, meta) - add_counter_cache_callbacks(meta) if meta.counter_cached? - meta - end - end - end - end -end diff --git a/lib/mongoid/core_ext/relations/metadata.rb b/lib/mongoid/core_ext/relations/metadata.rb deleted file mode 100755 index 113da68..0000000 --- a/lib/mongoid/core_ext/relations/metadata.rb +++ /dev/null @@ -1,63 +0,0 @@ -module Mongoid - module Relations - class Metadata < Hash - # Since a lot of the information from the metadata is inferred and not - # explicitly stored in the hash, the inspection needs to be much more - # detailed. - # - # @example Inspect the metadata. - # metadata.inspect - # - # @return [ String ] Oodles of information in a nice format. - # - # @since 2.0.0.rc.1 - def inspect - %(# - ) - end - - # Is this relation using Mongoid's internal versioning system? - # - # @example Is this relation versioned? - # metadata.versioned? - # - # @return [ true, false ] If the relation uses Mongoid versioning. - # - # @since 2.1.0 - def versioned? - !!self[:versioned] - end - - # Get the inverse relation candidates. - # - # @api private - # - # @example Get the inverse relation candidates. - # metadata.inverse_relation_candidates - # - # @return [ Array ] The candidates. - # - # @since 3.0.0 - def inverse_relation_candidates - relations_metadata.select do |meta| - next if meta.versioned? || meta.name == name - meta.class_name == inverse_class_name - end - end - end - end -end diff --git a/lib/mongoid/core_ext/relations/options.rb b/lib/mongoid/core_ext/relations/options.rb deleted file mode 100644 index f2e5730..0000000 --- a/lib/mongoid/core_ext/relations/options.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Mongoid - module Relations - module Options - alias_method :validate_without_versioned!, :validate! - - def validate!(options) - options_without_versioned = options.except(:versioned) - validate_without_versioned!(options_without_versioned) - end - end - end -end diff --git a/lib/mongoid/versioning.rb b/lib/mongoid/versioning.rb index a7abdc0..f935b93 100644 --- a/lib/mongoid/versioning.rb +++ b/lib/mongoid/versioning.rb @@ -2,13 +2,13 @@ require 'mongoid/core_ext/fields/standard.rb' require 'mongoid/core_ext/fields/validators/macro.rb' require 'mongoid/core_ext/hierarchy.rb' -require 'mongoid/core_ext/relations/bindings/embedded/many.rb' -require 'mongoid/core_ext/relations/cascading.rb' -require 'mongoid/core_ext/relations/embedded/batchable.rb' -require 'mongoid/core_ext/relations/embedded/many.rb' -require 'mongoid/core_ext/relations/macros.rb' -require 'mongoid/core_ext/relations/metadata.rb' -require 'mongoid/core_ext/relations/options.rb' +require 'mongoid/core_ext/association/embedded/embeds_many/binding.rb' +require 'mongoid/core_ext/association/cascading.rb' +require 'mongoid/core_ext/association/embedded/batchable.rb' +require 'mongoid/core_ext/association/embedded/many.rb' +require 'mongoid/core_ext/association/macros.rb' +require 'mongoid/core_ext/association/options.rb' +require 'mongoid/core_ext/association/relatable.rb' require 'mongoid/core_ext/threaded/lifecycle.rb' require 'mongoid/core_ext/versioning.rb' diff --git a/mongoid-versioning.code-workspace b/mongoid-versioning.code-workspace new file mode 100644 index 0000000..2cd5744 --- /dev/null +++ b/mongoid-versioning.code-workspace @@ -0,0 +1,13 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "../mongoid-test" + } + ], + "settings": { + "ruby.rubocop.onSave": false + } +} diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index 666c0a5..dea80d1 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_path = 'lib' gem.add_dependency 'activesupport', '>= 4.0' - gem.add_dependency 'mongoid', '>= 6.0.0', '< 7.0.0' + gem.add_dependency 'mongoid', '>= 7.0.0', '< 7.1.0' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end diff --git a/spec/app/models/wiki_page.rb b/spec/app/models/wiki_page.rb index f10c169..e00fbe5 100644 --- a/spec/app/models/wiki_page.rb +++ b/spec/app/models/wiki_page.rb @@ -10,6 +10,6 @@ class WikiPage max_versions 5 has_many :comments, dependent: :destroy, as: :commentable, validate: false - has_many :child_pages, class_name: 'WikiPage', dependent: :delete, inverse_of: :parent_pages + has_many :child_pages, class_name: 'WikiPage', dependent: :delete_all, inverse_of: :parent_pages belongs_to :parent_pages, class_name: 'WikiPage', inverse_of: :child_pages, optional: true end diff --git a/spec/mongoid/relations/macros_spec.rb b/spec/mongoid/association/macros_spec.rb similarity index 90% rename from spec/mongoid/relations/macros_spec.rb rename to spec/mongoid/association/macros_spec.rb index 8736bd5..1027d6d 100755 --- a/spec/mongoid/relations/macros_spec.rb +++ b/spec/mongoid/association/macros_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Mongoid::Relations::Macros do +describe Mongoid::Association::Macros do describe '.embedded_in' do context 'when the document is versioned' do it 'raises an error' do diff --git a/spec/mongoid/association/relatable_spec.rb b/spec/mongoid/association/relatable_spec.rb new file mode 100755 index 0000000..3c57b3c --- /dev/null +++ b/spec/mongoid/association/relatable_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Mongoid::Association::Relatable do + describe '#versioned?' do + context 'when versioned is true' do + let(:association) do + Mongoid::Association::Embedded::EmbedsMany.new( + Address, + :versions, + versioned: true + ) + end + + it 'returns true' do + expect(association).to be_versioned + end + end + + context 'when versioned is false' do + let(:association) do + Mongoid::Association::Embedded::EmbedsMany.new( + Address, + :versions, + versioned: false + ) + end + + it 'returns false' do + expect(association).not_to be_versioned + end + end + + context 'when versioned is nil' do + let(:association) do + Mongoid::Association::Embedded::EmbedsMany.new( + Address, + :versions + ) + end + + it 'returns false' do + expect(association).not_to be_versioned + end + end + end +end diff --git a/spec/mongoid/relations/metadata_spec.rb b/spec/mongoid/relations/metadata_spec.rb deleted file mode 100755 index 5831fa4..0000000 --- a/spec/mongoid/relations/metadata_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'spec_helper' - -describe Mongoid::Relations::Metadata do - describe '#versioned?' do - context 'when versioned is true' do - let(:metadata) do - described_class.new( - name: :versions, - relation: Mongoid::Relations::Embedded::Many, - versioned: true - ) - end - - it 'returns true' do - expect(metadata).to be_versioned - end - end - - context 'when versioned is false' do - let(:metadata) do - described_class.new( - name: :versions, - relation: Mongoid::Relations::Embedded::Many, - versioned: false - ) - end - - it 'returns false' do - expect(metadata).not_to be_versioned - end - end - - context 'when versioned is nil' do - let(:metadata) do - described_class.new( - name: :versions, - relation: Mongoid::Relations::Embedded::Many - ) - end - - it 'returns false' do - expect(metadata).not_to be_versioned - end - end - end -end diff --git a/spec/mongoid/versioning_spec.rb b/spec/mongoid/versioning_spec.rb index f25ef03..b40adee 100644 --- a/spec/mongoid/versioning_spec.rb +++ b/spec/mongoid/versioning_spec.rb @@ -199,7 +199,7 @@ class WikiPage context 'when the document is persisted more than once' do before do - skip "Mongoid 6 bug: https://jira.mongodb.org/browse/MONGOID-5379" + skip "Mongoid 7 bug: https://jira.mongodb.org/browse/MONGOID-5379" 3.times do |n| page.with(database: database_id_alt) do |page_alt| page_alt.update_attribute(:description, n.to_s) @@ -253,9 +253,10 @@ class WikiPage describe '#versions' do let(:page) do - WikiPage.create(title: '1', description: 'test') do |wiki| + pg = WikiPage.create!(title: '1', description: 'test') do |wiki| wiki.author = 'woodchuck' end + pg end context 'when saving the document ' do @@ -339,7 +340,7 @@ class WikiPage context 'when saving in succession' do before do 10.times do |n| - page.update_attribute(:title, n.to_s) + page.update(title: n.to_s) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3fa8fd4..71e3f56 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,9 +18,9 @@ HOST = ENV['MONGOID_SPEC_HOST'] PORT = ENV['MONGOID_SPEC_PORT'].to_i -# Moped.logger.level = Logger::DEBUG # TODO Remove Mongoid 4 support. # Mongoid.logger.level = Logger::DEBUG Mongo::Logger.logger.level = Logger::WARN if defined?(Mongo) +# Mongo::Monitoring::CommandLogSubscriber::LOG_STRING_LIMIT = 10_000 # When testing locally we use the database named mongoid_test. However when # tests are running in parallel on Travis we need to use different database From 091ed34905e6f3b528a024921fb57f31ad4ed3e8 Mon Sep 17 00:00:00 2001 From: Rodrigo R Aquino Date: Fri, 14 Apr 2023 15:32:25 -0300 Subject: [PATCH 09/11] Accept mongoid > 7 --- mongoid-versioning.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index dea80d1..02da388 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_path = 'lib' gem.add_dependency 'activesupport', '>= 4.0' - gem.add_dependency 'mongoid', '>= 7.0.0', '< 7.1.0' + gem.add_dependency 'mongoid', '>= 7.0.0', '< 8' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end From 5e09fe16c85f4e8beb696f969e66d6bd24096736 Mon Sep 17 00:00:00 2001 From: Rodrigo Aquino Date: Fri, 17 Nov 2023 10:23:02 -0300 Subject: [PATCH 10/11] Update spec to run with mongoid 7.1 --- .github/workflows/build.yml | 7 +++---- .tool-versions | 2 +- Gemfile | 2 +- gemfiles/{Mongoid_7.gemfile => Mongoid_71.gemfile} | 2 +- mongoid-versioning.gemspec | 2 +- spec/spec_helper.rb | 2 ++ 6 files changed, 9 insertions(+), 8 deletions(-) rename gemfiles/{Mongoid_7.gemfile => Mongoid_71.gemfile} (66%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7fefaa7..037051f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,12 +1,12 @@ name: Build -on: [push, pull_request] +on: [push] jobs: test: strategy: fail-fast: false matrix: - ruby: ['2.7'] - mongoid: ['7'] + ruby: ['3.0', '3.1'] + mongoid: ['71'] mongodb: ['4.4', '5.0'] runs-on: ubuntu-latest @@ -28,4 +28,3 @@ jobs: export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/Mongoid_${{ matrix.mongoid }}.gemfile" bundle install --jobs 4 --retry 3 - run: bundle exec rspec - diff --git a/.tool-versions b/.tool-versions index 974865f..306ab33 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 2.7.6 +ruby 3.1.4 diff --git a/Gemfile b/Gemfile index 2af579f..8d015c1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' gemspec -gem 'mongoid' +gem 'mongoid', '~> 7.1.0' diff --git a/gemfiles/Mongoid_7.gemfile b/gemfiles/Mongoid_71.gemfile similarity index 66% rename from gemfiles/Mongoid_7.gemfile rename to gemfiles/Mongoid_71.gemfile index 02acc83..8825216 100644 --- a/gemfiles/Mongoid_7.gemfile +++ b/gemfiles/Mongoid_71.gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' gemspec path: '../' -gem 'mongoid', '~> 7.0' +gem 'mongoid', '~> 7.1.0' diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index 02da388..3b399e1 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_path = 'lib' gem.add_dependency 'activesupport', '>= 4.0' - gem.add_dependency 'mongoid', '>= 7.0.0', '< 8' + gem.add_dependency 'mongoid', '>= 7.1.0', '< 8' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 71e3f56..8e182ed 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -53,6 +53,8 @@ def mongohq_connectable? module Rails class Application end + + def self.logger; nil; end end module MyApp From 03b50265fe6683a9de9d257bcf307bc03f48c467 Mon Sep 17 00:00:00 2001 From: Gilson Mendes Date: Fri, 17 Nov 2023 09:31:32 -0300 Subject: [PATCH 11/11] Adding support to mongoid 7.3.5 --- .github/workflows/build.yml | 2 +- Gemfile | 2 +- README.md | 3 ++- gemfiles/{Mongoid_71.gemfile => Mongoid_73.gemfile} | 2 +- lib/mongoid/core_ext/association/embedded/batchable.rb | 2 +- lib/mongoid/versioning/version.rb | 2 +- mongoid-versioning.gemspec | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) rename gemfiles/{Mongoid_71.gemfile => Mongoid_73.gemfile} (66%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 037051f..d8ccaca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: fail-fast: false matrix: ruby: ['3.0', '3.1'] - mongoid: ['71'] + mongoid: ['73'] mongodb: ['4.4', '5.0'] runs-on: ubuntu-latest diff --git a/Gemfile b/Gemfile index 8d015c1..4182c03 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' gemspec -gem 'mongoid', '~> 7.1.0' +gem 'mongoid', "~> 7.3.5" diff --git a/README.md b/README.md index 934caf7..d7baa83 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ This fork has additional changes to support the following mongoid/ruby versions: |-----------------|-----------------------------------------------------------------------------------|--------------------------|------------------------|-------| | mongoid <5 | [master](https://github.com/fullhealthmedical/mongoid-versioning/tree/master) | Yes | 2.5, 2.6 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=master) | | mongoid 6 | [mongoid6](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid6) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid6) | -| mongoid >= 7.0 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid7) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid7) | +| mongoid >= 7.0 < 7.3.5 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid7) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid7) | +| mongoid >= 7.0 < 7.3.5 | [mongoid7](https://github.com/fullhealthmedical/mongoid-versioning/tree/mongoid73) | No | 2.7 | ![Build](https://github.com/fullhealthmedical/mongoid-versioning/actions/workflows/build.yml/badge.svg?branch=mongoid73) | In your Gemfile: diff --git a/gemfiles/Mongoid_71.gemfile b/gemfiles/Mongoid_73.gemfile similarity index 66% rename from gemfiles/Mongoid_71.gemfile rename to gemfiles/Mongoid_73.gemfile index 8825216..7612014 100644 --- a/gemfiles/Mongoid_71.gemfile +++ b/gemfiles/Mongoid_73.gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' gemspec path: '../' -gem 'mongoid', '~> 7.1.0' +gem 'mongoid', '~> 7.3.5' diff --git a/lib/mongoid/core_ext/association/embedded/batchable.rb b/lib/mongoid/core_ext/association/embedded/batchable.rb index 8a97a0a..a905d02 100755 --- a/lib/mongoid/core_ext/association/embedded/batchable.rb +++ b/lib/mongoid/core_ext/association/embedded/batchable.rb @@ -20,7 +20,7 @@ def pre_process_batch_remove(docs, method) self.path = doc.atomic_path unless path execute_callback :before_remove, doc if !_assigning? && !association.versioned? - doc.apply_delete_dependencies! + doc.apply_destroy_dependencies! doc.run_before_callbacks(:destroy) if method == :destroy end _target.delete_one(doc) diff --git a/lib/mongoid/versioning/version.rb b/lib/mongoid/versioning/version.rb index 9551128..cd40d92 100644 --- a/lib/mongoid/versioning/version.rb +++ b/lib/mongoid/versioning/version.rb @@ -1,5 +1,5 @@ module Mongoid module Versioning - VERSION = '2.1.0'.freeze + VERSION = '3.0.0'.freeze end end diff --git a/mongoid-versioning.gemspec b/mongoid-versioning.gemspec index 3b399e1..c0462fb 100644 --- a/mongoid-versioning.gemspec +++ b/mongoid-versioning.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.require_path = 'lib' gem.add_dependency 'activesupport', '>= 4.0' - gem.add_dependency 'mongoid', '>= 7.1.0', '< 8' + gem.add_dependency 'mongoid', '~> 7.3.5' gem.add_development_dependency 'rake', '~> 10.0' gem.add_development_dependency 'rspec', '~> 3' end