mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Implementing application-wide 'decorate' view helper
This commit is contained in:
parent
b014e762e2
commit
67b8bc9bed
2 changed files with 23 additions and 0 deletions
5
lib/draper/helper_support.rb
Normal file
5
lib/draper/helper_support.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module Draper::HelperSupport
|
||||||
|
def decorate(input, &block)
|
||||||
|
capture { block.call(input.decorate) }
|
||||||
|
end
|
||||||
|
end
|
18
spec/draper/helper_support_spec.rb
Normal file
18
spec/draper/helper_support_spec.rb
Normal 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
|
Loading…
Reference in a new issue