diff options
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionview/test/actionpack/controller/layout_test.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/dependency_tracker_test.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/form_collections_helper_test.rb | 24 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 24 | ||||
-rw-r--r-- | actionview/test/ujs/server.rb | 1 |
6 files changed, 47 insertions, 12 deletions
diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index 56d617309c..acc2ed029b 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -58,7 +58,7 @@ module RenderERBUtils template = ActionView::Template.new( string.strip, "test template", - ActionView::Template::Handlers::ERB, + ActionView::Template.handler_for_extension(:erb), {}) template.render(ActionView::Base.empty, {}).strip diff --git a/actionview/test/actionpack/controller/layout_test.rb b/actionview/test/actionpack/controller/layout_test.rb index 6d5c97b7fd..838b564c5d 100644 --- a/actionview/test/actionpack/controller/layout_test.rb +++ b/actionview/test/actionpack/controller/layout_test.rb @@ -70,7 +70,7 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase end def test_third_party_template_library_auto_discovers_layout - with_template_handler :mab, lambda { |template| template.source.inspect } do + with_template_handler :mab, lambda { |template, source| source.inspect } do @controller = ThirdPartyTemplateLibraryController.new get :hello assert_response :success @@ -212,7 +212,7 @@ class LayoutSetInResponseTest < ActionController::TestCase end def test_layout_set_when_using_render - with_template_handler :mab, lambda { |template| template.source.inspect } do + with_template_handler :mab, lambda { |template, source| source.inspect } do @controller = SetsLayoutInRenderController.new get :hello assert_includes @response.body, "layouts/third_party_template_library.mab" diff --git a/actionview/test/template/dependency_tracker_test.rb b/actionview/test/template/dependency_tracker_test.rb index ef7aeac039..42cb14a18a 100644 --- a/actionview/test/template/dependency_tracker_test.rb +++ b/actionview/test/template/dependency_tracker_test.rb @@ -17,8 +17,8 @@ class FakeTemplate end end -Neckbeard = lambda { |template| template.source } -Bowtie = lambda { |template| template.source } +Neckbeard = lambda { |template, source| source } +Bowtie = lambda { |template, source| source } class DependencyTrackerTest < ActionView::TestCase def tracker diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index 6db55a1447..ca117d4a30 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -48,8 +48,16 @@ class FormCollectionsHelperTest < ActionView::TestCase test "collection radio should sanitize collection values for labels correctly" do with_collection_radio_buttons :user, :name, ["$0.99", "$1.99"], :to_s, :to_s - assert_select "label[for=user_name_099]", "$0.99" - assert_select "label[for=user_name_199]", "$1.99" + assert_select "label[for=user_name_0_99]", "$0.99" + assert_select "label[for=user_name_1_99]", "$1.99" + end + + test "collection radio correctly builds unique DOM IDs for float values" do + with_collection_radio_buttons :user, :name, [1.0, 10], :to_s, :to_s + assert_select "label[for=user_name_1_0]", "1.0" + assert_select "label[for=user_name_10]", "10" + assert_select 'input#user_name_1_0[type=radio][value="1.0"]' + assert_select 'input#user_name_10[type=radio][value="10"]' end test "collection radio accepts checked item" do @@ -302,8 +310,16 @@ class FormCollectionsHelperTest < ActionView::TestCase test "collection check box should sanitize collection values for labels correctly" do with_collection_check_boxes :user, :name, ["$0.99", "$1.99"], :to_s, :to_s - assert_select "label[for=user_name_099]", "$0.99" - assert_select "label[for=user_name_199]", "$1.99" + assert_select "label[for=user_name_0_99]", "$0.99" + assert_select "label[for=user_name_1_99]", "$1.99" + end + + test "collection check boxes correctly builds unique DOM IDs for float values" do + with_collection_check_boxes :user, :name, [1.0, 10], :to_s, :to_s + assert_select "label[for=user_name_1_0]", "1.0" + assert_select "label[for=user_name_10]", "10" + assert_select 'input#user_name_1_0[type=checkbox][value="1.0"]' + assert_select 'input#user_name_10[type=checkbox][value="10"]' end test "collection check boxes generates labels for non-English values correctly" do diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 76ffe3415d..f89d087c34 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -450,13 +450,31 @@ module RenderTestCases assert_equal "Hello, World!", @view.render(inline: "Hello, World!", type: :bar) end - CustomHandler = lambda do |template| + CustomHandler = lambda do |template, source| "@output_buffer = ''.dup\n" \ - "@output_buffer << 'source: #{template.source.inspect}'\n" + "@output_buffer << 'source: #{source.inspect}'\n" end def test_render_inline_with_render_from_to_proc - ActionView::Template.register_template_handler :ruby_handler, :source.to_proc + ActionView::Template.register_template_handler :ruby_handler, lambda { |_, source| source } + assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler) + ensure + ActionView::Template.unregister_template_handler :ruby_handler + end + + def test_render_inline_with_render_from_to_proc_deprecated + assert_deprecated do + ActionView::Template.register_template_handler :ruby_handler, :source.to_proc + end + assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler) + ensure + ActionView::Template.unregister_template_handler :ruby_handler + end + + def test_optional_second_arg_works_without_deprecation + assert_not_deprecated do + ActionView::Template.register_template_handler :ruby_handler, ->(view, source = nil) { source } + end assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler) ensure ActionView::Template.unregister_template_handler :ruby_handler diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb index 56f436c8b8..d7a6271587 100644 --- a/actionview/test/ujs/server.rb +++ b/actionview/test/ujs/server.rb @@ -23,6 +23,7 @@ module UJS config.public_file_server.enabled = true config.logger = Logger.new(STDOUT) config.log_level = :error + config.hosts << proc { true } config.content_security_policy do |policy| policy.default_src :self, :https |