Make helpers available from a decorator's class methods

This commit is contained in:
Jeff Casimir 2011-10-20 02:17:05 -04:00
parent e644f777d2
commit 4ead10a5b9
2 changed files with 26 additions and 1 deletions

View File

@ -100,10 +100,21 @@ module Draper
# Rails helpers. Aliased to `.h` for convinience.
#
# @return [Object] proxy
def helpers
self.class.helpers
end
alias :h :helpers
# Access the helpers proxy to call built-in and user-defined
# Rails helpers from a class context.
#
# @return [Object] proxy
class << self
def helpers
Thread.current[:current_view_context]
end
alias :h :helpers
end
# Fetch the original wrapped model.
#

View File

@ -24,6 +24,20 @@ describe Draper::Base do
it "should have a valid view_context" do
subject.helpers.should be
end
it "should be aliased to .h" do
subject.h.should == subject.helpers
end
end
context("#helpers") do
it "should have a valid view_context" do
Decorator.helpers.should be
end
it "should be aliased to #h" do
Decorator.h.should == Decorator.helpers
end
end
context(".decorates") do