diff --git a/lib/draper/decorator.rb b/lib/draper/decorator.rb index 1b9f904..74672fe 100755 --- a/lib/draper/decorator.rb +++ b/lib/draper/decorator.rb @@ -196,7 +196,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 71f7805..0e1cd51 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