Skip to content

Commit

Permalink
Correctly pass arguments to with
Browse files Browse the repository at this point in the history
  • Loading branch information
y-yagi committed May 24, 2024
1 parent 9ac75de commit 70daa4b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/draper/decoratable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ module Draper
scoped = [Product.new]
allow(Product).to receive(:all).and_return(scoped)

expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, {with: nil}).and_return(:decorated_collection)
expect(Product.decorate).to be :decorated_collection
end

Expand Down
4 changes: 2 additions & 2 deletions spec/draper/decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module Draper
it "creates a CollectionDecorator using itself for each item" do
object = [Model.new]

expect(CollectionDecorator).to receive(:new).with(object, with: Decorator)
expect(CollectionDecorator).to receive(:new).with(object, {with: Decorator})
Decorator.decorate_collection(object)
end

Expand All @@ -134,7 +134,7 @@ module Draper
it "creates a custom collection decorator using itself for each item" do
object = [Model.new]

expect(ProductsDecorator).to receive(:new).with(object, with: ProductDecorator)
expect(ProductsDecorator).to receive(:new).with(object, {with: ProductDecorator})
ProductDecorator.decorate_collection(object)
end

Expand Down
16 changes: 8 additions & 8 deletions spec/draper/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ module Draper
worker = ->(*){}
allow(Factory::Worker).to receive_messages new: worker

expect(worker).to receive(:call).with(baz: "qux", context: {foo: "bar"})
expect(worker).to receive(:call).with({baz: "qux", context: {foo: "bar"}})
factory.decorate(double, {baz: "qux"})
end

it "is overridden by explicitly-specified context" do
factory = Factory.new(context: {foo: "bar"})
factory = Factory.new({context: {foo: "bar"}})
worker = ->(*){}
allow(Factory::Worker).to receive_messages new: worker

expect(worker).to receive(:call).with(context: {baz: "qux"})
factory.decorate(double, context: {baz: "qux"})
expect(worker).to receive(:call).with({context: {baz: "qux"}})
factory.decorate(double, {context: {baz: "qux"}})
end
end
end
Expand All @@ -109,7 +109,7 @@ module Draper
allow(worker).to receive_messages decorator: decorator
context = {foo: "bar"}

expect(decorator).to receive(:call).with(anything(), context: context)
expect(decorator).to receive(:call).with(anything(), {context: context})
worker.call(context: ->{ context })
end

Expand Down Expand Up @@ -140,7 +140,7 @@ module Draper
allow(worker).to receive_messages decorator: decorator
context = {foo: "bar"}

expect(decorator).to receive(:call).with(anything(), context: context)
expect(decorator).to receive(:call).with(anything(), {context: context})
worker.call(context: context)
end
end
Expand All @@ -150,7 +150,7 @@ module Draper
decorator = ->(*){}
allow(worker).to receive_messages decorator: decorator

expect(decorator).to receive(:call).with(anything(), foo: "bar")
expect(decorator).to receive(:call).with(anything(), {foo: "bar"})
worker.call(foo: "bar", context_args: [])
end
end
Expand Down Expand Up @@ -228,7 +228,7 @@ module Draper
allow(object).to receive(:decorate){ nil }
worker = Factory::Worker.new(nil, object)

expect(decorator_class).to receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated)
expect(decorator_class).to receive(:decorate_collection).with(object, {foo: "bar", with: nil}).and_return(:decorated)
expect(worker.decorator.call(object, foo: "bar")).to be :decorated
end
end
Expand Down

0 comments on commit 70daa4b

Please sign in to comment.