Add decorator method to decorated model

This commit is contained in:
Paul Elliott 2011-08-07 22:07:40 -04:00
parent 464ffdfc04
commit 0711dc1413
5 changed files with 23 additions and 0 deletions

View File

@ -3,5 +3,6 @@ require 'draper/system'
require 'draper/all_helpers'
require 'draper/base'
require 'draper/lazy_helpers'
require 'draper/model_support'
Draper::System.setup

View File

@ -21,6 +21,7 @@ module Draper
def self.decorates(input)
self.model_class = input.to_s.classify.constantize
model_class.send :include, Draper::ModelSupport
end
def self.denies(*input_denied)

View File

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

View File

@ -56,6 +56,12 @@ describe Draper::Base do
end
end
context 'the decorated model' do
it 'receives the mixin' do
source.class.ancestors.include?(Draper::ModelSupport)
end
end
it "should wrap source methods so they still accept blocks" do
subject.block{"marker"}.should == "marker"
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
describe Draper::ModelSupport do
subject { Product.new }
describe '#decorator' do
its(:decorator) { should be_kind_of(ProductDecorator) }
its(:decorator) { should be(subject.decorator) }
end
end