From 63fff600accb41b56a3e6ac403d9b1732de3086d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 6 Aug 2016 19:36:34 +0200 Subject: modernizes hash syntax in actionview --- .../test/template/active_model_helper_test.rb | 10 +- actionview/test/template/asset_tag_helper_test.rb | 34 +- actionview/test/template/atom_feed_helper_test.rb | 20 +- .../test/template/compiled_templates_test.rb | 18 +- actionview/test/template/date_helper_i18n_test.rb | 70 +-- actionview/test/template/date_helper_test.rb | 592 ++++++++++----------- actionview/test/template/digestor_test.rb | 2 +- .../test/template/form_collections_helper_test.rb | 56 +- actionview/test/template/form_helper_test.rb | 8 +- .../test/template/form_options_helper_i18n_test.rb | 8 +- .../test/template/form_options_helper_test.rb | 138 ++--- actionview/test/template/form_tag_helper_test.rb | 120 ++--- actionview/test/template/javascript_helper_test.rb | 2 +- actionview/test/template/log_subscriber_test.rb | 16 +- actionview/test/template/lookup_context_test.rb | 2 +- actionview/test/template/number_helper_test.rb | 36 +- actionview/test/template/render_test.rb | 198 +++---- actionview/test/template/streaming_render_test.rb | 34 +- actionview/test/template/tag_helper_test.rb | 40 +- actionview/test/template/test_case_test.rb | 40 +- actionview/test/template/test_test.rb | 2 +- .../test/template/testing/fixture_resolver_test.rb | 4 +- .../test/template/testing/null_resolver_test.rb | 2 +- actionview/test/template/text_helper_test.rb | 158 +++--- .../test/template/translation_helper_test.rb | 66 +-- actionview/test/template/url_helper_test.rb | 4 +- 26 files changed, 840 insertions(+), 840 deletions(-) (limited to 'actionview/test/template') diff --git a/actionview/test/template/active_model_helper_test.rb b/actionview/test/template/active_model_helper_test.rb index aa708b6706..1fba4298e8 100644 --- a/actionview/test/template/active_model_helper_test.rb +++ b/actionview/test/template/active_model_helper_test.rb @@ -50,28 +50,28 @@ class ActiveModelHelperTest < ActionView::TestCase def test_select_with_errors_and_blank_option expected_dom = %(
) - assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :include_blank => "Choose one...")) - assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :prompt => "Choose one...")) + assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], include_blank: "Choose one...")) + assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], prompt: "Choose one...")) end def test_date_select_with_errors assert_dom_equal( %(
\n\n\n
), - date_select("post", "updated_at", :discard_month => true, :discard_day => true, :start_year => 2004, :end_year => 2005) + date_select("post", "updated_at", discard_month: true, discard_day: true, start_year: 2004, end_year: 2005) ) end def test_datetime_select_with_errors assert_dom_equal( %(
\n\n\n\n : \n
), - datetime_select("post", "updated_at", :discard_year => true, :discard_month => true, :discard_day => true, :minute_step => 60) + datetime_select("post", "updated_at", discard_year: true, discard_month: true, discard_day: true, minute_step: 60) ) end def test_time_select_with_errors assert_dom_equal( %(
\n\n\n\n : \n
), - time_select("post", "updated_at", :minute_step => 60) + time_select("post", "updated_at", minute_step: 60) ) end diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 226bb236c6..135c3b5fab 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -306,7 +306,7 @@ class AssetTagHelperTest < ActionView::TestCase end def test_autodiscovery_link_tag_with_unknown_type - result = auto_discovery_link_tag(:xml, "/feed.xml", :type => "application/xml") + result = auto_discovery_link_tag(:xml, "/feed.xml", type: "application/xml") expected = %() assert_dom_equal expected, result end @@ -331,9 +331,9 @@ class AssetTagHelperTest < ActionView::TestCase def test_compute_asset_public_path assert_equal "/robots.txt", compute_asset_path("robots.txt") assert_equal "/robots.txt", compute_asset_path("/robots.txt") - assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", :type => :javascript) - assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", :type => :javascript) - assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", :type => :stylesheet) + assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", type: :javascript) + assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", type: :javascript) + assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", type: :stylesheet) end def test_auto_discovery_link_tag @@ -421,7 +421,7 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag_escapes_options - assert_dom_equal %(), stylesheet_link_tag("/file", :media => "" + actual = select_tag "places", raw(""), prompt: "" expected = %() 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 = %() 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 = %() assert_dom_equal expected, actual end @@ -293,13 +293,13 @@ 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 = %() 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 = %() assert_dom_equal expected, actual end @@ -310,19 +310,19 @@ class FormTagHelperTest < ActionView::TestCase end def test_text_area_tag_escape_content - actual = text_area_tag "body", "hello world", :size => "20x40" + actual = text_area_tag "body", "hello world", size: "20x40" expected = %() assert_dom_equal expected, actual end def test_text_area_tag_unescaped_content - actual = text_area_tag "body", "hello world", :size => "20x40", :escape => false + actual = text_area_tag "body", "hello world", size: "20x40", escape: false expected = %() 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 = %() 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 = %() 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 = %() assert_dom_equal expected, actual end @@ -376,7 +376,7 @@ class FormTagHelperTest < ActionView::TestCase 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 = %() assert_dom_equal expected, actual end @@ -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('', output) end def test_boolean_options assert_dom_equal %(), check_box_tag("admin", 1, true, "disabled" => true, :readonly => "yes") - assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) - assert_dom_equal %(), tag(:input, :type => "checkbox", :checked => false) - assert_dom_equal %(), select_tag("people", raw(""), :multiple => true) - assert_dom_equal %(), select_tag("people[]", raw(""), :multiple => true) - assert_dom_equal %(), select_tag("people", raw(""), :multiple => nil) + assert_dom_equal %(), check_box_tag("admin", 1, true, disabled: false, readonly: nil) + assert_dom_equal %(), tag(:input, type: "checkbox", checked: false) + assert_dom_equal %(), select_tag("people", raw(""), multiple: true) + assert_dom_equal %(), select_tag("people[]", raw(""), multiple: true) + assert_dom_equal %(), select_tag("people", raw(""), 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 = %() assert_dom_equal expected, actual end @@ -447,7 +447,7 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag assert_dom_equal( %(), - submit_tag("Save", :onclick => "alert('hello!')", :data => { :disable_with => "Saving..." }) + submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." }) ) end @@ -485,21 +485,21 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag_having_data_hash_disable_with_boolean assert_dom_equal( %(), - 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( %(), - submit_tag("Save", :data => { :disable_with => "Saving..." }) + submit_tag("Save", data: { disable_with: "Saving..." }) ) end def test_submit_tag_with_confirmation assert_dom_equal( %(), - submit_tag("Save", :data => { :confirm => "Are you sure?" }) + submit_tag("Save", data: { confirm: "Are you sure?" }) ) end @@ -528,35 +528,35 @@ class FormTagHelperTest < ActionView::TestCase def test_button_tag_with_submit_type assert_dom_equal( %(), - button_tag("Save", :type => "submit") + button_tag("Save", type: "submit") ) end def test_button_tag_with_button_type assert_dom_equal( %(), - button_tag("Button", :type => "button") + button_tag("Button", type: "button") ) end def test_button_tag_with_reset_type assert_dom_equal( %(), - button_tag("Reset", :type => "reset") + button_tag("Reset", type: "reset") ) end def test_button_tag_with_disabled_option assert_dom_equal( %(), - 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_tag("Reset", :type => "reset", :disabled => true) + button_tag("Reset", type: "reset", disabled: true) ) end @@ -565,19 +565,19 @@ class FormTagHelperTest < ActionView::TestCase 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('', 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('', output) end def test_button_tag_with_confirmation assert_dom_equal( %(), - 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( %(), - 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 = %{} - 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 = %{} - 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? diff --git a/actionview/test/template/javascript_helper_test.rb b/actionview/test/template/javascript_helper_test.rb index 01ebc8cae1..0468c845d2 100644 --- a/actionview/test/template/javascript_helper_test.rb +++ b/actionview/test/template/javascript_helper_test.rb @@ -53,7 +53,7 @@ class JavaScriptHelperTest < ActionView::TestCase def test_javascript_tag_with_options assert_dom_equal "", - javascript_tag("alert('hello')", :id => "the_js_tag") + javascript_tag("alert('hello')", id: "the_js_tag") end def test_javascript_cdata_section diff --git a/actionview/test/template/log_subscriber_test.rb b/actionview/test/template/log_subscriber_test.rb index f864999a8e..565eee6628 100644 --- a/actionview/test/template/log_subscriber_test.rb +++ b/actionview/test/template/log_subscriber_test.rb @@ -32,7 +32,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_file_template Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(:file => "test/hello_world") + @view.render(file: "test/hello_world") wait assert_equal 2, @logger.logged(:info).size @@ -43,7 +43,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_text_template Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(:text => "TEXT") + @view.render(text: "TEXT") wait assert_equal 2, @logger.logged(:info).size @@ -54,7 +54,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_inline_template Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(:inline => "<%= 'TEXT' %>") + @view.render(inline: "<%= 'TEXT' %>") wait assert_equal 2, @logger.logged(:info).size @@ -65,7 +65,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_partial_template Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(:partial => "test/customer") + @view.render(partial: "test/customer") wait assert_equal 1, @logger.logged(:info).size @@ -75,7 +75,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_partial_with_implicit_path Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(Customer.new("david"), :greeting => "hi") + @view.render(Customer.new("david"), greeting: "hi") wait assert_equal 1, @logger.logged(:info).size @@ -85,7 +85,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_collection_template Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) + @view.render(partial: "test/customer", collection: [ Customer.new("david"), Customer.new("mary") ]) wait assert_equal 1, @logger.logged(:info).size @@ -95,7 +95,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_collection_with_implicit_path Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi") + @view.render([ Customer.new("david"), Customer.new("mary") ], greeting: "hi") wait assert_equal 1, @logger.logged(:info).size @@ -105,7 +105,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def test_render_collection_template_without_path Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do - @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi") + @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], greeting: "hi") wait assert_equal 1, @logger.logged(:info).size diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 2e3a3f9bae..2a8ae9d4a3 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -279,7 +279,7 @@ class TestMissingTemplate < ActiveSupport::TestCase test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do e = assert_raise ActionView::MissingTemplate do - details = {:handlers=>[], :formats=>[], :variants=>[], :locale=>[]} + details = {handlers: [], formats: [], variants: [], locale: []} @lookup_context.view_paths.find("foo", "parent", true, details) end assert_match %r{Missing partial parent/_foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message diff --git a/actionview/test/template/number_helper_test.rb b/actionview/test/template/number_helper_test.rb index ed31b930dd..d55651bd4a 100644 --- a/actionview/test/template/number_helper_test.rb +++ b/actionview/test/template/number_helper_test.rb @@ -71,27 +71,27 @@ class NumberHelperTest < ActionView::TestCase def test_number_to_human_escape_units volume = { unit: "ml", thousand: "lt", million: "m3", trillion: "km3", quadrillion: "Pl" } - assert_equal "123 <b>lt</b>", number_to_human(123456, :units => volume) - assert_equal "12 <b>ml</b>", number_to_human(12, :units => volume) - assert_equal "1.23 <b>m3</b>", number_to_human(1234567, :units => volume) - assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, :units => volume) - assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, :units => volume) + assert_equal "123 <b>lt</b>", number_to_human(123456, units: volume) + assert_equal "12 <b>ml</b>", number_to_human(12, units: volume) + assert_equal "1.23 <b>m3</b>", number_to_human(1234567, units: volume) + assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, units: volume) + assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, units: volume) #Including fractionals distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km", micro: "um", nano: "nm", pico: "pm", femto: "fm"} - assert_equal "1.23 <b>mm</b>", number_to_human(0.00123, :units => distance) - assert_equal "1.23 <b>cm</b>", number_to_human(0.0123, :units => distance) - assert_equal "1.23 <b>dm</b>", number_to_human(0.123, :units => distance) - assert_equal "1.23 <b>m</b>", number_to_human(1.23, :units => distance) - assert_equal "1.23 <b>dam</b>", number_to_human(12.3, :units => distance) - assert_equal "1.23 <b>hm</b>", number_to_human(123, :units => distance) - assert_equal "1.23 <b>km</b>", number_to_human(1230, :units => distance) - assert_equal "1.23 <b>um</b>", number_to_human(0.00000123, :units => distance) - assert_equal "1.23 <b>nm</b>", number_to_human(0.00000000123, :units => distance) - assert_equal "1.23 <b>pm</b>", number_to_human(0.00000000000123, :units => distance) - assert_equal "1.23 <b>fm</b>", number_to_human(0.00000000000000123, :units => distance) + assert_equal "1.23 <b>mm</b>", number_to_human(0.00123, units: distance) + assert_equal "1.23 <b>cm</b>", number_to_human(0.0123, units: distance) + assert_equal "1.23 <b>dm</b>", number_to_human(0.123, units: distance) + assert_equal "1.23 <b>m</b>", number_to_human(1.23, units: distance) + assert_equal "1.23 <b>dam</b>", number_to_human(12.3, units: distance) + assert_equal "1.23 <b>hm</b>", number_to_human(123, units: distance) + assert_equal "1.23 <b>km</b>", number_to_human(1230, units: distance) + assert_equal "1.23 <b>um</b>", number_to_human(0.00000123, units: distance) + assert_equal "1.23 <b>nm</b>", number_to_human(0.00000000123, units: distance) + assert_equal "1.23 <b>pm</b>", number_to_human(0.00000000000123, units: distance) + assert_equal "1.23 <b>fm</b>", number_to_human(0.00000000000000123, units: distance) end def test_number_helpers_escape_delimiter_and_separator @@ -117,8 +117,8 @@ class NumberHelperTest < ActionView::TestCase def test_number_to_human_with_custom_translation_scope I18n.backend.store_translations "ts", - :custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} - assert_equal "1.01 cm", number_to_human(0.0101, :locale => "ts", :units => :custom_units_for_number_to_human) + custom_units_for_number_to_human: {mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"} + assert_equal "1.01 cm", number_to_human(0.0101, locale: "ts", units: :custom_units_for_number_to_human) ensure I18n.reload! end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 91c74e0ec2..173c2c4cec 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -6,7 +6,7 @@ end module RenderTestCases def setup_view(paths) - @assigns = { :secret => "in the sauce" } + @assigns = { secret: "in the sauce" } @view = Class.new(ActionView::Base) do def view_cache_dependencies; end @@ -31,73 +31,73 @@ module RenderTestCases end def test_render_file - assert_equal "Hello world!", @view.render(:file => "test/hello_world") + assert_equal "Hello world!", @view.render(file: "test/hello_world") end # Test if :formats, :locale etc. options are passed correctly to the resolvers. def test_render_file_with_format - assert_match "

No Comment

", @view.render(:file => "comments/empty", :formats => [:html]) - assert_match "No Comment", @view.render(:file => "comments/empty", :formats => [:xml]) - assert_match "No Comment", @view.render(:file => "comments/empty", :formats => :xml) + assert_match "

No Comment

", @view.render(file: "comments/empty", formats: [:html]) + assert_match "No Comment", @view.render(file: "comments/empty", formats: [:xml]) + assert_match "No Comment", @view.render(file: "comments/empty", formats: :xml) end def test_render_template_with_format - assert_match "

No Comment

", @view.render(:template => "comments/empty", :formats => [:html]) - assert_match "No Comment", @view.render(:template => "comments/empty", :formats => [:xml]) + assert_match "

No Comment

", @view.render(template: "comments/empty", formats: [:html]) + assert_match "No Comment", @view.render(template: "comments/empty", formats: [:xml]) end def test_rendered_format_without_format - @view.render(:inline => "test") + @view.render(inline: "test") assert_equal :html, @view.lookup_context.rendered_format end def test_render_partial_implicitly_use_format_of_the_rendered_template @view.lookup_context.formats = [:json] - assert_equal "Hello world", @view.render(:template => "test/one", :formats => [:html]) + assert_equal "Hello world", @view.render(template: "test/one", formats: [:html]) end def test_render_partial_implicitly_use_format_of_the_rendered_partial @view.lookup_context.formats = [:html] - assert_equal "Third level", @view.render(:template => "test/html_template") + assert_equal "Third level", @view.render(template: "test/html_template") end def test_render_partial_use_last_prepended_format_for_partials_with_the_same_names @view.lookup_context.formats = [:html] - assert_equal "\nHTML Template, but JSON partial", @view.render(:template => "test/change_priority") + assert_equal "\nHTML Template, but JSON partial", @view.render(template: "test/change_priority") end def test_render_template_with_a_missing_partial_of_another_format @view.lookup_context.formats = [:html] e = assert_raise ActionView::Template::Error do - @view.render(:template => "with_format", :formats => [:json]) + @view.render(template: "with_format", formats: [:json]) end assert_includes(e.message, "Missing partial /_missing with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.") end def test_render_file_with_locale - assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => [:de]) - assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => :de) + assert_equal "

Kein Kommentar

", @view.render(file: "comments/empty", locale: [:de]) + assert_equal "

Kein Kommentar

", @view.render(file: "comments/empty", locale: :de) end def test_render_template_with_locale - assert_equal "

Kein Kommentar

", @view.render(:template => "comments/empty", :locale => [:de]) + assert_equal "

Kein Kommentar

", @view.render(template: "comments/empty", locale: [:de]) end def test_render_file_with_handlers - assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => [:builder]) - assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => :builder) + assert_equal "

No Comment

\n", @view.render(file: "comments/empty", handlers: [:builder]) + assert_equal "

No Comment

\n", @view.render(file: "comments/empty", handlers: :builder) end def test_render_template_with_handlers - assert_equal "

No Comment

\n", @view.render(:template => "comments/empty", :handlers => [:builder]) + assert_equal "

No Comment

\n", @view.render(template: "comments/empty", handlers: [:builder]) end def test_render_raw_template_with_handlers - assert_equal "<%= hello_world %>\n", @view.render(:template => "plain_text") + assert_equal "<%= hello_world %>\n", @view.render(template: "plain_text") end def test_render_raw_template_with_quotes - assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(:template => "plain_text_with_characters") + assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(template: "plain_text_with_characters") end def test_render_raw_is_html_safe_and_does_not_escape_output @@ -108,47 +108,47 @@ module RenderTestCases end def test_render_ruby_template_with_handlers - assert_equal "Hello from Ruby code", @view.render(:template => "ruby_template") + assert_equal "Hello from Ruby code", @view.render(template: "ruby_template") end def test_render_ruby_template_inline - assert_equal "4", @view.render(:inline => "(2**2).to_s", :type => :ruby) + assert_equal "4", @view.render(inline: "(2**2).to_s", type: :ruby) end def test_render_file_with_localization_on_context_level old_locale, @view.locale = @view.locale, :da - assert_equal "Hey verden", @view.render(:file => "test/hello_world") + assert_equal "Hey verden", @view.render(file: "test/hello_world") ensure @view.locale = old_locale end def test_render_file_with_dashed_locale old_locale, @view.locale = @view.locale, :"pt-BR" - assert_equal "Ola mundo", @view.render(:file => "test/hello_world") + assert_equal "Ola mundo", @view.render(file: "test/hello_world") ensure @view.locale = old_locale end def test_render_file_at_top_level - assert_equal "Elastica", @view.render(:file => "/shared") + assert_equal "Elastica", @view.render(file: "/shared") end def test_render_file_with_full_path template_path = File.join(File.dirname(__FILE__), "../fixtures/test/hello_world") - assert_equal "Hello world!", @view.render(:file => template_path) + assert_equal "Hello world!", @view.render(file: template_path) end def test_render_file_with_instance_variables - assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar") + assert_equal "The secret is in the sauce\n", @view.render(file: "test/render_file_with_ivar") end def test_render_file_with_locals - locals = { :secret => "in the sauce" } - assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals", :locals => locals) + locals = { secret: "in the sauce" } + assert_equal "The secret is in the sauce\n", @view.render(file: "test/render_file_with_locals", locals: locals) end def test_render_file_not_using_full_path_with_dot_in_path - assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar") + assert_equal "The secret is in the sauce\n", @view.render(file: "test/dot.directory/render_file_with_ivar") end def test_render_partial_from_default @@ -158,82 +158,82 @@ module RenderTestCases def test_render_outside_path assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb")) assert_raises ActionView::MissingTemplate do - @view.render(:template => "../\\../test/abstract_unit.rb") + @view.render(template: "../\\../test/abstract_unit.rb") end end def test_render_partial - assert_equal "only partial", @view.render(:partial => "test/partial_only") + assert_equal "only partial", @view.render(partial: "test/partial_only") end def test_render_partial_with_format - assert_equal "partial html", @view.render(:partial => "test/partial") + assert_equal "partial html", @view.render(partial: "test/partial") end def test_render_partial_with_selected_format - assert_equal "partial html", @view.render(:partial => "test/partial", :formats => :html) - assert_equal "partial js", @view.render(:partial => "test/partial", :formats => [:js]) + assert_equal "partial html", @view.render(partial: "test/partial", formats: :html) + assert_equal "partial js", @view.render(partial: "test/partial", formats: [:js]) end def test_render_partial_at_top_level # file fixtures/_top_level_partial_only (not fixtures/test) - assert_equal "top level partial", @view.render(:partial => "/top_level_partial_only") + assert_equal "top level partial", @view.render(partial: "/top_level_partial_only") end def test_render_partial_with_format_at_top_level # file fixtures/_top_level_partial.html (not fixtures/test, with format extension) - assert_equal "top level partial html", @view.render(:partial => "/top_level_partial") + assert_equal "top level partial html", @view.render(partial: "/top_level_partial") end def test_render_partial_with_locals - assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) + assert_equal "5", @view.render(partial: "test/counter", locals: { counter_counter: 5 }) end def test_render_partial_with_locals_from_default - assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5) + assert_equal "only partial", @view.render("test/partial_only", counter_counter: 5) end def test_render_partial_with_number - assert_nothing_raised { @view.render(:partial => "test/200") } + assert_nothing_raised { @view.render(partial: "test/200") } end def test_render_partial_with_missing_filename - assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/") } + assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/") } end def test_render_partial_with_incompatible_object - e = assert_raises(ArgumentError) { @view.render(:partial => nil) } + e = assert_raises(ArgumentError) { @view.render(partial: nil) } assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message end def test_render_partial_starting_with_a_capital - assert_nothing_raised { @view.render(:partial => "test/FooBar") } + assert_nothing_raised { @view.render(partial: "test/FooBar") } end def test_render_partial_with_hyphen - assert_nothing_raised { @view.render(:partial => "test/a-in") } + assert_nothing_raised { @view.render(partial: "test/a-in") } end def test_render_partial_with_unicode_text - assert_nothing_raised { @view.render(:partial => "test/🍣") } + assert_nothing_raised { @view.render(partial: "test/🍣") } end def test_render_partial_with_invalid_option_as - e = assert_raises(ArgumentError) { @view.render(:partial => "test/partial_only", :as => "a-in") } + e = assert_raises(ArgumentError) { @view.render(partial: "test/partial_only", as: "a-in") } assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " + "make sure it starts with lowercase letter, " + "and is followed by any combination of letters, numbers and underscores.", e.message end def test_render_partial_with_hyphen_and_invalid_option_as - e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in", :as => "a-in") } + e = assert_raises(ArgumentError) { @view.render(partial: "test/a-in", as: "a-in") } assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " + "make sure it starts with lowercase letter, " + "and is followed by any combination of letters, numbers and underscores.", e.message end def test_render_partial_with_errors - e = assert_raises(ActionView::Template::Error) { @view.render(:partial => "test/raise") } + e = assert_raises(ActionView::Template::Error) { @view.render(partial: "test/raise") } assert_match %r!method.*doesnt_exist!, e.message assert_equal "", e.sub_template_message assert_equal "1", e.line_number @@ -242,7 +242,7 @@ module RenderTestCases end def test_render_error_indentation - e = assert_raises(ActionView::Template::Error) { @view.render(:partial => "test/raise_indentation") } + e = assert_raises(ActionView::Template::Error) { @view.render(partial: "test/raise_indentation") } error_lines = e.annoted_source_code assert_match %r!error\shere!, e.message assert_equal "11", e.line_number @@ -251,7 +251,7 @@ module RenderTestCases end def test_render_sub_template_with_errors - e = assert_raises(ActionView::Template::Error) { @view.render(:template => "test/sub_template_raise") } + e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/sub_template_raise") } assert_match %r!method.*doesnt_exist!, e.message assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message assert_equal "1", e.line_number @@ -259,7 +259,7 @@ module RenderTestCases end def test_render_file_with_errors - e = assert_raises(ActionView::Template::Error) { @view.render(:file => File.expand_path("test/_raise", FIXTURE_LOAD_PATH)) } + e = assert_raises(ActionView::Template::Error) { @view.render(file: File.expand_path("test/_raise", FIXTURE_LOAD_PATH)) } assert_match %r!method.*doesnt_exist!, e.message assert_equal "", e.sub_template_message assert_equal "1", e.line_number @@ -268,45 +268,45 @@ module RenderTestCases end def test_render_object - assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david")) - assert_equal "FalseClass", @view.render(:partial => "test/klass", :object => false) - assert_equal "NilClass", @view.render(:partial => "test/klass", :object => nil) + assert_equal "Hello: david", @view.render(partial: "test/customer", object: Customer.new("david")) + assert_equal "FalseClass", @view.render(partial: "test/klass", object: false) + assert_equal "NilClass", @view.render(partial: "test/klass", object: nil) end def test_render_object_with_array - assert_equal "[1, 2, 3]", @view.render(:partial => "test/object_inspector", :object => [1, 2, 3]) + assert_equal "[1, 2, 3]", @view.render(partial: "test/object_inspector", object: [1, 2, 3]) end def test_render_partial_collection - assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) + assert_equal "Hello: davidHello: mary", @view.render(partial: "test/customer", collection: [ Customer.new("david"), Customer.new("mary") ]) end def test_render_partial_collection_with_partial_name_containing_dot assert_equal "Hello: davidHello: mary", - @view.render(:partial => "test/customer.mobile", :collection => [ Customer.new("david"), Customer.new("mary") ]) + @view.render(partial: "test/customer.mobile", collection: [ Customer.new("david"), Customer.new("mary") ]) end def test_render_partial_collection_as_by_string assert_equal "david david davidmary mary mary", - @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => "customer") + @view.render(partial: "test/customer_with_var", collection: [ Customer.new("david"), Customer.new("mary") ], as: "customer") end def test_render_partial_collection_as_by_symbol assert_equal "david david davidmary mary mary", - @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer) + @view.render(partial: "test/customer_with_var", collection: [ Customer.new("david"), Customer.new("mary") ], as: :customer) end def test_render_partial_collection_without_as assert_equal "local_inspector,local_inspector_counter,local_inspector_iteration", - @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ]) + @view.render(partial: "test/local_inspector", collection: [ Customer.new("mary") ]) end def test_render_partial_with_empty_collection_should_return_nil - assert_nil @view.render(:partial => "test/customer", :collection => []) + assert_nil @view.render(partial: "test/customer", collection: []) end def test_render_partial_with_nil_collection_should_return_nil - assert_nil @view.render(:partial => "test/customer", :collection => nil) + assert_nil @view.render(partial: "test/customer", collection: nil) end def test_render_partial_collection_for_non_array @@ -326,30 +326,30 @@ module RenderTestCases end def test_render_partial_with_nil_values_in_collection - assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ]) + assert_equal "Hello: davidHello: Anonymous", @view.render(partial: "test/customer", collection: [ Customer.new("david"), nil ]) end def test_render_partial_with_layout_using_collection_and_template - assert_equal "Hello: AmazonHello: Yahoo", @view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ]) + assert_equal "Hello: AmazonHello: Yahoo", @view.render(partial: "test/customer", layout: "test/b_layout_for_partial", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ]) end def test_render_partial_with_layout_using_collection_and_template_makes_current_item_available_in_layout assert_equal 'Hello: AmazonHello: Yahoo', - @view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ]) + @view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ]) end def test_render_partial_with_layout_using_collection_and_template_makes_current_item_counter_available_in_layout assert_equal 'Hello: AmazonHello: Yahoo', - @view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object_counter", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ]) + @view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object_counter", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ]) end def test_render_partial_with_layout_using_object_and_template_makes_object_available_in_layout assert_equal 'Hello: Amazon', - @view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object", :object => Customer.new("Amazon")) + @view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object", object: Customer.new("Amazon")) end def test_render_partial_with_empty_array_should_return_nil - assert_nil @view.render(:partial => []) + assert_nil @view.render(partial: []) end def test_render_partial_using_string @@ -357,28 +357,28 @@ module RenderTestCases end def test_render_partial_with_locals_using_string - assert_equal "Hola: david", @controller_view.render("customer_greeting", :greeting => "Hola", :customer_greeting => Customer.new("david")) + assert_equal "Hola: david", @controller_view.render("customer_greeting", greeting: "Hola", customer_greeting: Customer.new("david")) end def test_render_partial_with_object_uses_render_partial_path assert_equal "Hello: lifo", - @controller_view.render(:partial => Customer.new("lifo"), :locals => {:greeting => "Hello"}) + @controller_view.render(partial: Customer.new("lifo"), locals: {greeting: "Hello"}) end def test_render_partial_with_object_and_format_uses_render_partial_path assert_equal "Hellolifo", - @controller_view.render(:partial => Customer.new("lifo"), :formats => :xml, :locals => {:greeting => "Hello"}) + @controller_view.render(partial: Customer.new("lifo"), formats: :xml, locals: {greeting: "Hello"}) end def test_render_partial_using_object assert_equal "Hello: lifo", - @controller_view.render(Customer.new("lifo"), :greeting => "Hello") + @controller_view.render(Customer.new("lifo"), greeting: "Hello") end def test_render_partial_using_collection customers = [ Customer.new("Amazon"), Customer.new("Yahoo") ] assert_equal "Hello: AmazonHello: Yahoo", - @controller_view.render(customers, :greeting => "Hello") + @controller_view.render(customers, greeting: "Hello") end def test_render_partial_using_collection_without_path @@ -395,32 +395,32 @@ module RenderTestCases # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout - assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) + assert_equal "Before (Josh)\n\nAfter", @view.render(partial: "test/layout_for_partial", locals: { name: "Josh" }) end # TODO: The reason for this test is unclear, improve documentation def test_render_missing_xml_partial_and_raise_missing_template @view.formats = [:xml] - assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/layout_for_partial") } + assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/layout_for_partial") } ensure @view.formats = nil end def test_render_layout_with_block_and_other_partial_inside - render = @view.render(:layout => "test/layout_with_partial_and_yield") { "Yield!" } + render = @view.render(layout: "test/layout_with_partial_and_yield") { "Yield!" } assert_equal "Before\npartial html\nYield!\nAfter\n", render end def test_render_inline - assert_equal "Hello, World!", @view.render(:inline => "Hello, World!") + assert_equal "Hello, World!", @view.render(inline: "Hello, World!") end def test_render_inline_with_locals - assert_equal "Hello, Josh!", @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }) + assert_equal "Hello, Josh!", @view.render(inline: "Hello, <%= name %>!", locals: { name: "Josh" }) end def test_render_fallbacks_to_erb_for_unknown_types - assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar) + assert_equal "Hello, World!", @view.render(inline: "Hello, World!", type: :bar) end CustomHandler = lambda do |template| @@ -478,54 +478,54 @@ module RenderTestCases ActiveSupport::Deprecation.silence do %w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name| assert File.exist?(File.expand_path("#{FIXTURE_LOAD_PATH}/test/malformed/#{name}~")), "Malformed file (#{name}~) which should be ignored does not exists" - assert_raises(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") } + assert_raises(ActionView::MissingTemplate) { @view.render(file: "test/malformed/#{name}") } end end end def test_render_with_layout assert_equal %(\nHello world!\n), - @view.render(:file => "test/hello_world", :layout => "layouts/yield") + @view.render(file: "test/hello_world", layout: "layouts/yield") end def test_render_with_layout_which_has_render_inline assert_equal %(welcome\nHello world!\n), - @view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside") + @view.render(file: "test/hello_world", layout: "layouts/yield_with_render_inline_inside") end def test_render_with_layout_which_renders_another_partial assert_equal %(partial html\nHello world!\n), - @view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside") + @view.render(file: "test/hello_world", layout: "layouts/yield_with_render_partial_inside") end def test_render_partial_with_html_only_extension assert_equal %(

partial html

\nHello world!\n), - @view.render(:file => "test/hello_world", :layout => "layouts/render_partial_html") + @view.render(file: "test/hello_world", layout: "layouts/render_partial_html") end def test_render_layout_with_block_and_yield assert_equal %(Content from block!\n), - @view.render(:layout => "layouts/yield_only") { "Content from block!" } + @view.render(layout: "layouts/yield_only") { "Content from block!" } end def test_render_layout_with_block_and_yield_with_params assert_equal %(Yield! Content from block!\n), - @view.render(:layout => "layouts/yield_with_params") { |param| "#{param} Content from block!" } + @view.render(layout: "layouts/yield_with_params") { |param| "#{param} Content from block!" } end def test_render_layout_with_block_which_renders_another_partial_and_yields assert_equal %(partial html\nContent from block!\n), - @view.render(:layout => "layouts/partial_and_yield") { "Content from block!" } + @view.render(layout: "layouts/partial_and_yield") { "Content from block!" } end def test_render_partial_and_layout_without_block_with_locals assert_equal %(Before (Foo!)\npartial html\nAfter), - @view.render(:partial => "test/partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"}) + @view.render(partial: "test/partial", layout: "test/layout_for_partial", locals: { name: "Foo!"}) end def test_render_partial_and_layout_without_block_with_locals_and_rendering_another_partial assert_equal %(Before (Foo!)\npartial html\npartial with partial\n\nAfter), - @view.render(:partial => "test/partial_with_partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"}) + @view.render(partial: "test/partial_with_partial", layout: "test/layout_for_partial", locals: { name: "Foo!"}) end def test_render_partial_shortcut_with_block_content @@ -535,17 +535,17 @@ module RenderTestCases def test_render_layout_with_a_nested_render_layout_call assert_equal %(Before (Foo!)\nBefore (Bar!)\npartial html\nAfter\npartial with layout\n\nAfter), - @view.render(:partial => "test/partial_with_layout", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"}) + @view.render(partial: "test/partial_with_layout", layout: "test/layout_for_partial", locals: { name: "Foo!"}) end def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_partial assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n partial html\n\nAfterpartial with layout\n\nAfter), - @view.render(:partial => "test/partial_with_layout_block_partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"}) + @view.render(partial: "test/partial_with_layout_block_partial", layout: "test/layout_for_partial", locals: { name: "Foo!"}) end def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_content assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n Content from inside layout!\n\nAfterpartial with layout\n\nAfter), - @view.render(:partial => "test/partial_with_layout_block_content", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"}) + @view.render(partial: "test/partial_with_layout_block_content", layout: "test/layout_for_partial", locals: { name: "Foo!"}) end def test_render_partial_with_layout_raises_descriptive_error @@ -555,17 +555,17 @@ module RenderTestCases def test_render_with_nested_layout assert_equal %(title\n\n
column
\n
content
\n), - @view.render(:file => "test/nested_layout", :layout => "layouts/yield") + @view.render(file: "test/nested_layout", layout: "layouts/yield") end def test_render_with_file_in_layout assert_equal %(\ntitle\n\n), - @view.render(:file => "test/layout_render_file") + @view.render(file: "test/layout_render_file") end def test_render_layout_with_object assert_equal %(David), - @view.render(:file => "test/layout_render_object") + @view.render(file: "test/layout_render_object") end def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call @@ -615,7 +615,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_magic_comment with_external_encoding Encoding::ASCII_8BIT do - result = @view.render(:file => "test/utf8_magic", :formats => [:html], :layouts => "layouts/yield") + result = @view.render(file: "test/utf8_magic", formats: [:html], layouts: "layouts/yield") assert_equal Encoding::UTF_8, result.encoding assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result end @@ -623,7 +623,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_default_external_encoding with_external_encoding Encoding::UTF_8 do - result = @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") + result = @view.render(file: "test/utf8", formats: [:html], layouts: "layouts/yield") assert_equal Encoding::UTF_8, result.encoding assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result end @@ -631,14 +631,14 @@ class LazyViewRenderTest < ActiveSupport::TestCase def test_render_utf8_template_with_incompatible_external_encoding with_external_encoding Encoding::SHIFT_JIS do - e = assert_raises(ActionView::Template::Error) { @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") } + e = assert_raises(ActionView::Template::Error) { @view.render(file: "test/utf8", formats: [:html], layouts: "layouts/yield") } assert_match "Your template was not saved as valid Shift_JIS", e.cause.message end end def test_render_utf8_template_with_partial_with_incompatible_encoding with_external_encoding Encoding::SHIFT_JIS do - e = assert_raises(ActionView::Template::Error) { @view.render(:file => "test/utf8_magic_with_bare_partial", :formats => [:html], :layouts => "layouts/yield") } + e = assert_raises(ActionView::Template::Error) { @view.render(file: "test/utf8_magic_with_bare_partial", formats: [:html], layouts: "layouts/yield") } assert_match "Your template was not saved as valid Shift_JIS", e.cause.message end end diff --git a/actionview/test/template/streaming_render_test.rb b/actionview/test/template/streaming_render_test.rb index 894512ea31..6ce66a1275 100644 --- a/actionview/test/template/streaming_render_test.rb +++ b/actionview/test/template/streaming_render_test.rb @@ -6,7 +6,7 @@ end class FiberedTest < ActiveSupport::TestCase def setup view_paths = ActionController::Base.view_paths - @assigns = { :secret => "in the sauce", :name => nil } + @assigns = { secret: "in the sauce", name: nil } @view = ActionView::Base.new(view_paths, @assigns) @controller_view = TestController.new.view_context end @@ -26,7 +26,7 @@ class FiberedTest < ActiveSupport::TestCase def test_streaming_works content = [] - body = render_body(:template => "test/hello_world", :layout => "layouts/yield") + body = render_body(template: "test/hello_world", layout: "layouts/yield") body.each do |piece| content << piece @@ -40,68 +40,68 @@ class FiberedTest < ActiveSupport::TestCase end def test_render_file - assert_equal "Hello world!", buffered_render(:file => "test/hello_world") + assert_equal "Hello world!", buffered_render(file: "test/hello_world") end def test_render_file_with_locals - locals = { :secret => "in the sauce" } - assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals", :locals => locals) + locals = { secret: "in the sauce" } + assert_equal "The secret is in the sauce\n", buffered_render(file: "test/render_file_with_locals", locals: locals) end def test_render_partial - assert_equal "only partial", buffered_render(:partial => "test/partial_only") + assert_equal "only partial", buffered_render(partial: "test/partial_only") end def test_render_inline - assert_equal "Hello, World!", buffered_render(:inline => "Hello, World!") + assert_equal "Hello, World!", buffered_render(inline: "Hello, World!") end def test_render_without_layout - assert_equal "Hello world!", buffered_render(:template => "test/hello_world") + assert_equal "Hello world!", buffered_render(template: "test/hello_world") end def test_render_with_layout assert_equal %(\nHello world!\n), - buffered_render(:template => "test/hello_world", :layout => "layouts/yield") + buffered_render(template: "test/hello_world", layout: "layouts/yield") end def test_render_with_layout_which_has_render_inline assert_equal %(welcome\nHello world!\n), - buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside") + buffered_render(template: "test/hello_world", layout: "layouts/yield_with_render_inline_inside") end def test_render_with_layout_which_renders_another_partial assert_equal %(partial html\nHello world!\n), - buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside") + buffered_render(template: "test/hello_world", layout: "layouts/yield_with_render_partial_inside") end def test_render_with_nested_layout assert_equal %(title\n\n
column
\n
content
\n), - buffered_render(:template => "test/nested_layout", :layout => "layouts/yield") + buffered_render(template: "test/nested_layout", layout: "layouts/yield") end def test_render_with_file_in_layout assert_equal %(\ntitle\n\n), - buffered_render(:template => "test/layout_render_file") + buffered_render(template: "test/layout_render_file") end def test_render_with_handler_without_streaming_support - assert_match "

