Add preservation of decorator options on QueryMethods (#868)

This commit is contained in:
Douglas Lutz 2020-01-03 18:17:34 -03:00 committed by Cliff Braton
parent eb3468238f
commit 661c1a9f0f
2 changed files with 9 additions and 2 deletions

View File

@ -6,7 +6,7 @@ module Draper
def method_missing(method, *args, &block)
return super unless strategy.allowed? method
object.send(method, *args, &block).decorate
object.send(method, *args, &block).decorate(with: decorator_class, context: context)
end
def respond_to_missing?(method, include_private = false)

View File

@ -11,7 +11,8 @@ module Draper
describe '#method_missing' do
let(:collection) { [ Post.new, Post.new ] }
let(:collection_decorator) { PostDecorator.decorate_collection(collection) }
let(:collection_context) { { user: 'foo' } }
let(:collection_decorator) { PostDecorator.decorate_collection(collection, context: collection_context) }
context 'when strategy allows collection to call the method' do
let(:results) { spy(:results) }
@ -26,6 +27,12 @@ module Draper
expect(results).to have_received(:decorate)
end
it 'calls the method on the collection and keeps the decoration options' do
collection_decorator.some_query_method
expect(results).to have_received(:decorate).with({ context: collection_context, with: PostDecorator })
end
end
context 'when strategy does not allow collection to call the method' do