diff --git a/lib/draper/decorator.rb b/lib/draper/decorator.rb index d870bd4..e65e9ed 100755 --- a/lib/draper/decorator.rb +++ b/lib/draper/decorator.rb @@ -185,7 +185,7 @@ module Draper # # @return [Object] proxy def helpers - HelpersWrapper.new self.class.helpers + @helpers ||= HelpersWrapper.new self.class.helpers end alias :h :helpers diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index be9ed41..31ce11e 100755 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -28,6 +28,13 @@ describe Draper::Decorator do it "is aliased to .h" do subject.h.should == subject.helpers end + + it "initializes the wrapper only once" do + helper_proxy = subject.helpers + helper_proxy.stub(:test_method) { "test_method" } + subject.helpers.test_method.should eq("test_method") + subject.helpers.test_method.should eq("test_method") + end end context("#helpers") do