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

@ -101,10 +101,21 @@ module Draper
#
# @return [Object] proxy
def helpers
Thread.current[:current_view_context]
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.
#
# @return [Object] original_model

View File

@ -23,8 +23,22 @@ describe Draper::Base do
context(".helpers") 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
it "sets the model class for the decorator" do