Ability to pass block to decorator method

This commit is contained in:
Eduard Tsech 2011-09-16 20:42:33 +02:00
parent 62d80310f4
commit 16f69ee07c
4 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,6 @@
module Draper::ModelSupport
def decorator
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
block_given? ? yield(@decorator) : @decorator
end
end

View File

@ -6,5 +6,10 @@ describe Draper::ModelSupport do
describe '#decorator' do
its(:decorator) { should be_kind_of(ProductDecorator) }
its(:decorator) { should be(subject.decorator) }
it 'should have abillity to pass block' do
a = Product.new.decorator { |d| d.awesome_title }
a.should eql "Awesome Title"
end
end
end

View File

@ -4,4 +4,4 @@ module ActiveRecord
name
end
end
end
end

View File

@ -1,3 +1,7 @@
class ProductDecorator < Draper::Base
decorates :product
def awesome_title
"Awesome Title"
end
end