1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge branch 'stable'

Conflicts:
	lib/haml/helpers/action_view_extensions.rb
	test/helper_test.rb
	test/test_helper.rb
This commit is contained in:
Norman Clarke 2014-12-01 10:14:48 -03:00
commit 08f97ec4dc
3 changed files with 14 additions and 61 deletions

View file

@ -83,7 +83,7 @@ module Haml
DOCTYPE_REGEX = /(\d(?:\.\d)?)?\s*([a-z]*)\s*([^ ]+)?/i
# The Regex that matches a literal string or symbol value
LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?!\\|\#{|\#@|\#\$|\2).|\\.)*\2/
LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?!\\|\#\{|\#@|\#\$|\2).|\\.)*\2/
ID_KEY = 'id'.freeze
CLASS_KEY = 'class'.freeze

View file

@ -137,52 +137,26 @@ HAML
end
def test_form_tag
# This is usually provided by ActionController::Base.
def @base.protect_against_forgery?; false; end
form_attrs = if Rails.version < '4.2.0'
%(accept-charset="UTF-8" action="foo" method="post")
else
%(action="foo" accept-charset="UTF-8" method="post")
end
assert_equal(<<HTML, render(<<HAML, :action_view))
<form #{form_attrs}>#{rails_form_opener}
<p>bar</p>
<strong>baz</strong>
</form>
HTML
rendered = render(<<HAML, :action_view)
= form_tag 'foo' do
%p bar
%strong baz
%p bar
%strong baz
HAML
fragment = Nokogiri::HTML.fragment(rendered)
assert_equal 'foo', fragment.css('form').first.attributes['action'].to_s
assert_equal 'bar', fragment.css('form p').first.text.strip
assert_equal 'baz', fragment.css('form strong').first.text.strip
end
def test_form_for
form_attrs = if Rails.version < '4.2.0'
%(accept-charset="UTF-8" action="foo" class="new_post" id="new_post" method="post")
else
%(class="new_post" id="new_post" action="foo" accept-charset="UTF-8" method="post")
end
input_attrs = if Rails.version < '4.2.0'
size_attribute = Rails.version < '4.0.0' ? 'size="30" ' : ''
%(id="post_name" name="post[name]" ) << size_attribute << %(type="text")
else
%(type="text" name="post[name]" id="post_name")
end
# FIXME: current HAML doesn't do proper indentation with form_for (it's the capture { output } in #form_for).
def @base.protect_against_forgery?; false; end
assert_equal(<<HTML, render(<<HAML, :action_view))
<form #{form_attrs}>#{rails_form_opener}<input #{input_attrs} />
</form>
HTML
rendered = render(<<HAML, :action_view)
= form_for OpenStruct.new, url: 'foo', as: :post do |f|
= f.text_field :name
HAML
assert_match(/<div[^>]+><input/, rendered)
end
def test_pre
@ -277,18 +251,10 @@ HAML
def test_form_tag_in_helper_with_string_block
def @base.protect_against_forgery?; false; end
form_attrs = if Rails.version < '4.2.0'
%(accept-charset="UTF-8" action="/foo" method="post")
else
%(action="/foo" accept-charset="UTF-8" method="post")
end
assert_equal(<<HTML, render(<<HAML, :action_view))
<form #{form_attrs}>#{rails_form_opener}bar</form>
HTML
= wacky_form
HAML
rendered = render('= wacky_form', :action_view)
fragment = Nokogiri::HTML.fragment(rendered)
assert_equal 'bar', fragment.text.strip
assert_equal '/foo', fragment.css('form').first.attributes['action'].to_s
end
def test_haml_tag_name_attribute_with_id

View file

@ -81,18 +81,6 @@ class Haml::TestCase < BASE_TEST_CLASS
Haml::Util.silence_warnings(&block)
end
# Rails hidden_fields behavior changed here: https://github.com/rails/rails/commit/7a085dac2
# and again here: https://github.com/rails/rails/commit/89ff1f82f0
def rails_form_opener
if Rails.version < '4.1.0'
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>'
elsif Rails.version < '4.2.0'
'<div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /></div>'
else
'<input name="utf8" type="hidden" value="&#x2713;" />'
end
end
def assert_raises_message(klass, message)
yield
rescue Exception => e
@ -105,5 +93,4 @@ class Haml::TestCase < BASE_TEST_CLASS
def self.error(*args)
Haml::Error.message(*args)
end
end