mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Make the previous work for older Rails versions.
Also add some tests.
This commit is contained in:
parent
f467bcf4ae
commit
083196b152
2 changed files with 29 additions and 4 deletions
|
@ -127,8 +127,10 @@ module ActionView
|
|||
|
||||
def content_tag(*args)
|
||||
html_tag = content_tag_with_haml(*args)
|
||||
return error_wrapping(html_tag) if respond_to?(:error_wrapping)
|
||||
return html_tag
|
||||
return html_tag unless respond_to?(:error_wrapping)
|
||||
return error_wrapping(html_tag) if method(:error_wrapping).arity == 1
|
||||
return html_tag unless object.respond_to?(:errors) && object.errors.respond_to?(:on)
|
||||
return error_wrapping(html_tag, object.errors.on(@method_name))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,18 @@ module Haml::Helpers
|
|||
end
|
||||
|
||||
class HelperTest < Test::Unit::TestCase
|
||||
Post = Struct.new('Post', :body)
|
||||
Post = Struct.new('Post', :body, :error_field, :errors)
|
||||
class PostErrors
|
||||
def on(name)
|
||||
return unless name == 'error_field'
|
||||
["Really bad error"]
|
||||
end
|
||||
alias_method :full_messages, :on
|
||||
|
||||
def [](name)
|
||||
on(name) || []
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
@base = ActionView::Base.new
|
||||
|
@ -26,7 +37,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
@base.controller.response = ActionController::Response.new
|
||||
end
|
||||
|
||||
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
|
||||
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz", nil, PostErrors.new))
|
||||
end
|
||||
|
||||
def render(text, options = {})
|
||||
|
@ -153,6 +164,18 @@ HTML
|
|||
HAML
|
||||
end
|
||||
|
||||
def test_content_tag_error_wrapping
|
||||
def @base.protect_against_forgery?; false; end
|
||||
assert_equal(<<HTML, render(<<HAML, :action_view))
|
||||
<form action="" method="post">
|
||||
<div class="fieldWithErrors"><label for="post_error_field">Error field</label></div>
|
||||
</form>
|
||||
HTML
|
||||
#{rails_block_helper_char} form_for #{form_for_calling_convention('post')}, :url => '' do |f|
|
||||
= f.label 'error_field'
|
||||
HAML
|
||||
end
|
||||
|
||||
def test_haml_tag_attribute_html_escaping
|
||||
assert_equal("<p id='foo&bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue