Add decorator method to decorated model
This commit is contained in:
parent
464ffdfc04
commit
0711dc1413
|
@ -3,5 +3,6 @@ require 'draper/system'
|
||||||
require 'draper/all_helpers'
|
require 'draper/all_helpers'
|
||||||
require 'draper/base'
|
require 'draper/base'
|
||||||
require 'draper/lazy_helpers'
|
require 'draper/lazy_helpers'
|
||||||
|
require 'draper/model_support'
|
||||||
|
|
||||||
Draper::System.setup
|
Draper::System.setup
|
|
@ -21,6 +21,7 @@ module Draper
|
||||||
|
|
||||||
def self.decorates(input)
|
def self.decorates(input)
|
||||||
self.model_class = input.to_s.classify.constantize
|
self.model_class = input.to_s.classify.constantize
|
||||||
|
model_class.send :include, Draper::ModelSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.denies(*input_denied)
|
def self.denies(*input_denied)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
module Draper::ModelSupport
|
||||||
|
def decorator
|
||||||
|
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
|
||||||
|
end
|
||||||
|
end
|
|
@ -56,6 +56,12 @@ describe Draper::Base do
|
||||||
end
|
end
|
||||||
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
|
it "should wrap source methods so they still accept blocks" do
|
||||||
subject.block{"marker"}.should == "marker"
|
subject.block{"marker"}.should == "marker"
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue