diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b6e44..10a7836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ ## Changelog -### 2.1.1 (Next) +### 2.2.0 (Next) * Your contribution here. +* [#107](https://github.com/mongoid/mongoid-locker/pull/107): Revert introduction of `forwardable` to ensure compatibility with mongoid-history - [@scpike](https://github.com/scpike). ### 2.1.0 (2024-05-07) diff --git a/Gemfile b/Gemfile index 1d8e285..5925a0f 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ group :development, :test do gem 'mongoid-compatibility' gem 'mongoid-danger', '~> 0.2.0' + gem 'mongoid-history' gem 'rspec', '~> 3.9' gem 'rubocop', '0.81.0' gem 'rubocop-rspec', '1.38.1' diff --git a/lib/mongoid/locker.rb b/lib/mongoid/locker.rb index 4e6b8fb..9f97d07 100644 --- a/lib/mongoid/locker.rb +++ b/lib/mongoid/locker.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'forwardable' require 'securerandom' module Mongoid @@ -104,8 +103,6 @@ def reset! # @api private def included(klass) - klass.extend(Forwardable) unless klass.ancestors.include?(Forwardable) - klass.extend ClassMethods klass.singleton_class.instance_eval { attr_accessor(*MODULE_METHODS) } @@ -117,7 +114,7 @@ def included(klass) klass.backoff_algorithm = backoff_algorithm klass.locking_name_generator = locking_name_generator - klass.def_delegators(klass, *MODULE_METHODS) + klass.delegate(*MODULE_METHODS, to: :class) klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map { |method| [method, "#{method}=".to_sym] } - %i[included reset! configure]), to: self) end end diff --git a/lib/mongoid/locker/version.rb b/lib/mongoid/locker/version.rb index 4035002..20a0c73 100644 --- a/lib/mongoid/locker/version.rb +++ b/lib/mongoid/locker/version.rb @@ -2,6 +2,6 @@ module Mongoid module Locker - VERSION = '2.1.1' + VERSION = '2.2.0' end end diff --git a/spec/integration/mongoid-history/mongoid_history_spec.rb b/spec/integration/mongoid-history/mongoid_history_spec.rb new file mode 100644 index 0000000..7b0b006 --- /dev/null +++ b/spec/integration/mongoid-history/mongoid_history_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'mongoid-history' + +# This replicates the exception reported at https://github.com/mongoid/mongoid-history/issues/238#issuecomment-1063155193 +# when mongoid-locker required 'forwardable' instead of relying on the +# active support-provided delegation method +RSpec.describe 'MongoidHistory' do # rubocop:disable RSpec/DescribeClass + # rubocop:disable RSpec/ExampleLength + it 'does not raise an exception' do + expect do + Class.new do + include Mongoid::Document + include Mongoid::Locker + include Mongoid::History::Trackable + + field :title + + track_history on: [:title] + end + end.not_to raise_exception + end + # rubocop:enable RSpec/ExampleLength +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8ebf22e..17c4eb0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,8 @@ ENV['RACK_ENV'] = 'test' +require 'logger' # Required for compatibility with activesupport 7 + if ENV['COVERAGE'] require 'simplecov' require 'simplecov_json_formatter'