Implementing application-wide 'decorate' view helper

This commit is contained in:
Jeff Casimir 2011-10-28 22:24:55 -04:00
parent b014e762e2
commit 67b8bc9bed
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,5 @@
module Draper::HelperSupport
def decorate(input, &block)
capture { block.call(input.decorate) }
end
end

View File

@ -0,0 +1,18 @@
require 'spec_helper'
describe Draper::HelperSupport do
before(:each){ @product = Product.new}
context '#decorate' do
it 'renders a block' do
output = ApplicationController.decorate(@product){|p| p.model.object_id }
output.should == @product.object_id
end
it 'uses #capture so Rails only renders the content once' do
ApplicationController.decorate(@product){|p| p.model.object_id }
ApplicationController.capture_triggered.should be
end
end
end