From 5f6b7c96fb3388bdd8488282f303f2e058c5a8fa Mon Sep 17 00:00:00 2001 From: Federico Ravasio Date: Fri, 23 Aug 2013 09:57:10 +0200 Subject: Use NameError#name to assert raised error. This makes the test compatible with other Ruby implementations, which may implement error messages differently. --- actionview/test/template/render_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/test/template') diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 5a7d11f513..0395ce3735 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -319,7 +319,7 @@ module RenderTestCases exception = assert_raises ActionView::Template::Error do @controller_view.render("partial_name_local_variable") end - assert_match "undefined local variable or method `partial_name_local_variable'", exception.message + assert_equal :partial_name_local_variable, exception.original_exception.name end # TODO: The reason for this test is unclear, improve documentation -- cgit v1.2.3 From 424878526276c989a02f0ae353da630d234f519c Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 12 Jul 2014 18:52:40 +0930 Subject: Assert the nature of the original exception Just so it's clearer what's going on in the following assertion. /cc #11993 @robin850 --- actionview/test/template/render_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index e9e33bb5f6..a26f20d522 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -328,6 +328,7 @@ module RenderTestCases exception = assert_raises ActionView::Template::Error do @controller_view.render("partial_name_local_variable") end + assert_instance_of NameError, exception.original_exception assert_equal :partial_name_local_variable, exception.original_exception.name end -- cgit v1.2.3 From d005777469b7182b1a8f657a5b94363b321bef5d Mon Sep 17 00:00:00 2001 From: Jolyon Pawlyn Date: Sat, 12 Jul 2014 17:00:09 +0100 Subject: Return an absolute instead of relative path from an asset url in the case of the `asset_host` proc returning nil --- actionview/test/template/asset_tag_helper_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 343681b5a9..d789a5ca27 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -546,6 +546,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal "http://cdn.example.com/images/file.png", image_path("file.png") end + def test_image_url_with_asset_host_proc_returning_nil + @controller.config.asset_host = Proc.new { nil } + @controller.request = Struct.new(:base_url, :script_name).new("http://www.example.com", nil) + + assert_equal "/images/rails.png", image_path("rails.png") + assert_equal "http://www.example.com/images/rails.png", image_url("rails.png") + end + def test_caching_image_path_with_caching_and_proc_asset_host_using_request @controller.config.asset_host = Proc.new do |source, request| if request.ssl? -- cgit v1.2.3 From 1f5b360466c3494267cc9aad08a19d1ace4763d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Junstr=C3=B6m?= Date: Sun, 16 Sep 2012 22:45:08 +0200 Subject: Added PartialIteration class used when rendering collections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The iteration object is available as the local variable "template_name_iteration" when rendering partials with collections. It gives access to the +size+ of the collection beeing iterated over, the current +index+ and two convinicence methods +first?+ and +last?+ "template_name_counter" variable is kept but is deprecated. [Joel Junström + Lucas Uyezu] --- actionview/test/template/partial_iteration_test.rb | 31 ++++++++++++++++++++++ actionview/test/template/render_test.rb | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 actionview/test/template/partial_iteration_test.rb (limited to 'actionview/test/template') diff --git a/actionview/test/template/partial_iteration_test.rb b/actionview/test/template/partial_iteration_test.rb new file mode 100644 index 0000000000..3976c855ae --- /dev/null +++ b/actionview/test/template/partial_iteration_test.rb @@ -0,0 +1,31 @@ +require 'abstract_unit' +require 'action_view/partial_iteration' +class PartialIterationTest < ActiveSupport::TestCase + + def test_has_size_and_index + iteration = ActionView::PartialIteration.new 3, 0 + assert_equal 0, iteration.index, "should be at the first index" + assert_equal 3, iteration.size, "should have the size" + end + + def test_first_is_true_when_current_is_at_the_first_index + iteration = ActionView::PartialIteration.new 3, 0 + assert iteration.first?, "first when current is 0" + end + + def test_first_is_false_unless_current_is_at_the_first_index + iteration = ActionView::PartialIteration.new 3, 1 + assert !iteration.first?, "not first when current is 1" + end + + def test_last_is_true_when_current_is_at_the_last_index + iteration = ActionView::PartialIteration.new 3, 2 + assert iteration.last?, "last when current is 2" + end + + def test_last_is_false_unless_current_is_at_the_last_index + iteration = ActionView::PartialIteration.new 3, 0 + assert !iteration.last?, "not last when current is 0" + end + +end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index a26f20d522..c13e59d82b 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -256,7 +256,7 @@ module RenderTestCases end def test_render_partial_collection_without_as - assert_equal "local_inspector,local_inspector_counter", + assert_equal "local_inspector,local_inspector_counter,local_inspector_iteration", @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ]) end -- cgit v1.2.3 From 9830ebbeaf6f7faead9b4503ed9c9ab0a327df9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 16 Jul 2014 14:13:42 -0300 Subject: No need to have a file to PartialIteration class This class is only used on the PartialRenderer. --- actionview/test/template/partial_iteration_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionview/test/template') diff --git a/actionview/test/template/partial_iteration_test.rb b/actionview/test/template/partial_iteration_test.rb index 3976c855ae..af0dde96c3 100644 --- a/actionview/test/template/partial_iteration_test.rb +++ b/actionview/test/template/partial_iteration_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' -require 'action_view/partial_iteration' -class PartialIterationTest < ActiveSupport::TestCase +require 'action_view/renderer/partial_renderer' +class PartialIterationTest < ActiveSupport::TestCase def test_has_size_and_index iteration = ActionView::PartialIteration.new 3, 0 assert_equal 0, iteration.index, "should be at the first index" @@ -27,5 +27,4 @@ class PartialIterationTest < ActiveSupport::TestCase iteration = ActionView::PartialIteration.new 3, 0 assert !iteration.last?, "not last when current is 0" end - end -- cgit v1.2.3 From 9290fc5ce213836f666a97e0e458d98e69a920ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 16 Jul 2014 14:28:39 -0300 Subject: Build only one PartialIteration object for loop --- actionview/test/template/partial_iteration_test.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'actionview/test/template') diff --git a/actionview/test/template/partial_iteration_test.rb b/actionview/test/template/partial_iteration_test.rb index af0dde96c3..695f9f1bef 100644 --- a/actionview/test/template/partial_iteration_test.rb +++ b/actionview/test/template/partial_iteration_test.rb @@ -3,28 +3,31 @@ require 'action_view/renderer/partial_renderer' class PartialIterationTest < ActiveSupport::TestCase def test_has_size_and_index - iteration = ActionView::PartialIteration.new 3, 0 + iteration = ActionView::PartialIteration.new 3 assert_equal 0, iteration.index, "should be at the first index" assert_equal 3, iteration.size, "should have the size" end def test_first_is_true_when_current_is_at_the_first_index - iteration = ActionView::PartialIteration.new 3, 0 + iteration = ActionView::PartialIteration.new 3 assert iteration.first?, "first when current is 0" end def test_first_is_false_unless_current_is_at_the_first_index - iteration = ActionView::PartialIteration.new 3, 1 + iteration = ActionView::PartialIteration.new 3 + iteration.iterate! assert !iteration.first?, "not first when current is 1" end def test_last_is_true_when_current_is_at_the_last_index - iteration = ActionView::PartialIteration.new 3, 2 + iteration = ActionView::PartialIteration.new 3 + iteration.iterate! + iteration.iterate! assert iteration.last?, "last when current is 2" end def test_last_is_false_unless_current_is_at_the_last_index - iteration = ActionView::PartialIteration.new 3, 0 + iteration = ActionView::PartialIteration.new 3 assert !iteration.last?, "not last when current is 0" end end -- cgit v1.2.3 From c6a97b8d4d07b430d821f0ede0df32da30a210b8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 16 Jul 2014 21:48:26 -0700 Subject: subclass Rails::Engine --- actionview/test/template/test_case_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionview/test/template') diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index 4ee0930341..4582fa13ee 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'rails/engine' module ActionView @@ -223,7 +224,7 @@ module ActionView test "is able to use mounted routes" do with_routing do |set| - app = Class.new do + app = Class.new(Rails::Engine) do def self.routes @routes ||= ActionDispatch::Routing::RouteSet.new end -- cgit v1.2.3 From 080c2ba0cadc9789ae97a35ef23808d3c0197b9c Mon Sep 17 00:00:00 2001 From: Eugene Gilburg Date: Fri, 18 Jul 2014 20:55:22 -0700 Subject: adding missing test coverage --- actionview/test/template/render_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index c13e59d82b..85817119ba 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -324,6 +324,10 @@ module RenderTestCases @controller_view.render(customers, :greeting => "Hello") end + def test_render_partial_using_collection_without_path + assert_equal "hi good customer: david0", @controller_view.render([ GoodCustomer.new("david") ], greeting: "hi") + end + def test_render_partial_without_object_or_collection_does_not_generate_partial_name_local_variable exception = assert_raises ActionView::Template::Error do @controller_view.render("partial_name_local_variable") @@ -388,6 +392,14 @@ module RenderTestCases ActionView::Template.unregister_template_handler :foo end + def test_render_body + assert_equal 'some body', @view.render(body: 'some body') + end + + def test_render_plain + assert_equal 'some plaintext', @view.render(plain: 'some plaintext') + end + def test_render_knows_about_types_registered_when_extensions_are_checked_earlier_in_initialization ActionView::Template::Handlers.extensions ActionView::Template.register_template_handler :foo, CustomHandler -- cgit v1.2.3 From afc928445dbf22bbcb4cc97e67638cbc71ce0c9b Mon Sep 17 00:00:00 2001 From: Eugene Gilburg Date: Fri, 18 Jul 2014 21:34:23 -0700 Subject: adding missing test for text area value before type cast --- actionview/test/template/form_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 3e39dadcf1..a9f137aec6 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -694,6 +694,13 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_area_with_value_before_type_cast + assert_dom_equal( + %{}, + text_area("post", "id") + ) + end + def test_text_area_with_html_entities @post.body = "The HTML Entity for & is &" assert_dom_equal( -- cgit v1.2.3 From da1b8a786cad277c1e4dc1a9f03acec4268dda1f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 25 Jul 2014 16:35:16 -0700 Subject: Fix that render layout should also be picked up by the template dependency tracker, but only half-ways. You can add that layout option on the same render call, and both templates should be added to the dependency tree. But thats going to require a more serious rework of the tracker. Please do help fix this part of it too. For now, render layout needs to be on its own line. --- actionview/test/template/dependency_tracker_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/dependency_tracker_test.rb b/actionview/test/template/dependency_tracker_test.rb index 6c780f2297..bb375076c6 100644 --- a/actionview/test/template/dependency_tracker_test.rb +++ b/actionview/test/template/dependency_tracker_test.rb @@ -60,6 +60,21 @@ class ERBTrackerTest < Minitest::Test assert_equal ["messages/message123"], tracker.dependencies end + def test_dependency_of_template_partial_with_layout + skip # FIXME: Needs to be fixed properly, right now we can only match one dependency per line. Need multiple! + template = FakeTemplate.new("<%# render partial: 'messages/show', layout: 'messages/layout' %>", :erb) + tracker = make_tracker("multiple/_dependencies", template) + + assert_equal ["messages/layout", "messages/show"], tracker.dependencies + end + + def test_dependency_of_template_layout_standalone + template = FakeTemplate.new("<%# render layout: 'messages/layout' do %>", :erb) + tracker = make_tracker("messages/layout", template) + + assert_equal ["messages/layout"], tracker.dependencies + end + def test_finds_dependency_in_correct_directory template = FakeTemplate.new("<%# render(message.topic) %>", :erb) tracker = make_tracker("messages/_message", template) -- cgit v1.2.3 From 7a0c2ba48b0145e5031e51d316407ba28d769905 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Tue, 5 Aug 2014 17:23:00 +0300 Subject: Fixed #select form builder helper to support block with html output --- actionview/test/template/form_options_helper_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index fbafb7aa08..d25fa3706f 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -591,6 +591,19 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_under_fields_for_with_block_without_options + @post = Post.new + + output_buffer = fields_for :post, @post do |f| + concat(f.select(:category) {}) + end + + assert_dom_equal( + "", + output_buffer + ) + end + def test_select_with_multiple_to_add_hidden_input output_buffer = select(:post, :category, "", {}, :multiple => true) assert_dom_equal( -- cgit v1.2.3