Skip to content

Commit

Permalink
[Haml] Fix some tests to work with Rails 3 RC.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jul 27, 2010
1 parent 5b053f3 commit 41b0973
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/haml/helper_test.rb
Expand Up @@ -118,7 +118,7 @@ def test_form_tag
# This is usually provided by ActionController::Base.
def @base.protect_against_forgery?; false; end
assert_equal(<<HTML, render(<<HAML, :action_view))
<form action="foo" method="post">
<form #{rails_form_attr}action="foo" method="post">#{rails_form_opener}
<p>bar</p>
<strong>baz</strong>
</form>
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_content_tag_error_wrapping
def @base.protect_against_forgery?; false; end
error_class = Haml::Util.ap_geq_3? ? "field_with_errors" : "fieldWithErrors"
assert_equal(<<HTML, render(<<HAML, :action_view))
<form action="" method="post">
<form #{rails_form_attr}action="" method="post">#{rails_form_opener}
<div class="#{error_class}"><label for="post_error_field">Error field</label></div>
</form>
HTML
Expand Down
4 changes: 2 additions & 2 deletions test/haml/template_test.rb
Expand Up @@ -280,7 +280,7 @@ def test_exceptions_should_work_correctly
def test_av_block_deprecation_warning
assert_warning(/^DEPRECATION WARNING: - style block helpers are deprecated\. Please use =\./) do
assert_equal <<HTML, render(<<HAML, :action_view)
<form action="" method="post">
<form #{rails_form_attr}action="" method="post">#{rails_form_opener}
Title:
<input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
Body:
Expand Down Expand Up @@ -379,7 +379,7 @@ def test_xss_protection_with_nested_haml_tag

def test_xss_protection_with_form_for
assert_equal(<<HTML, render(<<HAML, :action_view))
<form action="" method="post">
<form #{rails_form_attr}action="" method="post">#{rails_form_opener}
Title:
<input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
Body:
Expand Down
10 changes: 10 additions & 0 deletions test/test_helper.rb
Expand Up @@ -68,4 +68,14 @@ def form_for_calling_convention(name)
return "@#{name}, :as => :#{name}, :html => {:class => nil, :id => nil}" if Haml::Util.ap_geq_3?
return ":#{name}, @#{name}"
end

def rails_form_attr
return 'accept-charset="UTF-8" ' if Haml::Util.ap_geq?("3.0.0.rc")
return ''
end

def rails_form_opener
return '' unless Haml::Util.ap_geq?("3.0.0.rc")
return '<div style="margin:0;padding:0;display:inline"><input name="_snowman" type="hidden" value="&#9731;" /></div>'
end
end

0 comments on commit 41b0973

Please sign in to comment.