Permalink
Browse files

Merge pull request #306 from dqminh/master

Memoize .helpers
  • Loading branch information...
2 parents a8e46e2 + e2a757d commit cb3878a867d3003a5369567c3819b56d4099f253 @steveklabnik steveklabnik committed Oct 12, 2012
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/draper/decorator.rb
  2. +7 −0 spec/draper/decorator_spec.rb
View
@@ -185,7 +185,7 @@ def ==(other)
#
# @return [Object] proxy
def helpers
- HelpersWrapper.new self.class.helpers
+ @helpers ||= HelpersWrapper.new self.class.helpers
end
alias :h :helpers
@@ -28,6 +28,13 @@
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

0 comments on commit cb3878a

Please sign in to comment.