Make Draper::CollectionDecorator#object public

`Draper::Decorator#object` is public, so it would be consistent if
`Draper::CollectionDecorator#object` is also public. And it makes
sense to choose "public", because users should be able to access
the underlying objects.
This commit is contained in:
Janko Marohnić 2014-06-20 21:13:05 +02:00
parent ff41f17fa3
commit 5a8cce9c85
2 changed files with 12 additions and 3 deletions

View File

@ -4,6 +4,9 @@ module Draper
include Draper::ViewHelpers
extend Draper::Delegation
# @return the collection being decorated.
attr_reader :object
# @return [Class] the decorator class used to decorate each item, as set by
# {#initialize}.
attr_reader :decorator_class
@ -79,9 +82,6 @@ module Draper
protected
# @return the collection being decorated.
attr_reader :object
# Decorates the given item.
def decorate_item(item)
item_decorator.call(item, context: context)

View File

@ -238,6 +238,15 @@ module Draper
end
end
describe '#object' do
it 'returns the underlying collection' do
collection = [Product.new]
decorator = ProductsDecorator.new(collection)
expect(decorator.object).to eq collection
end
end
describe '#decorated?' do
it 'returns true' do
decorator = ProductsDecorator.new([Product.new])