Make helpers available from a decorator's class methods
This commit is contained in:
parent
e644f777d2
commit
4ead10a5b9
|
@ -101,10 +101,21 @@ module Draper
|
||||||
#
|
#
|
||||||
# @return [Object] proxy
|
# @return [Object] proxy
|
||||||
def helpers
|
def helpers
|
||||||
Thread.current[:current_view_context]
|
self.class.helpers
|
||||||
end
|
end
|
||||||
alias :h :helpers
|
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.
|
# Fetch the original wrapped model.
|
||||||
#
|
#
|
||||||
# @return [Object] original_model
|
# @return [Object] original_model
|
||||||
|
|
|
@ -23,8 +23,22 @@ describe Draper::Base do
|
||||||
context(".helpers") do
|
context(".helpers") do
|
||||||
it "should have a valid view_context" do
|
it "should have a valid view_context" do
|
||||||
subject.helpers.should be
|
subject.helpers.should be
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be aliased to .h" do
|
||||||
|
subject.h.should == subject.helpers
|
||||||
end
|
end
|
||||||
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
|
context(".decorates") do
|
||||||
it "sets the model class for the decorator" do
|
it "sets the model class for the decorator" do
|
||||||
|
|
Loading…
Reference in New Issue