diff options
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/actionpack/abstract/render_test.rb | 1 | ||||
-rw-r--r-- | actionview/test/actionpack/controller/render_test.rb | 4 | ||||
-rw-r--r-- | actionview/test/fixtures/digestor/comments/_comment.html.erb | 2 | ||||
-rw-r--r-- | actionview/test/fixtures/test/_klass.erb | 1 | ||||
-rw-r--r-- | actionview/test/template/asset_tag_helper_test.rb | 5 | ||||
-rw-r--r-- | actionview/test/template/date_helper_test.rb | 20 | ||||
-rw-r--r-- | actionview/test/template/form_collections_helper_test.rb | 53 | ||||
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 53 | ||||
-rw-r--r-- | actionview/test/template/form_tag_helper_test.rb | 34 | ||||
-rw-r--r-- | actionview/test/template/lookup_context_test.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 20 | ||||
-rw-r--r-- | actionview/test/template/template_error_test.rb | 25 | ||||
-rw-r--r-- | actionview/test/template/translation_helper_test.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/url_helper_test.rb | 31 |
14 files changed, 230 insertions, 29 deletions
diff --git a/actionview/test/actionpack/abstract/render_test.rb b/actionview/test/actionpack/abstract/render_test.rb index e5721d6416..e185b76adb 100644 --- a/actionview/test/actionpack/abstract/render_test.rb +++ b/actionview/test/actionpack/abstract/render_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'active_support/deprecation' module AbstractController module Testing diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 27150c7d5f..bdb9e0397b 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -466,7 +466,7 @@ class TestController < ApplicationController end def render_content_type_from_body - response.content_type = Mime::RSS + response.content_type = Mime[:rss] render body: "hello world!" end @@ -728,7 +728,7 @@ class RenderTest < ActionController::TestCase def test_render_process get :render_action_hello_world_as_string - assert_equal ["Hello world!"], @controller.process(:render_action_hello_world_as_string) + assert_equal "Hello world!", @controller.process(:render_action_hello_world_as_string) end # :ported: diff --git a/actionview/test/fixtures/digestor/comments/_comment.html.erb b/actionview/test/fixtures/digestor/comments/_comment.html.erb index f172e749da..a8fa21f644 100644 --- a/actionview/test/fixtures/digestor/comments/_comment.html.erb +++ b/actionview/test/fixtures/digestor/comments/_comment.html.erb @@ -1 +1 @@ -Great story, bro! +Great story! diff --git a/actionview/test/fixtures/test/_klass.erb b/actionview/test/fixtures/test/_klass.erb new file mode 100644 index 0000000000..9936f86001 --- /dev/null +++ b/actionview/test/fixtures/test/_klass.erb @@ -0,0 +1 @@ +<%= klass.class.name %>
\ No newline at end of file diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 496b33b35e..fe40010528 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -97,6 +97,7 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_include_tag("bank")) => %(<script src="/javascripts/bank.js" ></script>), %(javascript_include_tag("bank.js")) => %(<script src="/javascripts/bank.js" ></script>), %(javascript_include_tag("bank", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/bank.js" ></script>), + %(javascript_include_tag("bank", :host => "assets.example.com")) => %(<script src="http://assets.example.com/javascripts/bank.js"></script>), %(javascript_include_tag("http://example.com/all")) => %(<script src="http://example.com/all"></script>), %(javascript_include_tag("http://example.com/all.js")) => %(<script src="http://example.com/all.js"></script>), @@ -141,6 +142,7 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_link_tag("/elsewhere/file")) => %(<link href="/elsewhere/file.css" media="screen" rel="stylesheet" />), %(stylesheet_link_tag("subdir/subdir")) => %(<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" />), %(stylesheet_link_tag("bank", :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" />), + %(stylesheet_link_tag("bank", :host => "assets.example.com")) => %(<link href="http://assets.example.com/stylesheets/bank.css" media="screen" rel="stylesheet" />), %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" />), %(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" />), @@ -191,7 +193,8 @@ class AssetTagHelperTest < ActionView::TestCase %(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />), %(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />), %(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />), - %(image_tag("")) => %(<img src="" />) + %(image_tag("")) => %(<img src="" />), + %(image_tag("gold.png", data: { title: 'Rails Application' })) => %(<img data-title="Rails Application" src="/images/gold.png" alt="Gold" />) } FaviconLinkToTag = { diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index 9212420ec9..c4234a71c3 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -1559,6 +1559,26 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :selected => Date.new(2004, 07, 10)) end + def test_date_select_with_selected_in_hash + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} + expected << "</select>\n" + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7" selected="selected">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} + expected << "</select>\n" + + expected << %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10" selected="selected">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n} + + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", :selected => {day: 10, month: 07, year: 2004}) + end + def test_date_select_with_selected_nil @post = Post.new @post.written_on = Date.new(2004, 6, 15) diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index b193d387c3..b59be8e36c 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -198,6 +198,41 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'input[type=radio][value=false][checked=checked]' end + test 'collection radio buttons generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_radio_buttons :user, :category_ids, collection, :id, :name + + assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 1 + end + + test 'collection radio buttons generates a hidden field using the given :name in :html_options' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_radio_buttons :user, :category_ids, collection, :id, :name, {}, { name: "user[other_category_ids][]" } + + assert_select "input[type=hidden][name='user[other_category_ids][]'][value='']", count: 1 + end + + test 'collection radio buttons generates a hidden field with index if it was provided' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_radio_buttons :user, :category_ids, collection, :id, :name, { index: 322 } + + assert_select "input[type=hidden][name='user[322][category_ids][]'][value='']", count: 1 + end + + test 'collection radio buttons does not generate a hidden field if include_hidden option is false' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_radio_buttons :user, :category_ids, collection, :id, :name, include_hidden: false + + assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 0 + end + + test 'collection radio buttons does not generate a hidden field if include_hidden option is false with key as string' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_radio_buttons :user, :category_ids, collection, :id, :name, 'include_hidden' => false + + assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 0 + end + # COLLECTION CHECK BOXES test 'collection check boxes accepts a collection and generate a series of checkboxes for value method' do collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] @@ -235,6 +270,13 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select "input[type=hidden][name='user[category_ids][]'][value='']", :count => 0 end + test 'collection check boxes does not generate a hidden field if include_hidden option is false with key as string' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_check_boxes :user, :category_ids, collection, :id, :name, 'include_hidden' => false + + assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 0 + end + test 'collection check boxes accepts a collection and generate a series of checkboxes with labels for label method' do collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] with_collection_check_boxes :user, :category_ids, collection, :id, :name @@ -264,6 +306,17 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'input[type=checkbox][value="2"].bar' end + test 'collection check boxes propagates input id to the label for attribute' do + collection = [[1, 'Category 1', {id: 'foo'}], [2, 'Category 2', {id: 'bar'}]] + with_collection_check_boxes :user, :active, collection, :first, :second + + assert_select 'input[type=checkbox][value="1"]#foo' + assert_select 'input[type=checkbox][value="2"]#bar' + + assert_select 'label[for=foo]' + assert_select 'label[for=bar]' + end + test 'collection check boxes sets the label class defined inside the block' do collection = [[1, 'Category 1', {class: 'foo'}], [2, 'Category 2', {class: 'bar'}]] with_collection_check_boxes :user, :active, collection, :second, :first do |b| diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 77c660d450..1f7ff3ca7c 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1281,7 +1281,7 @@ class FormHelperTest < ActionView::TestCase end def test_week_field - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} assert_dom_equal(expected, week_field("post", "written_on")) end @@ -1292,13 +1292,13 @@ class FormHelperTest < ActionView::TestCase end def test_week_field_with_datetime_value - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = DateTime.new(2004, 6, 15, 1, 2, 3) assert_dom_equal(expected, week_field("post", "written_on")) end def test_week_field_with_extra_attrs - expected = %{<input id="post_written_on" step="2" max="2010-W51" min="2000-W06" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" step="2" max="2010-W51" min="2000-W06" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = DateTime.new(2004, 6, 15, 1, 2, 3) min_value = DateTime.new(2000, 2, 13) max_value = DateTime.new(2010, 12, 23) @@ -1308,13 +1308,19 @@ class FormHelperTest < ActionView::TestCase def test_week_field_with_timewithzone_value previous_time_zone, Time.zone = Time.zone, 'UTC' - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = Time.zone.parse('2004-06-15 15:30:45') assert_dom_equal(expected, week_field("post", "written_on")) ensure Time.zone = previous_time_zone end + def test_week_field_week_number_base + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2015-W01" />} + @post.written_on = DateTime.new(2015, 1, 1, 1, 2, 3) + assert_dom_equal(expected, week_field("post", "written_on")) + end + def test_url_field expected = %{<input id="user_homepage" name="user[homepage]" type="url" />} assert_dom_equal(expected, url_field("user", "homepage")) @@ -1539,9 +1545,10 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_requires_block - assert_raises(ArgumentError) do - form_for(:post, @post, html: { id: 'create-post' }) + error = assert_raises(ArgumentError) do + form_for(@post, html: { id: 'create-post' }) end + assert_equal "Missing block", error.message end def test_form_for_requires_arguments @@ -1596,7 +1603,8 @@ class FormHelperTest < ActionView::TestCase "<input id='post_active_true' name='post[active]' type='radio' value='true' />" + "<label for='post_active_true'>true</label>" + "<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" + - "<label for='post_active_false'>false</label>" + "<label for='post_active_false'>false</label>" + + "<input type='hidden' name='post[active][]' value='' />" end assert_dom_equal expected, output_buffer @@ -1619,7 +1627,8 @@ class FormHelperTest < ActionView::TestCase "true</label>" + "<label for='post_active_false'>"+ "<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" + - "false</label>" + "false</label>" + + "<input type='hidden' name='post[active][]' value='' />" end assert_dom_equal expected, output_buffer @@ -1645,6 +1654,7 @@ class FormHelperTest < ActionView::TestCase "<label for='post_active_false'>"+ "<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" + "false</label>"+ + "<input type='hidden' name='post[active][]' value='' />" + "<input id='post_id' name='post[id]' type='hidden' value='1' />" end @@ -1663,7 +1673,8 @@ class FormHelperTest < ActionView::TestCase "<input id='foo_post_active_true' name='post[active]' type='radio' value='true' />" + "<label for='foo_post_active_true'>true</label>" + "<input checked='checked' id='foo_post_active_false' name='post[active]' type='radio' value='false' />" + - "<label for='foo_post_active_false'>false</label>" + "<label for='foo_post_active_false'>false</label>" + + "<input type='hidden' name='post[active][]' value='' />" end assert_dom_equal expected, output_buffer @@ -1681,7 +1692,8 @@ class FormHelperTest < ActionView::TestCase "<input id='post_1_active_true' name='post[1][active]' type='radio' value='true' />" + "<label for='post_1_active_true'>true</label>" + "<input checked='checked' id='post_1_active_false' name='post[1][active]' type='radio' value='false' />" + - "<label for='post_1_active_false'>false</label>" + "<label for='post_1_active_false'>false</label>" + + "<input type='hidden' name='post[1][active][]' value='' />" end assert_dom_equal expected, output_buffer @@ -2292,6 +2304,27 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_deep_nested_fields_for + @comment.save + form_for(:posts) do |f| + f.fields_for('post[]', @post) do |f2| + f2.text_field(:id) + @post.comments.each do |comment| + concat f2.fields_for('comment[]', comment) { |c| + concat c.text_field(:name) + } + end + end + end + + expected = whole_form do + "<input name='posts[post][0][comment][1][name]' type='text' id='posts_post_0_comment_1_name' value='comment #1' />" + end + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_nested_collections form_for(@post, as: 'post[]') do |f| concat f.text_field(:title) diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index a9d9562580..de1eb89dc5 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -64,6 +64,18 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_check_box_tag_disabled + actual = check_box_tag "admin","1", false, disabled: true + expected = %(<input id="admin" disabled="disabled" name="admin" type="checkbox" value="1" />) + assert_dom_equal expected, actual + end + + def test_check_box_tag_default_checked + actual = check_box_tag "admin","1", true + expected = %(<input id="admin" checked="checked" name="admin" type="checkbox" value="1" />) + assert_dom_equal expected, actual + end + def test_check_box_tag_id_sanitized label_elem = root_elem(check_box_tag("project[2][admin]")) assert_match VALID_HTML_ID, label_elem['id'] @@ -351,12 +363,18 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end - def test_text_field_disabled + def test_text_field_tag_disabled actual = text_field_tag "title", "Hello!", disabled: true expected = %(<input id="title" name="title" disabled="disabled" type="text" value="Hello!" />) assert_dom_equal expected, actual end + def test_text_field_tag_with_placeholder_option + actual = text_field_tag "title", "Hello!", placeholder: 'Enter search term...' + expected = %(<input id="title" name="title" placeholder="Enter search term..." type="text" value="Hello!" />) + assert_dom_equal expected, actual + end + def test_text_field_tag_with_multiple_options actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80 expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />) @@ -450,21 +468,21 @@ class FormTagHelperTest < ActionView::TestCase ActionView::Base.automatically_disable_submit_tag = true end - def test_data_disable_with_string + def test_submit_tag_having_data_disable_with_string assert_dom_equal( %(<input data-disable-with="Processing..." data-confirm="Are you sure?" name='commit' type="submit" value="Save" />), submit_tag("Save", { "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?" }) ) end - def test_data_disable_with_boolean + def test_submit_tag_having_data_disable_with_boolean assert_dom_equal( %(<input data-confirm="Are you sure?" name='commit' type="submit" value="Save" />), submit_tag("Save", { "data-disable-with" => false, "data-confirm" => "Are you sure?" }) ) end - def test_data_hash_disable_with_boolean + def test_submit_tag_having_data_hash_disable_with_boolean assert_dom_equal( %(<input data-confirm="Are you sure?" name='commit' type="submit" value="Save" />), submit_tag("Save", { :data => { :confirm => "Are you sure?", :disable_with => false } }) @@ -485,6 +503,14 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_submit_tag_doesnt_have_data_disable_with_twice + assert_equal( + %(<input type="submit" name="commit" value="Save" data-confirm="Are you sure?" data-disable-with="Processing..." />), + submit_tag("Save", { "data-disable-with" => "Processing...", "data-confirm" => "Are you sure?" }) + ) + end + + def test_button_tag assert_dom_equal( %(<button name="button" type="submit">Button</button>), diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 1184cf7da8..2e3a3f9bae 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -52,7 +52,7 @@ class LookupContextTest < ActiveSupport::TestCase end test "handles explicitly defined */* formats fallback to :js" do - @lookup_context.formats = [:js, Mime::Type[:ALL]] + @lookup_context.formats = [:js, Mime::ALL] assert_equal [:js, *Mime::SET.symbols], @lookup_context.formats end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 9c2c9507b7..84aca222b2 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -247,6 +247,8 @@ module RenderTestCases 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) end def test_render_object_with_array @@ -352,8 +354,8 @@ 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 + assert_instance_of NameError, exception.cause + assert_equal :partial_name_local_variable, exception.cause.name end # TODO: The reason for this test is unclear, improve documentation @@ -590,14 +592,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") } - assert_match 'Your template was not saved as valid Shift_JIS', e.original_exception.message + 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") } - assert_match 'Your template was not saved as valid Shift_JIS', e.original_exception.message + assert_match 'Your template was not saved as valid Shift_JIS', e.cause.message end end @@ -627,6 +629,16 @@ class CachedCollectionViewRenderTest < CachedViewRenderTest @view.render(partial: "test/customer", collection: [customer], cache: ->(item) { [item, 'key'] }) end + test "with caching with custom key and rendering with different key" do + customer = Customer.new("david") + key = cache_key([customer, 'key'], "test/_customer") + + ActionView::PartialRenderer.collection_cache.write(key, 'Hello') + + assert_equal "Hello: david", + @view.render(partial: "test/customer", collection: [customer], cache: ->(item) { [item, 'another_key'] }) + end + test "automatic caching with inferred cache name" do customer = CachedCustomer.new("david") key = cache_key(customer, "test/_cached_customer") diff --git a/actionview/test/template/template_error_test.rb b/actionview/test/template/template_error_test.rb index 3971ec809c..54c1d53b60 100644 --- a/actionview/test/template/template_error_test.rb +++ b/actionview/test/template/template_error_test.rb @@ -2,19 +2,34 @@ require "abstract_unit" class TemplateErrorTest < ActiveSupport::TestCase def test_provides_original_message - error = ActionView::Template::Error.new("test", Exception.new("original")) + error = begin + raise Exception.new("original") + rescue Exception + raise ActionView::Template::Error.new("test") rescue $! + end + assert_equal "original", error.message end def test_provides_original_backtrace - original_exception = Exception.new - original_exception.set_backtrace(%W[ foo bar baz ]) - error = ActionView::Template::Error.new("test", original_exception) + error = begin + original_exception = Exception.new + original_exception.set_backtrace(%W[ foo bar baz ]) + raise original_exception + rescue Exception + raise ActionView::Template::Error.new("test") rescue $! + end + assert_equal %W[ foo bar baz ], error.backtrace end def test_provides_useful_inspect - error = ActionView::Template::Error.new("test", Exception.new("original")) + error = begin + raise Exception.new("original") + rescue Exception + raise ActionView::Template::Error.new("test") rescue $! + end + assert_equal "#<ActionView::Template::Error: original>", error.inspect end end diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 261576bead..631bceadd8 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -66,6 +66,14 @@ class TranslationHelperTest < ActiveSupport::TestCase assert translate(:"translations.missing").html_safe? end + def test_returns_missing_translation_message_does_filters_out_i18n_options + expected = '<span class="translation_missing" title="translation missing: en.translations.missing, year: 2015">Missing</span>' + assert_equal expected, translate(:"translations.missing", year: '2015', default: []) + + expected = '<span class="translation_missing" title="translation missing: en.scoped.translations.missing, year: 2015">Missing</span>' + assert_equal expected, translate(:"translations.missing", year: '2015', scope: %i(scoped)) + end + def test_raises_missing_translation_message_with_raise_config_option ActionView::Base.raise_on_missing_translations = true diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 50b7865f88..48d0a9a47a 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -50,6 +50,23 @@ class UrlHelperTest < ActiveSupport::TestCase assert_equal 'javascript:history.back()', url_for(:back) end + def test_url_for_with_back_and_no_controller + @controller = nil + assert_equal 'javascript:history.back()', url_for(:back) + end + + def test_url_for_with_back_and_javascript_referer + referer = 'javascript:alert(document.cookie)' + @controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer)) + assert_equal 'javascript:history.back()', url_for(:back) + end + + def test_url_for_with_invalid_referer + referer = 'THIS IS NOT A URL' + @controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer)) + assert_equal 'javascript:history.back()', url_for(:back) + end + def test_button_to_with_straight_url assert_dom_equal %{<form method="post" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /></form>}, button_to("Hello", "http://www.example.com") end @@ -523,6 +540,20 @@ class UrlHelperTest < ActiveSupport::TestCase mail_to('feedback@example.com', '<img src="/feedback.png" />'.html_safe) end + def test_mail_to_with_html_safe_string + assert_dom_equal( + %{<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>}, + mail_to("david@loudthinking.com".html_safe) + ) + end + + def test_mail_to_with_nil + assert_dom_equal( + %{<a href="mailto:"></a>}, + mail_to(nil) + ) + end + def test_mail_to_returns_html_safe_string assert mail_to("david@loudthinking.com").html_safe? end |