diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-08-12 11:10:42 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-08-12 11:10:42 -0300 |
commit | a2400308eab88b5eff27e05d1f7624345fb33b54 (patch) | |
tree | 38630de37ac59c50061734d9f353ebb798ba2023 /actionview/test/template | |
parent | 045d7173167043389dbe8bd961425c1b1cc86d48 (diff) | |
parent | 82e28492e7c581cdeea904464a18eb11118f4ac0 (diff) | |
download | rails-a2400308eab88b5eff27e05d1f7624345fb33b54.tar.gz rails-a2400308eab88b5eff27e05d1f7624345fb33b54.tar.bz2 rails-a2400308eab88b5eff27e05d1f7624345fb33b54.zip |
Merge branch 'master' into loofah
Conflicts:
actionpack/CHANGELOG.md
actionpack/test/controller/integration_test.rb
actionview/CHANGELOG.md
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/asset_tag_helper_test.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/dependency_tracker_test.rb | 15 | ||||
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 7 | ||||
-rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 13 | ||||
-rw-r--r-- | actionview/test/template/partial_iteration_test.rb | 33 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 17 | ||||
-rw-r--r-- | actionview/test/template/test_case_test.rb | 3 |
7 files changed, 93 insertions, 3 deletions
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? 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) 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( + %{<textarea id="post_id" name="post[id]">\n123</textarea>}, + text_area("post", "id") + ) + end + def test_text_area_with_html_entities @post.body = "The HTML Entity for & is &" assert_dom_equal( 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( + "<select id=\"post_category\" name=\"post[category]\"></select>", + output_buffer + ) + end + def test_select_with_multiple_to_add_hidden_input output_buffer = select(:post, :category, "", {}, :multiple => true) assert_dom_equal( diff --git a/actionview/test/template/partial_iteration_test.rb b/actionview/test/template/partial_iteration_test.rb new file mode 100644 index 0000000000..695f9f1bef --- /dev/null +++ b/actionview/test/template/partial_iteration_test.rb @@ -0,0 +1,33 @@ +require 'abstract_unit' +require 'action_view/renderer/partial_renderer' + +class PartialIterationTest < ActiveSupport::TestCase + def test_has_size_and_index + 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 + 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 + 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 + 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 + 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 67f1aabbd2..85817119ba 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 @@ -324,11 +324,16 @@ 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") end - assert_match "undefined local variable or method `partial_name_local_variable'", exception.message + assert_instance_of NameError, exception.original_exception + assert_equal :partial_name_local_variable, exception.original_exception.name end # TODO: The reason for this test is unclear, improve documentation @@ -387,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 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 |