Merge pull request #306 from dqminh/master

Memoize .helpers
This commit is contained in:
Steve Klabnik 2012-10-12 09:45:01 -07:00
commit cb3878a867
2 changed files with 8 additions and 1 deletions

View File

@ -185,7 +185,7 @@ module Draper
# #
# @return [Object] proxy # @return [Object] proxy
def helpers def helpers
HelpersWrapper.new self.class.helpers @helpers ||= HelpersWrapper.new self.class.helpers
end end
alias :h :helpers alias :h :helpers

View File

@ -28,6 +28,13 @@ describe Draper::Decorator do
it "is aliased to .h" do it "is aliased to .h" do
subject.h.should == subject.helpers subject.h.should == subject.helpers
end 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 end
context("#helpers") do context("#helpers") do