Make helpers available from a decorator's class methods
This commit is contained in:
parent
e644f777d2
commit
4ead10a5b9
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue