[Haml] Expect non-String return values from with_output_buffer.

This commit is contained in:
Nathan Weizenbaum 2010-03-21 16:16:01 -07:00
parent be8080b271
commit 2aab52cda5
3 changed files with 20 additions and 1 deletions

View File

@ -18,6 +18,8 @@
* Don't crash when methods like `form_for` return `nil` in, for example, Rails 3 beta.
* Compatibility with Rails 3 beta's RJS facilities.
## 2.2.21
[Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.21).

View File

@ -99,7 +99,12 @@ module ActionView
module Helpers
module CaptureHelper
def with_output_buffer_with_haml_xss(*args, &block)
Haml::Util.html_safe(with_output_buffer_without_haml_xss(*args, &block))
res = with_output_buffer_without_haml_xss(*args, &block)
case res
when Array; res.map {|s| Haml::Util.html_safe(s)}
when String; Haml::Util.html_safe(res)
else; res
end
end
alias_method :with_output_buffer_without_haml_xss, :with_output_buffer
alias_method :with_output_buffer, :with_output_buffer_with_haml_xss

View File

@ -77,6 +77,9 @@ class TemplateTest < Test::Unit::TestCase
base.send(:_evaluate_assigns_and_ivars)
end
# This is needed by RJS in (at least) Rails 3
base.instance_variable_set('@template', base)
# This is used by form_for.
# It's usually provided by ActionController::Base.
def base.protect_against_forgery?; false; end
@ -369,6 +372,15 @@ HTML
= f.text_field :title
Body:
= f.text_field :body
HAML
end
def test_rjs
assert_equal(<<HTML, render(<<HAML, :action_view))
window.location.reload();
HTML
= update_page do |p|
- p.reload
HAML
end
end