This is grand!

", buffered_render(:template => "test/hello") + assert_match "

This is grand!

", buffered_render(template: "test/hello") end def test_render_with_streaming_multiple_yields_provide_and_content_for assert_equal "Yes, \nthis works\n like a charm.", - buffered_render(:template => "test/streaming", :layout => "layouts/streaming") + buffered_render(template: "test/streaming", layout: "layouts/streaming") end def test_render_with_streaming_with_fake_yields_and_streaming_buster assert_equal "This won't look\n good.", - buffered_render(:template => "test/streaming_buster", :layout => "layouts/streaming") + buffered_render(template: "test/streaming_buster", layout: "layouts/streaming") end def test_render_with_nested_streaming_multiple_yields_provide_and_content_for assert_equal "?Yes, \n\nthis works\n\n? like a charm.", - buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming") + buffered_render(template: "test/nested_streaming", layout: "layouts/streaming") end def test_render_with_streaming_and_capture diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 0c8bfd03d7..5b67b657be 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -7,7 +7,7 @@ class TagHelperTest < ActionView::TestCase def test_tag assert_equal "
", tag("br") - assert_equal "
", tag(:br, :clear => "left") + assert_equal "
", tag(:br, clear: "left") assert_equal "
", tag("br", nil, true) end @@ -36,7 +36,7 @@ class TagHelperTest < ActionView::TestCase end def test_tag_options_rejects_nil_option - assert_equal "

", tag("p", :ignored => nil) + assert_equal "

", tag("p", ignored: nil) end def test_tag_builder_options_rejects_nil_option @@ -44,7 +44,7 @@ class TagHelperTest < ActionView::TestCase end def test_tag_options_accepts_false_option - assert_equal "

", tag("p", :value => false) + assert_equal "

", tag("p", value: false) end def test_tag_builder_options_accepts_false_option @@ -52,7 +52,7 @@ class TagHelperTest < ActionView::TestCase end def test_tag_options_accepts_blank_option - assert_equal "

", tag("p", :included => "") + assert_equal "

", tag("p", included: "") end def test_tag_builder_options_accepts_blank_option @@ -61,7 +61,7 @@ class TagHelperTest < ActionView::TestCase def test_tag_options_converts_boolean_option assert_dom_equal '

', - tag("p", :disabled => true, :itemscope => true, :multiple => true, :readonly => true, :allowfullscreen => true, :seamless => true, :typemustmatch => true, :sortable => true, :default => true, :inert => true, :truespeed => true) + tag("p", disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true) end def test_tag_builder_options_converts_boolean_option @@ -73,7 +73,7 @@ class TagHelperTest < ActionView::TestCase assert_equal "Create", content_tag("a", "Create", "href" => "create") assert content_tag("a", "Create", "href" => "create").html_safe? assert_equal content_tag("a", "Create", "href" => "create"), - content_tag("a", "Create", :href => "create") + content_tag("a", "Create", href: "create") assert_equal "

<script>evil_js</script>

", content_tag(:p, "") assert_equal "

", @@ -131,7 +131,7 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_block_and_options_out_of_erb - assert_dom_equal %(
Hello world!
), content_tag(:div, :class => "green") { "Hello world!" } + assert_dom_equal %(
Hello world!
), content_tag(:div, class: "green") { "Hello world!" } end def test_tag_builder_with_block_and_options_out_of_erb @@ -139,7 +139,7 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_block_and_options_outside_out_of_erb - assert_equal content_tag("a", "Create", :href => "create"), + assert_equal content_tag("a", "Create", href: "create"), content_tag("a", "href" => "create") { "Create" } end @@ -173,13 +173,13 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_escaped_array_class - str = content_tag("p", "limelight", :class => ["song", "play>"]) + str = content_tag("p", "limelight", class: ["song", "play>"]) assert_equal "

limelight

", str - str = content_tag("p", "limelight", :class => ["song", "play"]) + str = content_tag("p", "limelight", class: ["song", "play"]) assert_equal "

limelight

", str - str = content_tag("p", "limelight", :class => ["song", ["play"]]) + str = content_tag("p", "limelight", class: ["song", ["play"]]) assert_equal "

limelight

", str end @@ -195,10 +195,10 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_unescaped_array_class - str = content_tag("p", "limelight", {:class => ["song", "play>"]}, false) + str = content_tag("p", "limelight", {class: ["song", "play>"]}, false) assert_equal "

\">limelight

", str - str = content_tag("p", "limelight", {:class => ["song", ["play>"]]}, false) + str = content_tag("p", "limelight", {class: ["song", ["play>"]]}, false) assert_equal "

\">limelight

", str end @@ -211,7 +211,7 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_empty_array_class - str = content_tag("p", "limelight", {:class => []}) + str = content_tag("p", "limelight", {class: []}) assert_equal '

limelight

', str end @@ -220,7 +220,7 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_unescaped_empty_array_class - str = content_tag("p", "limelight", {:class => []}, false) + str = content_tag("p", "limelight", {class: []}, false) assert_equal '

limelight

', str end @@ -259,14 +259,14 @@ class TagHelperTest < ActionView::TestCase def test_tag_honors_html_safe_for_param_values ["1&2", "1 < 2", "“test“"].each do |escaped| - assert_equal %(), tag("a", :href => escaped.html_safe) + assert_equal %(), tag("a", href: escaped.html_safe) assert_equal %(), tag.a(href: escaped.html_safe) end end def test_tag_honors_html_safe_with_escaped_array_class - assert_equal '

', tag("p", :class => ["song>", raw("play>")]) - assert_equal '

', tag("p", :class => [raw("song>"), "play>"]) + assert_equal '

', tag("p", class: ["song>", raw("play>")]) + assert_equal '

', tag("p", class: [raw("song>"), "play>"]) end def test_tag_builder_honors_html_safe_with_escaped_array_class @@ -276,13 +276,13 @@ class TagHelperTest < ActionView::TestCase def test_skip_invalid_escaped_attributes ["&1;", "dfa3;", "& #123;"].each do |escaped| - assert_equal %(), tag("a", :href => escaped) + assert_equal %(), tag("a", href: escaped) assert_equal %(), tag.a(href: escaped) end end def test_disable_escaping - assert_equal '', tag("a", { :href => "&" }, false, false) + assert_equal '', tag("a", { href: "&" }, false, false) end def test_tag_builder_disable_escaping diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index 02167caa71..cd7221ca0e 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -55,12 +55,12 @@ module ActionView end test "works without testing a helper module" do - assert_equal "Eloy", render("developers/developer", :developer => DeveloperStruct.new("Eloy")) + assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy")) end test "can render a layout with block" do assert_equal "Before (ChrisCruft)\n!\nAfter", - render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"} + render(layout: "test/layout_for_partial", locals: {name: "ChrisCruft"}) {"!"} end helper AnotherTestHelper @@ -110,14 +110,14 @@ module ActionView from_another_helper end end - assert_equal "Howdy!", render(:partial => "test/from_helper") + assert_equal "Howdy!", render(partial: "test/from_helper") end end class HelperInclusionTest < ActionView::TestCase module RenderHelper def render_from_helper - render :partial => "customer", :collection => @customers + render partial: "customer", collection: @customers end end @@ -127,14 +127,14 @@ module ActionView @controller.controller_path = "test" @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] - assert_match(/Hello: EloyHello: Manfred/, render(:partial => "test/from_helper")) + assert_match(/Hello: EloyHello: Manfred/, render(partial: "test/from_helper")) end end class ControllerHelperMethod < ActionView::TestCase module SomeHelper def some_method - render :partial => "test/from_helper" + render partial: "test/from_helper" end end @@ -156,7 +156,7 @@ module ActionView test "view_assigns returns a Hash of user defined ivars" do @a = "b" @c = "d" - assert_equal({:a => "b", :c => "d"}, view_assigns) + assert_equal({a: "b", c: "d"}, view_assigns) end test "view_assigns excludes internal ivars" do @@ -174,7 +174,7 @@ module ActionView end end) test "is able to make methods available to the view" do - assert_equal "Word!", render(:partial => "test/from_helper") + assert_equal "Word!", render(partial: "test/from_helper") end def from_test_case; "Word!"; end @@ -218,14 +218,14 @@ module ActionView test "is able to use routes" do controller.request.assign_parameters(@routes, "foo", "index", {}, "/foo", []) assert_equal "/foo", url_for - assert_equal "/bar", url_for(:controller => "bar") + assert_equal "/bar", url_for(controller: "bar") end test "is able to use named routes" do with_routing do |set| set.draw { resources :contents } assert_equal "http://test.host/contents/new", new_content_url - assert_equal "http://test.host/contents/1", content_url(:id => 1) + assert_equal "http://test.host/contents/1", content_url(id: 1) end end @@ -236,7 +236,7 @@ module ActionView @routes ||= ActionDispatch::Routing::RouteSet.new end - routes.draw { get "bar", :to => lambda {} } + routes.draw { get "bar", to: lambda {} } def self.call(*) end @@ -257,21 +257,21 @@ module ActionView end end - assert_equal "http://test.host/contents/new", render(:partial => "test/from_helper") + assert_equal "http://test.host/contents/new", render(partial: "test/from_helper") end end test "is able to render partials with local variables" do - assert_equal "Eloy", render("developers/developer", :developer => DeveloperStruct.new("Eloy")) - assert_equal "Eloy", render(:partial => "developers/developer", - :locals => { :developer => DeveloperStruct.new("Eloy") }) + assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy")) + assert_equal "Eloy", render(partial: "developers/developer", + locals: { developer: DeveloperStruct.new("Eloy") }) end test "is able to render partials from templates and also use instance variables" do @controller.controller_path = "test" @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] - assert_match(/Hello: EloyHello: Manfred/, render(:file => "test/list")) + assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list")) end test "is able to render partials from templates and also use instance variables after view has been referenced" do @@ -280,7 +280,7 @@ module ActionView view @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] - assert_match(/Hello: EloyHello: Manfred/, render(:file => "test/list")) + assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list")) end end @@ -288,16 +288,16 @@ module ActionView class AssertionsTest < ActionView::TestCase def render_from_helper form_tag("/foo") do - safe_concat render(:text => "

") + safe_concat render(text: "") end end helper_method :render_from_helper test "uses the output_buffer for assert_select" do - render(:partial => "test/from_helper") + render(partial: "test/from_helper") assert_select "form" do - assert_select "li", :text => "foo" + assert_select "li", text: "foo" end end diff --git a/actionview/test/template/test_test.rb b/actionview/test/template/test_test.rb index 47d57c0c04..52cac77bc5 100644 --- a/actionview/test/template/test_test.rb +++ b/actionview/test/template/test_test.rb @@ -60,7 +60,7 @@ class PeopleHelperTest < ActionView::TestCase def with_test_route_set with_routing do |set| set.draw do - get "people", :to => "people#index", :as => :people + get "people", to: "people#index", as: :people end yield end diff --git a/actionview/test/template/testing/fixture_resolver_test.rb b/actionview/test/template/testing/fixture_resolver_test.rb index aae56ff472..4ae4324860 100644 --- a/actionview/test/template/testing/fixture_resolver_test.rb +++ b/actionview/test/template/testing/fixture_resolver_test.rb @@ -3,13 +3,13 @@ require "abstract_unit" class FixtureResolverTest < ActiveSupport::TestCase def test_should_return_empty_list_for_unknown_path resolver = ActionView::FixtureResolver.new() - templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :variants => [], :handlers => []}) + templates = resolver.find_all("path", "arbitrary", false, {locale: [], formats: [:html], variants: [], handlers: []}) assert_equal [], templates, "expected an empty list of templates" end def test_should_return_template_for_declared_path resolver = ActionView::FixtureResolver.new("arbitrary/path.erb" => "this text") - templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :variants => [], :handlers => [:erb]}) + templates = resolver.find_all("path", "arbitrary", false, {locale: [], formats: [:html], variants: [], handlers: [:erb]}) assert_equal 1, templates.size, "expected one template" assert_equal "this text", templates.first.source assert_equal "arbitrary/path", templates.first.virtual_path diff --git a/actionview/test/template/testing/null_resolver_test.rb b/actionview/test/template/testing/null_resolver_test.rb index c0e02bd9b7..907431389c 100644 --- a/actionview/test/template/testing/null_resolver_test.rb +++ b/actionview/test/template/testing/null_resolver_test.rb @@ -3,7 +3,7 @@ require "abstract_unit" class NullResolverTest < ActiveSupport::TestCase def test_should_return_template_for_any_path resolver = ActionView::NullResolver.new() - templates = resolver.find_all("path.erb", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []}) + templates = resolver.find_all("path.erb", "arbitrary", false, {locale: [], formats: [:html], handlers: []}) assert_equal 1, templates.size, "expected one template" assert_equal "Template generated by Null Resolver", templates.first.source assert_equal "arbitrary/path.erb", templates.first.virtual_path.to_s diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 8c866040d9..0317c433d1 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -38,8 +38,8 @@ class TextHelperTest < ActionView::TestCase text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze assert_equal "

A\n
\n
B

\n\n

\t\n
C\n
D

", simple_format(text) - assert_equal %q(

This is a classy test

), simple_format("This is a classy test", :class => "test") - assert_equal %Q(

para 1

\n\n

para 2

), simple_format("para 1\n\npara 2", :class => "test") + assert_equal %q(

This is a classy test

), simple_format("This is a classy test", class: "test") + assert_equal %Q(

para 1

\n\n

para 2

), simple_format("para 1\n\npara 2", class: "test") end def test_simple_format_should_sanitize_input_when_sanitize_option_is_not_false @@ -52,15 +52,15 @@ class TextHelperTest < ActionView::TestCase end def test_simple_format_should_not_sanitize_input_when_sanitize_option_is_false - assert_equal "

test with unsafe string

", simple_format(" test with unsafe string ", {}, :sanitize => false) + assert_equal "

test with unsafe string

", simple_format(" test with unsafe string ", {}, sanitize: false) end def test_simple_format_with_custom_wrapper - assert_equal "
", simple_format(nil, {}, :wrapper_tag => "div") + assert_equal "
", simple_format(nil, {}, wrapper_tag: "div") end def test_simple_format_with_custom_wrapper_and_multi_line_breaks - assert_equal "
We want to put a wrapper...
\n\n
...right there.
", simple_format("We want to put a wrapper...\n\n...right there.", {}, :wrapper_tag => "div") + assert_equal "
We want to put a wrapper...
\n\n
...right there.
", simple_format("We want to put a wrapper...\n\n...right there.", {}, wrapper_tag: "div") end def test_simple_format_should_not_change_the_text_passed @@ -71,22 +71,22 @@ class TextHelperTest < ActionView::TestCase end def test_simple_format_does_not_modify_the_html_options_hash - options = { :class => "foobar"} + options = { class: "foobar"} passed_options = options.dup simple_format("some text", passed_options) assert_equal options, passed_options end def test_simple_format_does_not_modify_the_options_hash - options = { :wrapper_tag => :div, :sanitize => false } + options = { wrapper_tag: :div, sanitize: false } passed_options = options.dup simple_format("some text", {}, passed_options) assert_equal options, passed_options end def test_truncate - assert_equal "Hello World!", truncate("Hello World!", :length => 12) - assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12) + assert_equal "Hello World!", truncate("Hello World!", length: 12) + assert_equal "Hello Wor...", truncate("Hello World!!", length: 12) end def test_truncate_should_use_default_length_of_30 @@ -95,21 +95,21 @@ class TextHelperTest < ActionView::TestCase end def test_truncate_with_options_hash - assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]") - assert_equal "Hello W...", truncate("Hello World!", :length => 10) - assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10) - assert_equal "Hello[...]", truncate("Hello Big World!", :omission => "[...]", :length => 13, :separator => " ") - assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 14, :separator => " ") - assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 15, :separator => " ") + assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", omission: "[...]") + assert_equal "Hello W...", truncate("Hello World!", length: 10) + assert_equal "Hello[...]", truncate("Hello World!", omission: "[...]", length: 10) + assert_equal "Hello[...]", truncate("Hello Big World!", omission: "[...]", length: 13, separator: " ") + assert_equal "Hello Big[...]", truncate("Hello Big World!", omission: "[...]", length: 14, separator: " ") + assert_equal "Hello Big[...]", truncate("Hello Big World!", omission: "[...]", length: 15, separator: " ") end def test_truncate_multibyte assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8), - truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8), :length => 10) + truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8), length: 10) end def test_truncate_does_not_modify_the_options_hash - options = { :length => 10 } + options = { length: 10 } passed_options = options.dup truncate("some text", passed_options) assert_equal options, passed_options @@ -117,49 +117,49 @@ class TextHelperTest < ActionView::TestCase def test_truncate_with_link_options assert_equal "Here is a long test and ...
Continue", - truncate("Here is a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" } + truncate("Here is a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" } end def test_truncate_should_be_html_safe - assert truncate("Hello World!", :length => 12).html_safe? + assert truncate("Hello World!", length: 12).html_safe? end def test_truncate_should_escape_the_input - assert_equal "Hello <sc...", truncate("Hello World!!", :length => 12) + assert_equal "Hello <sc...", truncate("Hello World!!", length: 12) end def test_truncate_should_not_escape_the_input_with_escape_false - assert_equal "Hello code!World!!", :length => 12, :escape => false) + assert_equal "Hello code!World!!", length: 12, escape: false) end def test_truncate_with_escape_false_should_be_html_safe - truncated = truncate("Hello World!!", :length => 12, :escape => false) + truncated = truncate("Hello World!!", length: 12, escape: false) assert truncated.html_safe? end def test_truncate_with_block_should_be_html_safe - truncated = truncate("Here's a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" } + truncated = truncate("Here's a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" } assert truncated.html_safe? end def test_truncate_with_block_should_escape_the_input assert_equal "<script>code!</script>He...Continue", - truncate("Here's a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" } + truncate("Here's a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" } end def test_truncate_with_block_should_not_escape_the_input_with_escape_false assert_equal "He...Continue", - truncate("Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to "Continue", "#" } + truncate("Here's a long test and I need a continue to read link", length: 27, escape: false) { link_to "Continue", "#" } end def test_truncate_with_block_with_escape_false_should_be_html_safe - truncated = truncate("Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to "Continue", "#" } + truncated = truncate("Here's a long test and I need a continue to read link", length: 27, escape: false) { link_to "Continue", "#" } assert truncated.html_safe? end def test_truncate_with_block_should_escape_the_block assert_equal "Here is a long test and ...<script>alert('foo');</script>", - truncate("Here is a long test and I need a continue to read link", :length => 27) { "" } + truncate("Here is a long test and I need a continue to read link", length: 27) { "" } end def test_highlight_should_be_html_safe @@ -179,7 +179,7 @@ class TextHelperTest < ActionView::TestCase assert_equal( "This is a beautiful morning, but also a beautiful day", - highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '\1') + highlight("This is a beautiful morning, but also a beautiful day", "beautiful", highlighter: '\1') ) assert_equal( @@ -206,7 +206,7 @@ class TextHelperTest < ActionView::TestCase def test_highlight_should_not_sanitize_if_sanitize_option_if_false assert_equal( "This is a beautiful morning", - highlight("This is a beautiful morning", "beautiful", :sanitize => false) + highlight("This is a beautiful morning", "beautiful", sanitize: false) ) end @@ -233,7 +233,7 @@ class TextHelperTest < ActionView::TestCase end def test_highlight_with_multiple_phrases_in_one_pass - assert_equal %(wow em), highlight("wow em", %w(wow em), :highlighter => '\1') + assert_equal %(wow em), highlight("wow em", %w(wow em), highlighter: '\1') end def test_highlight_with_html @@ -259,12 +259,12 @@ class TextHelperTest < ActionView::TestCase ) assert_equal( "
abc div
", - highlight("
abc div
", "div", :highlighter => '\1') + highlight("
abc div
", "div", highlighter: '\1') ) end def test_highlight_does_not_modify_the_options_hash - options = { :highlighter => '\1', :sanitize => false } + options = { highlighter: '\1', sanitize: false } passed_options = options.dup highlight("
abc div
", "div", passed_options) assert_equal options, passed_options @@ -278,73 +278,73 @@ class TextHelperTest < ActionView::TestCase end def test_excerpt - assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5)) - assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5)) - assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", :radius => 5)) + assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", radius: 5)) + assert_equal("This is a...", excerpt("This is a beautiful morning", "this", radius: 5)) + assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", radius: 5)) assert_nil excerpt("This is a beautiful morning", "day") end def test_excerpt_with_regex - assert_equal("...is a beautiful! mor...", excerpt("This is a beautiful! morning", "beautiful", :radius => 5)) - assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", "beautiful", :radius => 5)) - assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\bbeau\w*\b/i, :radius => 5)) - assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\b(beau\w*)\b/i, :radius => 5)) - assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 5)) - assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 1, :separator => " ")) - assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, :radius => 5)) + assert_equal("...is a beautiful! mor...", excerpt("This is a beautiful! morning", "beautiful", radius: 5)) + assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", "beautiful", radius: 5)) + assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\bbeau\w*\b/i, radius: 5)) + assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\b(beau\w*)\b/i, radius: 5)) + assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, radius: 5)) + assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, radius: 1, separator: " ")) + assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, radius: 5)) end def test_excerpt_should_not_be_html_safe - assert !excerpt("This is a beautiful! morning", "beautiful", :radius => 5).html_safe? + assert !excerpt("This is a beautiful! morning", "beautiful", radius: 5).html_safe? end def test_excerpt_in_borderline_cases - assert_equal("", excerpt("", "", :radius => 0)) - assert_equal("a", excerpt("a", "a", :radius => 0)) - assert_equal("...b...", excerpt("abc", "b", :radius => 0)) - assert_equal("abc", excerpt("abc", "b", :radius => 1)) - assert_equal("abc...", excerpt("abcd", "b", :radius => 1)) - assert_equal("...abc", excerpt("zabc", "b", :radius => 1)) - assert_equal("...abc...", excerpt("zabcd", "b", :radius => 1)) - assert_equal("zabcd", excerpt("zabcd", "b", :radius => 2)) + assert_equal("", excerpt("", "", radius: 0)) + assert_equal("a", excerpt("a", "a", radius: 0)) + assert_equal("...b...", excerpt("abc", "b", radius: 0)) + assert_equal("abc", excerpt("abc", "b", radius: 1)) + assert_equal("abc...", excerpt("abcd", "b", radius: 1)) + assert_equal("...abc", excerpt("zabc", "b", radius: 1)) + assert_equal("...abc...", excerpt("zabcd", "b", radius: 1)) + assert_equal("zabcd", excerpt("zabcd", "b", radius: 2)) # excerpt strips the resulting string before ap-/prepending excerpt_string. # whether this behavior is meaningful when excerpt_string is not to be # appended is questionable. - assert_equal("zabcd", excerpt(" zabcd ", "b", :radius => 4)) - assert_equal("...abc...", excerpt("z abc d", "b", :radius => 1)) + assert_equal("zabcd", excerpt(" zabcd ", "b", radius: 4)) + assert_equal("...abc...", excerpt("z abc d", "b", radius: 1)) end def test_excerpt_with_omission - assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5)) + assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", omission: "[...]",radius: 5)) assert_equal( "This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]", excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very", - :omission => "[...]") + omission: "[...]") ) end def test_excerpt_with_utf8 - assert_equal("...\357\254\203ciency could not be...".force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding(Encoding::UTF_8), "could", :radius => 8)) + assert_equal("...\357\254\203ciency could not be...".force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding(Encoding::UTF_8), "could", radius: 8)) end def test_excerpt_does_not_modify_the_options_hash - options = { :omission => "[...]",:radius => 5 } + options = { omission: "[...]",radius: 5 } passed_options = options.dup excerpt("This is a beautiful morning", "beautiful", passed_options) assert_equal options, passed_options end def test_excerpt_with_separator - options = { :separator => " ", :radius => 1 } + options = { separator: " ", radius: 1 } assert_equal("...a very beautiful...", excerpt("This is a very beautiful morning", "very", options)) assert_equal("This is...", excerpt("This is a very beautiful morning", "this", options)) assert_equal("...beautiful morning", excerpt("This is a very beautiful morning", "morning", options)) - options = { :separator => "\n", :radius => 0 } + options = { separator: "\n", radius: 0 } assert_equal("...very long...", excerpt("my very\nvery\nvery long\nstring", "long", options)) - options = { :separator => "\n", :radius => 1 } + options = { separator: "\n", radius: 1 } assert_equal("...very\nvery long\nstring", excerpt("my very\nvery\nvery long\nstring", "long", options)) assert_equal excerpt("This is a beautiful morning", "a"), @@ -352,15 +352,15 @@ class TextHelperTest < ActionView::TestCase end def test_word_wrap - assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15)) + assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", line_width: 15)) end def test_word_wrap_with_extra_newlines - assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", :line_width => 15)) + assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", line_width: 15)) end def test_word_wrap_does_not_modify_the_options_hash - options = { :line_width => 15 } + options = { line_width: 15 } passed_options = options.dup word_wrap("some text", passed_options) assert_equal options, passed_options @@ -458,12 +458,12 @@ class TextHelperTest < ActionView::TestCase end def test_named_cycles - assert_equal("1", cycle(1, 2, 3, :name => "numbers")) - assert_equal("red", cycle("red", "blue", :name => "colors")) - assert_equal("2", cycle(1, 2, 3, :name => "numbers")) - assert_equal("blue", cycle("red", "blue", :name => "colors")) - assert_equal("3", cycle(1, 2, 3, :name => "numbers")) - assert_equal("red", cycle("red", "blue", :name => "colors")) + assert_equal("1", cycle(1, 2, 3, name: "numbers")) + assert_equal("red", cycle("red", "blue", name: "colors")) + assert_equal("2", cycle(1, 2, 3, name: "numbers")) + assert_equal("blue", cycle("red", "blue", name: "colors")) + assert_equal("3", cycle(1, 2, 3, name: "numbers")) + assert_equal("red", cycle("red", "blue", name: "colors")) end def test_current_cycle_with_default_name @@ -476,11 +476,11 @@ class TextHelperTest < ActionView::TestCase end def test_current_cycle_with_named_cycles - cycle("red", "blue", :name => "colors") + cycle("red", "blue", name: "colors") assert_equal "red", current_cycle("colors") - cycle("red", "blue", :name => "colors") + cycle("red", "blue", name: "colors") assert_equal "blue", current_cycle("colors") - cycle("red", "blue", :name => "colors") + cycle("red", "blue", name: "colors") assert_equal "red", current_cycle("colors") end @@ -502,7 +502,7 @@ class TextHelperTest < ActionView::TestCase def test_default_named_cycle assert_equal("1", cycle(1, 2, 3)) - assert_equal("2", cycle(1, 2, 3, :name => "default")) + assert_equal("2", cycle(1, 2, 3, name: "default")) assert_equal("3", cycle(1, 2, 3)) end @@ -518,13 +518,13 @@ class TextHelperTest < ActionView::TestCase end def test_reset_named_cycle - assert_equal("1", cycle(1, 2, 3, :name => "numbers")) - assert_equal("red", cycle("red", "blue", :name => "colors")) + assert_equal("1", cycle(1, 2, 3, name: "numbers")) + assert_equal("red", cycle("red", "blue", name: "colors")) reset_cycle("numbers") - assert_equal("1", cycle(1, 2, 3, :name => "numbers")) - assert_equal("blue", cycle("red", "blue", :name => "colors")) - assert_equal("2", cycle(1, 2, 3, :name => "numbers")) - assert_equal("red", cycle("red", "blue", :name => "colors")) + assert_equal("1", cycle(1, 2, 3, name: "numbers")) + assert_equal("blue", cycle("red", "blue", name: "colors")) + assert_equal("2", cycle(1, 2, 3, name: "numbers")) + assert_equal("red", cycle("red", "blue", name: "colors")) end def test_cycle_no_instance_variable_clashes diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 909eb1e50a..1cfc13f337 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -15,22 +15,22 @@ class TranslationHelperTest < ActiveSupport::TestCase setup do I18n.backend.store_translations(:en, - :translations => { - :templates => { - :found => { :foo => "Foo" }, - :array => { :foo => { :bar => "Foo Bar" } }, - :default => { :foo => "Foo" } + translations: { + templates: { + found: { foo: "Foo" }, + array: { foo: { bar: "Foo Bar" } }, + default: { foo: "Foo" } }, - :foo => "Foo", - :hello => "Hello World", - :html => "Hello World", - :hello_html => "Hello World", - :interpolated_html => "Hello %{word}", - :array_html => %w(foo bar), - :array => %w(foo bar), - :count_html => { - :one => "One %{count}", - :other => "Other %{count}" + foo: "Foo", + hello: "Hello World", + html: "Hello World", + hello_html: "Hello World", + interpolated_html: "Hello %{word}", + array_html: %w(foo bar), + array: %w(foo bar), + count_html: { + one: "One %{count}", + other: "Other %{count}" } } ) @@ -42,8 +42,8 @@ class TranslationHelperTest < ActiveSupport::TestCase end def test_delegates_setting_to_i18n - assert_called_with(I18n, :translate, [:foo, :locale => "en", :raise => true], returns: "") do - translate :foo, :locale => "en" + assert_called_with(I18n, :translate, [:foo, locale: "en", raise: true], returns: "") do + translate :foo, locale: "en" end end @@ -96,7 +96,7 @@ class TranslationHelperTest < ActiveSupport::TestCase def test_raises_missing_translation_message_with_raise_option assert_raise(I18n::MissingTranslationData) do - translate(:"translations.missing", :raise => true) + translate(:"translations.missing", raise: true) end end @@ -122,20 +122,20 @@ class TranslationHelperTest < ActiveSupport::TestCase end def test_finds_translation_scoped_by_partial - assert_equal "Foo", view.render(:file => "translations/templates/found").strip + assert_equal "Foo", view.render(file: "translations/templates/found").strip end def test_finds_array_of_translations_scoped_by_partial - assert_equal "Foo Bar", @view.render(:file => "translations/templates/array").strip + assert_equal "Foo Bar", @view.render(file: "translations/templates/array").strip end def test_default_lookup_scoped_by_partial - assert_equal "Foo", view.render(:file => "translations/templates/default").strip + assert_equal "Foo", view.render(file: "translations/templates/default").strip end def test_missing_translation_scoped_by_partial expected = 'Missing' - assert_equal expected, view.render(:file => "translations/templates/missing").strip + assert_equal expected, view.render(file: "translations/templates/missing").strip end def test_translate_does_not_mark_plain_text_as_safe_html @@ -152,14 +152,14 @@ class TranslationHelperTest < ActiveSupport::TestCase def test_translate_escapes_interpolations_in_translations_with_a_html_suffix word_struct = Struct.new(:to_s) - assert_equal "Hello <World>", translate(:'translations.interpolated_html', :word => "") - assert_equal "Hello <World>", translate(:'translations.interpolated_html', :word => word_struct.new("")) + assert_equal "Hello <World>", translate(:'translations.interpolated_html', word: "") + assert_equal "Hello <World>", translate(:'translations.interpolated_html', word: word_struct.new("")) end def test_translate_with_html_count - assert_equal "One 1", translate(:'translations.count_html', :count => 1) - assert_equal "Other 2", translate(:'translations.count_html', :count => 2) - assert_equal "Other <One>", translate(:'translations.count_html', :count => "") + assert_equal "One 1", translate(:'translations.count_html', count: 1) + assert_equal "Other 2", translate(:'translations.count_html', count: 2) + assert_equal "Other <One>", translate(:'translations.count_html', count: "") end def test_translation_returning_an_array_ignores_html_suffix @@ -167,13 +167,13 @@ class TranslationHelperTest < ActiveSupport::TestCase end def test_translate_with_default_named_html - translation = translate(:'translations.missing', :default => :'translations.hello_html') + translation = translate(:'translations.missing', default: :'translations.hello_html') assert_equal "Hello World", translation assert_equal true, translation.html_safe? end def test_translate_with_missing_default - translation = translate(:'translations.missing', :default => :'translations.missing_html') + translation = translate(:'translations.missing', default: :'translations.missing_html') expected = 'Missing Html' assert_equal expected, translation assert_equal true, translation.html_safe? @@ -181,24 +181,24 @@ class TranslationHelperTest < ActiveSupport::TestCase def test_translate_with_missing_default_and_raise_option assert_raise(I18n::MissingTranslationData) do - translate(:'translations.missing', :default => :'translations.missing_html', :raise => true) + translate(:'translations.missing', default: :'translations.missing_html', raise: true) end end def test_translate_with_two_defaults_named_html - translation = translate(:'translations.missing', :default => [:'translations.missing_html', :'translations.hello_html']) + translation = translate(:'translations.missing', default: [:'translations.missing_html', :'translations.hello_html']) assert_equal "Hello World", translation assert_equal true, translation.html_safe? end def test_translate_with_last_default_named_html - translation = translate(:'translations.missing', :default => [:'translations.missing', :'translations.hello_html']) + translation = translate(:'translations.missing', default: [:'translations.missing', :'translations.hello_html']) assert_equal "Hello World", translation assert_equal true, translation.html_safe? end def test_translate_with_last_default_not_named_html - translation = translate(:'translations.missing', :default => [:'translations.missing_html', :'translations.foo']) + translation = translate(:'translations.missing', default: [:'translations.missing_html', :'translations.foo']) assert_equal "Foo", translation assert_equal false, translation.html_safe? end diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 66259ac01f..4fd3e0369c 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -452,7 +452,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_current_page_with_http_head_method - @request = request_for_url("/", :method => :head) + @request = request_for_url("/", method: :head) assert current_page?(url_hash) assert current_page?("http://www.example.com/") end @@ -492,7 +492,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_current_page_with_escaped_params_with_different_encoding @request = request_for_url("/") @request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do - assert current_page?(:controller => "foo", :action => "category", category: "administração") + assert current_page?(controller: "foo", action: "category", category: "administração") assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o") end end -- cgit v1.2.3