Add preservation of decorator options on QueryMethods (#868)
This commit is contained in:
parent
eb3468238f
commit
661c1a9f0f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue