1
0
Fork 0
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:
jarosluv 2016-09-22 18:13:04 +03:00 committed by Jaroslav Toropygin
parent 45e18569d9
commit c03370c9be
2 changed files with 28 additions and 0 deletions

View file

@ -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

View 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