mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Add decorator method to decorated model
This commit is contained in:
parent
464ffdfc04
commit
0711dc1413
5 changed files with 23 additions and 0 deletions
|
@ -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
|
|
@ -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)
|
||||
|
|
5
lib/draper/model_support.rb
Normal file
5
lib/draper/model_support.rb
Normal file
|
@ -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
|
||||
|
||||
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
|
||||
|
|
10
spec/draper/model_support_spec.rb
Normal file
10
spec/draper/model_support_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue