diff options
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/atom_feed_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/digestor_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/record_tag_helper_test.rb | 30 | ||||
-rw-r--r-- | actionpack/test/template/render_test.rb | 7 |
6 files changed, 58 insertions, 17 deletions
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 89aae4ac56..63b5ac0fab 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -238,7 +238,7 @@ class AtomFeedTest < ActionController::TestCase get :index, :id=>"provide_builder" # because we pass in the non-default builder, the content generated by the # helper should go 'nowhere'. Leaving the response body blank. - assert_blank @response.body + assert @response.body.blank? end end diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 02b1fd87a8..849e2981a6 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -138,6 +138,20 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_dependencies_via_options_results_in_different_digest + digest_plain = digest("comments/_comment") + digest_fridge = digest("comments/_comment", dependencies: ["fridge"]) + digest_phone = digest("comments/_comment", dependencies: ["phone"]) + digest_fridge_phone = digest("comments/_comment", dependencies: ["fridge", "phone"]) + + assert_not_equal digest_plain, digest_fridge + assert_not_equal digest_plain, digest_phone + assert_not_equal digest_plain, digest_fridge_phone + assert_not_equal digest_fridge, digest_phone + assert_not_equal digest_fridge, digest_fridge_phone + assert_not_equal digest_phone, digest_fridge_phone + end + private def assert_logged(message) old_logger = ActionView::Base.logger @@ -164,8 +178,8 @@ class TemplateDigestorTest < ActionView::TestCase ActionView::Digestor.cache.clear end - def digest(template_name) - ActionView::Digestor.digest(template_name, :html, FixtureFinder.new) + def digest(template_name, options={}) + ActionView::Digestor.digest(template_name, :html, FixtureFinder.new, options) end def change_template(template_name) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index c730e3ab74..5e47e4db23 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1171,7 +1171,6 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_form_for_with_format form_for(@post, :format => :json, :html => { :id => "edit_post_123", :class => "edit_post" }) do |f| concat f.label(:title) @@ -2693,6 +2692,19 @@ class FormHelperTest < ActionView::TestCase end end + def test_form_for_only_instantiates_builder_once + initialization_count = 0 + builder_class = Class.new(ActionView::Helpers::FormBuilder) do + define_method :initialize do |*args| + super(*args) + initialization_count += 1 + end + end + + form_for(@post, builder: builder_class) { } + assert_equal 1, initialization_count, 'form builder instantiated more than once' + end + protected def hidden_fields(method = nil) diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 0a94fa079b..6c6a142397 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -488,7 +488,7 @@ class FormTagHelperTest < ActionView::TestCase def test_image_submit_tag_with_confirmation assert_dom_equal( - %(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />), + %(<input alt="Save" type="image" src="/images/save.gif" data-confirm="Are you sure?" />), image_submit_tag("save.gif", :data => { :confirm => "Are you sure?" }) ) end @@ -496,7 +496,7 @@ class FormTagHelperTest < ActionView::TestCase def test_image_submit_tag_with_deprecated_confirmation assert_deprecated ":confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: \'Text\' }' instead" do assert_dom_equal( - %(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />), + %(<input alt="Save" type="image" src="/images/save.gif" data-confirm="Are you sure?" />), image_submit_tag("save.gif", :confirm => "Are you sure?") ) end diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index a84034c02e..9c49438f6a 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -25,33 +25,33 @@ class RecordTagHelperTest < ActionView::TestCase def test_content_tag_for expected = %(<li class="record_tag_post" id="record_tag_post_45"></li>) - actual = content_tag_for(:li, @post) { } + actual = content_tag_for(:li, @post) assert_dom_equal expected, actual end def test_content_tag_for_prefix expected = %(<ul class="archived_record_tag_post" id="archived_record_tag_post_45"></ul>) - actual = content_tag_for(:ul, @post, :archived) { } + actual = content_tag_for(:ul, @post, :archived) assert_dom_equal expected, actual end def test_content_tag_for_with_extra_html_options expected = %(<tr class="record_tag_post special" id="record_tag_post_45" style='background-color: #f0f0f0'></tr>) - actual = content_tag_for(:tr, @post, :class => "special", :style => "background-color: #f0f0f0") { } + actual = content_tag_for(:tr, @post, class: "special", style: "background-color: #f0f0f0") assert_dom_equal expected, actual end def test_content_tag_for_with_prefix_and_extra_html_options expected = %(<tr class="archived_record_tag_post special" id="archived_record_tag_post_45" style='background-color: #f0f0f0'></tr>) - actual = content_tag_for(:tr, @post, :archived, :class => "special", :style => "background-color: #f0f0f0") { } + actual = content_tag_for(:tr, @post, :archived, class: "special", style: "background-color: #f0f0f0") assert_dom_equal expected, actual end def test_block_not_in_erb_multiple_calls expected = %(<div class="record_tag_post special" id="record_tag_post_45">What a wonderful world!</div>) - actual = div_for(@post, :class => "special") { @post.body } + actual = div_for(@post, class: "special") { @post.body } assert_dom_equal expected, actual - actual = div_for(@post, :class => "special") { @post.body } + actual = div_for(@post, class: "special") { @post.body } assert_dom_equal expected, actual end @@ -63,7 +63,7 @@ class RecordTagHelperTest < ActionView::TestCase def test_div_for_in_erb expected = %(<div class="record_tag_post special" id="record_tag_post_45">What a wonderful world!</div>) - actual = render_erb("<%= div_for(@post, :class => 'special') do %><%= @post.body %><% end %>") + actual = render_erb("<%= div_for(@post, class: 'special') do %><%= @post.body %><% end %>") assert_dom_equal expected, actual end @@ -75,6 +75,14 @@ class RecordTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_content_tag_for_collection_without_given_block + post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!" } + post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!" } + expected = %(<li class="record_tag_post" id="record_tag_post_101"></li>\n<li class="record_tag_post" id="record_tag_post_102"></li>) + actual = content_tag_for(:li, [post_1, post_2]) + assert_dom_equal expected, actual + end + def test_div_for_collection post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" } post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" } @@ -84,7 +92,7 @@ class RecordTagHelperTest < ActionView::TestCase end def test_content_tag_for_single_record_is_html_safe - result = div_for(@post, :class => "special") { @post.body } + result = div_for(@post, class: "special") { @post.body } assert result.html_safe? end @@ -96,8 +104,8 @@ class RecordTagHelperTest < ActionView::TestCase end def test_content_tag_for_does_not_change_options_hash - options = { :class => "important" } - content_tag_for(:li, @post, options) { } - assert_equal({ :class => "important" }, options) + options = { class: "important" } + content_tag_for(:li, @post, options) + assert_equal({ class: "important" }, options) end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9fb26e32b1..8111e58527 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -318,6 +318,13 @@ module RenderTestCases @controller_view.render(customers, :greeting => "Hello") 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") + end + assert_match "undefined local variable or method `partial_name_local_variable'", exception.message + end + # 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" }) |