Skip to content

Commit

Permalink
MONGOID-5717 Fix some cases of missing **kwargs pass-thru (mongodb#5758)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Rybakov <[email protected]>
  • Loading branch information
johnnyshields and comandeo-mongo authored Dec 20, 2023
1 parent 65b9f7e commit 0ab88b9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/mongoid/scopable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/criteria/marshalable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions spec/mongoid/extensions/set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/mongoid/validatable/uniqueness_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ab88b9

Please sign in to comment.