mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Merge pull request #238 from fringd/master
fix problem with html_escape being private
This commit is contained in:
commit
c54341c1d9
4 changed files with 31 additions and 2 deletions
|
@ -161,12 +161,30 @@ module Draper
|
|||
decorate(model_class.last, options)
|
||||
end
|
||||
|
||||
# Some helpers are private, for example html_escape... as a workaround
|
||||
# we are wrapping the helpers in a delegator that passes the methods
|
||||
# along through a send, which will ignore private/public distinctions
|
||||
class HelpersWrapper
|
||||
def initialize(helpers)
|
||||
@helpers = helpers
|
||||
end
|
||||
|
||||
def method_missing(method, *args, &block)
|
||||
@helpers.send(method, *args, &block)
|
||||
end
|
||||
|
||||
#needed for tests
|
||||
def ==(other)
|
||||
other.instance_variable_get(:@helpers) == @helpers
|
||||
end
|
||||
end
|
||||
|
||||
# Access the helpers proxy to call built-in and user-defined
|
||||
# Rails helpers. Aliased to `.h` for convenience.
|
||||
#
|
||||
# @return [Object] proxy
|
||||
def helpers
|
||||
self.class.helpers
|
||||
HelpersWrapper.new self.class.helpers
|
||||
end
|
||||
alias :h :helpers
|
||||
|
||||
|
|
|
@ -706,9 +706,13 @@ describe Draper::Base do
|
|||
|
||||
it "is able to use l rather than helpers.l" do
|
||||
now = Time.now
|
||||
decorator.helpers.should_receive(:localize).with(now)
|
||||
decorator.helpers.instance_variable_get(:@helpers).should_receive(:localize).with(now)
|
||||
decorator.l now
|
||||
end
|
||||
|
||||
it "is able to access html_escape, a private method" do
|
||||
decorator.sample_html_escaped_text.should == '<script>danger</script>'
|
||||
end
|
||||
end
|
||||
|
||||
context "#method_missing" do
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
require 'active_support/core_ext/string/output_safety.rb'
|
||||
module ApplicationHelper
|
||||
include ERB::Util
|
||||
|
||||
def hello_world
|
||||
"Hello, World!"
|
||||
end
|
||||
|
|
|
@ -18,4 +18,8 @@ class DecoratorWithApplicationHelper < Draper::Base
|
|||
def length
|
||||
"overridden"
|
||||
end
|
||||
|
||||
def sample_html_escaped_text
|
||||
h.html_escape '<script>danger</script>'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue