aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/form_tag_helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/template/form_tag_helper_test.rb')
-rw-r--r--actionview/test/template/form_tag_helper_test.rb164
1 files changed, 82 insertions, 82 deletions
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 4fdca4976f..52f32e9f0e 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "abstract_unit"
class FormTagHelperTest < ActionView::TestCase
include RenderERBUtils
@@ -14,7 +14,7 @@ class FormTagHelperTest < ActionView::TestCase
method = options[:method]
enforce_utf8 = options.fetch(:enforce_utf8, true)
- ''.tap do |txt|
+ "".tap do |txt|
if enforce_utf8
txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
end
@@ -78,7 +78,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_check_box_tag_id_sanitized
label_elem = root_elem(check_box_tag("project[2][admin]"))
- assert_match VALID_HTML_ID, label_elem['id']
+ assert_match VALID_HTML_ID, label_elem["id"]
end
def test_form_tag
@@ -88,54 +88,54 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_form_tag_multipart
- actual = form_tag({}, { 'multipart' => true })
- expected = whole_form("http://www.example.com", :enctype => true)
+ actual = form_tag({}, "multipart" => true)
+ expected = whole_form("http://www.example.com", enctype: true)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_patch
- actual = form_tag({}, { :method => :patch })
- expected = whole_form("http://www.example.com", :method => :patch)
+ actual = form_tag({}, method: :patch)
+ expected = whole_form("http://www.example.com", method: :patch)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_put
- actual = form_tag({}, { :method => :put })
- expected = whole_form("http://www.example.com", :method => :put)
+ actual = form_tag({}, method: :put)
+ expected = whole_form("http://www.example.com", method: :put)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_delete
- actual = form_tag({}, { :method => :delete })
+ actual = form_tag({}, method: :delete)
- expected = whole_form("http://www.example.com", :method => :delete)
+ expected = whole_form("http://www.example.com", method: :delete)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote
- actual = form_tag({}, :remote => true)
+ actual = form_tag({}, remote: true)
- expected = whole_form("http://www.example.com", :remote => true)
+ expected = whole_form("http://www.example.com", remote: true)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote_false
- actual = form_tag({}, :remote => false)
+ actual = form_tag({}, remote: false)
expected = whole_form
assert_dom_equal expected, actual
end
def test_form_tag_enforce_utf8_true
- actual = form_tag({}, { :enforce_utf8 => true })
- expected = whole_form("http://www.example.com", :enforce_utf8 => true)
+ actual = form_tag({}, enforce_utf8: true)
+ expected = whole_form("http://www.example.com", enforce_utf8: true)
assert_dom_equal expected, actual
assert actual.html_safe?
end
def test_form_tag_enforce_utf8_false
- actual = form_tag({}, { :enforce_utf8 => false })
- expected = whole_form("http://www.example.com", :enforce_utf8 => false)
+ actual = form_tag({}, enforce_utf8: false)
+ expected = whole_form("http://www.example.com", enforce_utf8: false)
assert_dom_equal expected, actual
assert actual.html_safe?
end
@@ -150,7 +150,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_form_tag_with_block_and_method_in_erb
output_buffer = render_erb("<%= form_tag('http://www.example.com', :method => :put) do %>Hello world!<% end %>")
- expected = whole_form("http://www.example.com", :method => "put") do
+ expected = whole_form("http://www.example.com", method: "put") do
"Hello world!"
end
@@ -165,7 +165,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_hidden_field_tag_id_sanitized
input_elem = root_elem(hidden_field_tag("item[][title]"))
- assert_match VALID_HTML_ID, input_elem['id']
+ assert_match VALID_HTML_ID, input_elem["id"]
end
def test_file_field_tag
@@ -173,7 +173,7 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_file_field_tag_with_options
- assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", :class => "pix")
+ assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", class: "pix")
end
def test_password_field_tag
@@ -183,7 +183,7 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_multiple_field_tags_with_same_options
- options = {class: 'important'}
+ options = {class: "important"}
assert_dom_equal %(<input name="title" type="file" id="title" class="important"/>), file_field_tag("title", options)
assert_dom_equal %(<input type="password" name="title" id="title" value="Hello!" class="important" />), password_field_tag("title", "Hello!", options)
assert_dom_equal %(<input type="text" name="title" id="title" value="Hello!" class="important" />), text_field_tag("title", "Hello!", options)
@@ -210,7 +210,7 @@ class FormTagHelperTest < ActionView::TestCase
expected = %(<input id="person_gender_m" name="person[gender]" type="radio" value="m" />)
assert_dom_equal expected, actual
- actual = radio_button_tag('ctrlname', 'apache2.2')
+ actual = radio_button_tag("ctrlname", "apache2.2")
expected = %(<input id="ctrlname_apache2.2" name="ctrlname" type="radio" value="apache2.2" />)
assert_dom_equal expected, actual
end
@@ -235,7 +235,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_select_tag_id_sanitized
input_elem = root_elem(select_tag("project[1]people", "<option>david</option>"))
- assert_match VALID_HTML_ID, input_elem['id']
+ assert_match VALID_HTML_ID, input_elem["id"]
end
def test_select_tag_with_include_blank
@@ -251,19 +251,19 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_select_tag_with_include_blank_string
- actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), include_blank: 'Choose'
+ actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), include_blank: "Choose"
expected = %(<select id="places" name="places"><option value="">Choose</option><option>Home</option><option>Work</option><option>Pub</option></select>)
assert_dom_equal expected, actual
end
def test_select_tag_with_prompt
- actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :prompt => "string"
+ actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), prompt: "string"
expected = %(<select id="places" name="places"><option value="">string</option><option>Home</option><option>Work</option><option>Pub</option></select>)
assert_dom_equal expected, actual
end
def test_select_tag_escapes_prompt
- actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :prompt => "<script>alert(1337)</script>"
+ actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), prompt: "<script>alert(1337)</script>"
expected = %(<select id="places" name="places"><option value="">&lt;script&gt;alert(1337)&lt;/script&gt;</option><option>Home</option><option>Work</option><option>Pub</option></select>)
assert_dom_equal expected, actual
end
@@ -275,13 +275,13 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_select_tag_with_nil_option_tags_and_include_blank
- actual = select_tag "places", nil, :include_blank => true
+ actual = select_tag "places", nil, include_blank: true
expected = %(<select id="places" name="places"><option value="" label=" "></option></select>)
assert_dom_equal expected, actual
end
def test_select_tag_with_nil_option_tags_and_prompt
- actual = select_tag "places", nil, :prompt => "string"
+ actual = select_tag "places", nil, prompt: "string"
expected = %(<select id="places" name="places"><option value="">string</option></select>)
assert_dom_equal expected, actual
end
@@ -293,36 +293,36 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_text_area_tag_size_symbol
- actual = text_area_tag "body", "hello world", :size => "20x40"
+ actual = text_area_tag "body", "hello world", size: "20x40"
expected = %(<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>)
assert_dom_equal expected, actual
end
def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
- actual = text_area_tag "body", "hello world", :size => 20
+ actual = text_area_tag "body", "hello world", size: 20
expected = %(<textarea id="body" name="body">\nhello world</textarea>)
assert_dom_equal expected, actual
end
def test_text_area_tag_id_sanitized
input_elem = root_elem(text_area_tag("item[][description]"))
- assert_match VALID_HTML_ID, input_elem['id']
+ assert_match VALID_HTML_ID, input_elem["id"]
end
def test_text_area_tag_escape_content
- actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40"
+ actual = text_area_tag "body", "<b>hello world</b>", size: "20x40"
expected = %(<textarea cols="20" id="body" name="body" rows="40">\n&lt;b&gt;hello world&lt;/b&gt;</textarea>)
assert_dom_equal expected, actual
end
def test_text_area_tag_unescaped_content
- actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40", :escape => false
+ actual = text_area_tag "body", "<b>hello world</b>", size: "20x40", escape: false
expected = %(<textarea cols="20" id="body" name="body" rows="40">\n<b>hello world</b></textarea>)
assert_dom_equal expected, actual
end
def test_text_area_tag_unescaped_nil_content
- actual = text_area_tag "body", nil, :escape => false
+ actual = text_area_tag "body", nil, escape: false
expected = %(<textarea id="body" name="body">\n</textarea>)
assert_dom_equal expected, actual
end
@@ -340,7 +340,7 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_text_field_tag_size_symbol
- actual = text_field_tag "title", "Hello!", :size => 75
+ actual = text_field_tag "title", "Hello!", size: 75
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
assert_dom_equal expected, actual
end
@@ -352,7 +352,7 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_text_field_tag_maxlength_symbol
- actual = text_field_tag "title", "Hello!", :maxlength => 75
+ actual = text_field_tag "title", "Hello!", maxlength: 75
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
assert_dom_equal expected, actual
end
@@ -370,20 +370,20 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_text_field_tag_with_placeholder_option
- actual = text_field_tag "title", "Hello!", placeholder: 'Enter search term...'
+ actual = text_field_tag "title", "Hello!", placeholder: "Enter search term..."
expected = %(<input id="title" name="title" placeholder="Enter search term..." type="text" value="Hello!" />)
assert_dom_equal expected, actual
end
def test_text_field_tag_with_multiple_options
- actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80
+ actual = text_field_tag "title", "Hello!", size: 70, maxlength: 80
expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />)
assert_dom_equal expected, actual
end
def test_text_field_tag_id_sanitized
input_elem = root_elem(text_field_tag("item[][title]"))
- assert_match VALID_HTML_ID, input_elem['id']
+ assert_match VALID_HTML_ID, input_elem["id"]
end
def test_label_tag_without_text
@@ -412,11 +412,11 @@ class FormTagHelperTest < ActionView::TestCase
def test_label_tag_id_sanitized
label_elem = root_elem(label_tag("item[title]"))
- assert_match VALID_HTML_ID, label_elem['for']
+ assert_match VALID_HTML_ID, label_elem["for"]
end
def test_label_tag_with_block
- assert_dom_equal('<label>Blocked</label>', label_tag { "Blocked" })
+ assert_dom_equal("<label>Blocked</label>", label_tag { "Blocked" })
end
def test_label_tag_with_block_and_argument
@@ -425,21 +425,21 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_label_tag_with_block_and_argument_and_options
- output = label_tag("clock", :id => "label_clock") { "Grandfather" }
+ output = label_tag("clock", id: "label_clock") { "Grandfather" }
assert_dom_equal('<label for="clock" id="label_clock">Grandfather</label>', output)
end
def test_boolean_options
- assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
- assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
- assert_dom_equal %(<input type="checkbox" />), tag(:input, :type => "checkbox", :checked => false)
- assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), :multiple => true)
- assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", raw("<option>david</option>"), :multiple => true)
- assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), :multiple => nil)
+ assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, "disabled" => true, :readonly => "yes")
+ assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, disabled: false, readonly: nil)
+ assert_dom_equal %(<input type="checkbox" />), tag(:input, type: "checkbox", checked: false)
+ assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), multiple: true)
+ assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", raw("<option>david</option>"), multiple: true)
+ assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), multiple: nil)
end
def test_stringify_symbol_keys
- actual = text_field_tag "title", "Hello!", :id => "admin"
+ actual = text_field_tag "title", "Hello!", id: "admin"
expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
assert_dom_equal expected, actual
end
@@ -447,7 +447,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_submit_tag
assert_dom_equal(
%(<input name='commit' data-disable-with="Saving..." onclick="alert(&#39;hello!&#39;)" type="submit" value="Save" />),
- submit_tag("Save", :onclick => "alert('hello!')", :data => { :disable_with => "Saving..." })
+ submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." })
)
end
@@ -471,42 +471,42 @@ class FormTagHelperTest < ActionView::TestCase
def test_submit_tag_having_data_disable_with_string
assert_dom_equal(
%(<input data-disable-with="Processing..." data-confirm="Are you sure?" name='commit' type="submit" value="Save" />),
- submit_tag("Save", { "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?" })
+ submit_tag("Save", "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?")
)
end
def test_submit_tag_having_data_disable_with_boolean
assert_dom_equal(
%(<input data-confirm="Are you sure?" name='commit' type="submit" value="Save" />),
- submit_tag("Save", { "data-disable-with" => false, "data-confirm" => "Are you sure?" })
+ submit_tag("Save", "data-disable-with" => false, "data-confirm" => "Are you sure?")
)
end
def test_submit_tag_having_data_hash_disable_with_boolean
assert_dom_equal(
%(<input data-confirm="Are you sure?" name='commit' type="submit" value="Save" />),
- submit_tag("Save", { :data => { :confirm => "Are you sure?", :disable_with => false } })
+ submit_tag("Save", data: { confirm: "Are you sure?", disable_with: false })
)
end
def test_submit_tag_with_no_onclick_options
assert_dom_equal(
%(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />),
- submit_tag("Save", :data => { :disable_with => "Saving..." })
+ submit_tag("Save", data: { disable_with: "Saving..." })
)
end
def test_submit_tag_with_confirmation
assert_dom_equal(
%(<input name='commit' type='submit' value='Save' data-confirm="Are you sure?" data-disable-with="Save" />),
- submit_tag("Save", :data => { :confirm => "Are you sure?" })
+ submit_tag("Save", data: { confirm: "Are you sure?" })
)
end
def test_submit_tag_doesnt_have_data_disable_with_twice
assert_equal(
%(<input type="submit" name="commit" value="Save" data-confirm="Are you sure?" data-disable-with="Processing..." />),
- submit_tag("Save", { "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?" })
+ submit_tag("Save", "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?")
)
end
@@ -528,56 +528,56 @@ class FormTagHelperTest < ActionView::TestCase
def test_button_tag_with_submit_type
assert_dom_equal(
%(<button name="button" type="submit">Save</button>),
- button_tag("Save", :type => "submit")
+ button_tag("Save", type: "submit")
)
end
def test_button_tag_with_button_type
assert_dom_equal(
%(<button name="button" type="button">Button</button>),
- button_tag("Button", :type => "button")
+ button_tag("Button", type: "button")
)
end
def test_button_tag_with_reset_type
assert_dom_equal(
%(<button name="button" type="reset">Reset</button>),
- button_tag("Reset", :type => "reset")
+ button_tag("Reset", type: "reset")
)
end
def test_button_tag_with_disabled_option
assert_dom_equal(
%(<button name="button" type="reset" disabled="disabled">Reset</button>),
- button_tag("Reset", :type => "reset", :disabled => true)
+ button_tag("Reset", type: "reset", disabled: true)
)
end
def test_button_tag_escape_content
assert_dom_equal(
%(<button name="button" type="reset" disabled="disabled">&lt;b&gt;Reset&lt;/b&gt;</button>),
- button_tag("<b>Reset</b>", :type => "reset", :disabled => true)
+ button_tag("<b>Reset</b>", type: "reset", disabled: true)
)
end
def test_button_tag_with_block
- assert_dom_equal('<button name="button" type="submit">Content</button>', button_tag { 'Content' })
+ assert_dom_equal('<button name="button" type="submit">Content</button>', button_tag { "Content" })
end
def test_button_tag_with_block_and_options
- output = button_tag(:name => 'temptation', :type => 'button') { content_tag(:strong, 'Do not press me') }
+ output = button_tag(name: "temptation", type: "button") { content_tag(:strong, "Do not press me") }
assert_dom_equal('<button name="temptation" type="button"><strong>Do not press me</strong></button>', output)
end
def test_button_tag_defaults_with_block_and_options
- output = button_tag(:name => 'temptation', :value => 'within') { content_tag(:strong, 'Do not press me') }
+ output = button_tag(name: "temptation", value: "within") { content_tag(:strong, "Do not press me") }
assert_dom_equal('<button name="temptation" value="within" type="submit" ><strong>Do not press me</strong></button>', output)
end
def test_button_tag_with_confirmation
assert_dom_equal(
%(<button name="button" type="submit" data-confirm="Are you sure?">Save</button>),
- button_tag("Save", :type => "submit", :data => { :confirm => "Are you sure?" })
+ button_tag("Save", type: "submit", data: { confirm: "Are you sure?" })
)
end
@@ -591,7 +591,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_image_submit_tag_with_confirmation
assert_dom_equal(
%(<input alt="Save" type="image" src="/images/save.gif" data-confirm="Are you sure?" />),
- image_submit_tag("save.gif", :data => { :confirm => "Are you sure?" })
+ image_submit_tag("save.gif", data: { confirm: "Are you sure?" })
)
end
@@ -652,12 +652,12 @@ class FormTagHelperTest < ActionView::TestCase
def test_number_field_tag
expected = %{<input name="quantity" max="9" id="quantity" type="number" min="1" />}
- assert_dom_equal(expected, number_field_tag("quantity", nil, :in => 1...10))
+ assert_dom_equal(expected, number_field_tag("quantity", nil, in: 1...10))
end
def test_range_input_tag
expected = %{<input name="volume" step="0.1" max="11" id="volume" type="range" min="0" />}
- assert_dom_equal(expected, range_field_tag("volume", nil, :in => 0..11, :step => 0.1))
+ assert_dom_equal(expected, range_field_tag("volume", nil, in: 0..11, step: 0.1))
end
def test_field_set_tag_in_erb
@@ -693,33 +693,33 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_text_area_tag_options_symbolize_keys_side_effects
- options = { :option => "random_option" }
+ options = { option: "random_option" }
text_area_tag "body", "hello world", options
- assert_equal options, { :option => "random_option" }
+ assert_equal options, option: "random_option"
end
def test_submit_tag_options_symbolize_keys_side_effects
- options = { :option => "random_option" }
+ options = { option: "random_option" }
submit_tag "submit value", options
- assert_equal options, { :option => "random_option" }
+ assert_equal options, option: "random_option"
end
def test_button_tag_options_symbolize_keys_side_effects
- options = { :option => "random_option" }
+ options = { option: "random_option" }
button_tag "button value", options
- assert_equal options, { :option => "random_option" }
+ assert_equal options, option: "random_option"
end
def test_image_submit_tag_options_symbolize_keys_side_effects
- options = { :option => "random_option" }
+ options = { option: "random_option" }
image_submit_tag "submit source", options
- assert_equal options, { :option => "random_option" }
+ assert_equal options, option: "random_option"
end
def test_image_label_tag_options_symbolize_keys_side_effects
- options = { :option => "random_option" }
+ options = { option: "random_option" }
label_tag "submit source", "title", options
- assert_equal options, { :option => "random_option" }
+ assert_equal options, option: "random_option"
end
def protect_against_forgery?
@@ -728,7 +728,7 @@ class FormTagHelperTest < ActionView::TestCase
private
- def root_elem(rendered_content)
- Nokogiri::HTML::DocumentFragment.parse(rendered_content).children.first # extract from nodeset
- end
+ def root_elem(rendered_content)
+ Nokogiri::HTML::DocumentFragment.parse(rendered_content).children.first # extract from nodeset
+ end
end