mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Add undecorate_chain feature
This commit is contained in:
parent
45e18569d9
commit
c03370c9be
2 changed files with 28 additions and 0 deletions
|
@ -6,4 +6,12 @@ module Draper
|
|||
object
|
||||
end
|
||||
end
|
||||
|
||||
def self.undecorate_chain(object)
|
||||
if object.respond_to?(:decorated?) && object.decorated?
|
||||
undecorate_chain(object.object)
|
||||
else
|
||||
object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
20
spec/draper/undecorate_chain_spec.rb
Normal file
20
spec/draper/undecorate_chain_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Draper, '.undecorate_chain' do
|
||||
let!(:object) { Model.new }
|
||||
let!(:decorated_inner) { Class.new(Draper::Decorator).new(object) }
|
||||
let!(:decorated_outer) { Class.new(Draper::Decorator).new(decorated_inner) }
|
||||
|
||||
it 'undecorates full chain of decorated objects' do
|
||||
expect(Draper.undecorate_chain(decorated_outer)).to equal object
|
||||
end
|
||||
|
||||
it 'passes a non-decorated object through' do
|
||||
expect(Draper.undecorate_chain(object)).to equal object
|
||||
end
|
||||
|
||||
it 'passes a non-decorator object through' do
|
||||
object = Object.new
|
||||
expect(Draper.undecorate_chain(object)).to equal object
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue