From 0ab88b9052fa7b82b70f9611340945559b69448c Mon Sep 17 00:00:00 2001 From: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Date: Wed, 20 Dec 2023 18:53:26 +0900 Subject: [PATCH] MONGOID-5717 Fix some cases of missing **kwargs pass-thru (#5758) Co-authored-by: Dmitry Rybakov --- lib/mongoid/scopable.rb | 4 ++-- spec/mongoid/criteria/marshalable_spec.rb | 4 ++-- spec/mongoid/extensions/set_spec.rb | 4 +--- spec/mongoid/validatable/uniqueness_spec.rb | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/mongoid/scopable.rb b/lib/mongoid/scopable.rb index 08cb8ecba1..35635acdc3 100644 --- a/lib/mongoid/scopable.rb +++ b/lib/mongoid/scopable.rb @@ -290,9 +290,9 @@ def check_scope_validity(value) def define_scope_method(name) singleton_class.class_eval do ruby2_keywords( - define_method(name) do |*args| + define_method(name) do |*args, **kwargs| scoping = _declared_scopes[name] - scope = instance_exec(*args, &scoping[:scope]) + scope = instance_exec(*args, **kwargs, &scoping[:scope]) extension = scoping[:extension] to_merge = scope || queryable criteria = to_merge.empty_and_chainable? ? to_merge : with_default_scope.merge(to_merge) diff --git a/spec/mongoid/criteria/marshalable_spec.rb b/spec/mongoid/criteria/marshalable_spec.rb index c7050d0e6c..fed243ae5f 100644 --- a/spec/mongoid/criteria/marshalable_spec.rb +++ b/spec/mongoid/criteria/marshalable_spec.rb @@ -31,8 +31,8 @@ let(:dump) { Marshal.dump(criteria) } before do - expect_any_instance_of(Mongoid::Criteria).to receive(:marshal_dump).and_wrap_original do |m, *args| - data = m.call(*args) + expect_any_instance_of(Mongoid::Criteria).to receive(:marshal_dump).and_wrap_original do |m, *args, **kwargs| + data = m.call(*args, **kwargs) data[1] = :mongo1x data end diff --git a/spec/mongoid/extensions/set_spec.rb b/spec/mongoid/extensions/set_spec.rb index cde2d7da01..f81e43c5fc 100644 --- a/spec/mongoid/extensions/set_spec.rb +++ b/spec/mongoid/extensions/set_spec.rb @@ -113,9 +113,7 @@ end before do - expect(BigDecimal).to receive(:mongoize).exactly(4).times.and_wrap_original do |m, *args| - 1 - end + expect(BigDecimal).to receive(:mongoize).exactly(4).times.and_return(1) end context "when the input is a set" do diff --git a/spec/mongoid/validatable/uniqueness_spec.rb b/spec/mongoid/validatable/uniqueness_spec.rb index ec8453dc43..e931ac3d73 100644 --- a/spec/mongoid/validatable/uniqueness_spec.rb +++ b/spec/mongoid/validatable/uniqueness_spec.rb @@ -20,8 +20,8 @@ end it "reads from the primary" do - expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args| - crit = m.call(*args) + expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs| + crit = m.call(*args, **kwargs) expect(crit.view.options["read"]).to eq({ "mode" => :primary }) crit end @@ -1670,8 +1670,8 @@ let(:word) { Word.create! } it "reads from the primary" do - expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args| - crit = m.call(*args) + expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs| + crit = m.call(*args, **kwargs) expect(crit.options[:read]).to eq({ mode: :primary }) crit end