diff options
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/date_helper_test.rb | 12 | ||||
-rw-r--r-- | actionview/test/template/digestor_test.rb | 47 | ||||
-rw-r--r-- | actionview/test/template/form_collections_helper_test.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 19 | ||||
-rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 15 | ||||
-rw-r--r-- | actionview/test/template/javascript_helper_test.rb | 7 | ||||
-rw-r--r-- | actionview/test/template/lookup_context_test.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 5 | ||||
-rw-r--r-- | actionview/test/template/resolver_patterns_test.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/text_helper_test.rb | 3 | ||||
-rw-r--r-- | actionview/test/template/url_helper_test.rb | 22 |
11 files changed, 122 insertions, 20 deletions
diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index 242b56a1fd..5f09aef249 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -19,8 +19,6 @@ class DateHelperTest < ActionView::TestCase end def assert_distance_of_time_in_words(from, to=nil) - Fixnum.send :private, :/ # test we avoid Integer#/ (redefined by mathn) - to ||= from # 0..1 minute with :include_seconds => true @@ -123,9 +121,6 @@ class DateHelperTest < ActionView::TestCase assert_equal "about 4 hours", distance_of_time_in_words(from + 4.hours, to) assert_equal "less than 20 seconds", distance_of_time_in_words(from + 19.seconds, to, :include_seconds => true) assert_equal "less than a minute", distance_of_time_in_words(from + 19.seconds, to, :include_seconds => false) - - ensure - Fixnum.send :public, :/ end def test_distance_in_words @@ -133,6 +128,13 @@ class DateHelperTest < ActionView::TestCase assert_distance_of_time_in_words(from) end + def test_distance_in_words_with_mathn_required + # test we avoid Integer#/ (redefined by mathn) + require 'mathn' + from = Time.utc(2004, 6, 6, 21, 45, 0) + assert_distance_of_time_in_words(from) + end + def test_time_ago_in_words_passes_include_seconds assert_equal "less than 20 seconds", time_ago_in_words(15.seconds.ago, :include_seconds => true) assert_equal "less than a minute", time_ago_in_words(15.seconds.ago, :include_seconds => false) diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 07f8d36d93..0f6b14a57d 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -15,6 +15,16 @@ end class FixtureFinder FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" + attr_reader :details + + def initialize + @details = {} + end + + def details_key + details.hash + end + def find(logical_name, keys, partial, options) FixtureTemplate.new("digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") end @@ -100,7 +110,7 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_nil digest("level/recursion") # assert digest is stored end - def test_chaning_the_top_templete_on_recursion + def test_chaining_the_top_template_on_recursion assert digest("level/recursion") # assert recursion is possible assert_digest_difference("level/recursion") do @@ -110,7 +120,7 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_nil digest("level/recursion") # assert digest is stored end - def test_chaning_the_partial_templete_on_recursion + def test_chaining_the_partial_template_on_recursion assert digest("level/recursion") # assert recursion is possible assert_digest_difference("level/recursion") do @@ -140,6 +150,20 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_details_are_included_in_cache_key + # Cache the template digest. + old_digest = digest("events/_event") + + # Change the template; the cached digest remains unchanged. + change_template("events/_event") + + # The details are changed, so a new cache key is generated. + finder.details[:foo] = "bar" + + # The cache is busted. + assert_not_equal old_digest, digest("events/_event") + end + def test_extra_whitespace_in_render_partial assert_digest_difference("messages/edit") do change_template("messages/_form") @@ -184,6 +208,15 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_equal digest_phone, digest_fridge_phone end + def test_cache_template_loading + resolver_before = ActionView::Resolver.caching + ActionView::Resolver.caching = false + assert_digest_difference("messages/edit", true) do + change_template("comments/_comment") + end + ActionView::Resolver.caching = resolver_before + end + private def assert_logged(message) old_logger = ActionView::Base.logger @@ -200,9 +233,9 @@ class TemplateDigestorTest < ActionView::TestCase end end - def assert_digest_difference(template_name) + def assert_digest_difference(template_name, persistent = false) previous_digest = digest(template_name) - ActionView::Digestor.cache.clear + ActionView::Digestor.cache.clear unless persistent yield @@ -211,7 +244,11 @@ class TemplateDigestorTest < ActionView::TestCase end def digest(template_name, options={}) - ActionView::Digestor.digest(template_name, :html, FixtureFinder.new, options) + ActionView::Digestor.digest(template_name, :html, finder, options) + end + + def finder + @finder ||= FixtureFinder.new end def change_template(template_name) diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index bc9c21dfd3..b56847396d 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -17,14 +17,14 @@ class FormCollectionsHelperTest < ActionView::TestCase end # COLLECTION RADIO BUTTONS - test 'collection radio accepts a collection and generate inputs from value method' do + test 'collection radio accepts a collection and generates inputs from value method' do with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s assert_select 'input[type=radio][value=true]#user_active_true' assert_select 'input[type=radio][value=false]#user_active_false' end - test 'collection radio accepts a collection and generate inputs from label method' do + test 'collection radio accepts a collection and generates inputs from label method' do with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s assert_select 'label[for=user_active_true]', 'true' @@ -38,7 +38,7 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'label[for=user_active_no]', 'No' end - test 'colection radio should sanitize collection values for labels correctly' do + 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' @@ -194,7 +194,7 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'label[for=user_active_no]', 'No' end - test 'colection check box should sanitize collection values for labels correctly' do + 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' diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index f05b6d0d94..944884c9dd 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -676,6 +676,13 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_area_with_nil_alternate_value + assert_dom_equal( + %{<textarea id="post_body" name="post[body]">\n</textarea>}, + text_area("post", "body", value: nil) + ) + end + def test_text_area_with_html_entities @post.body = "The HTML Entity for & is &" assert_dom_equal( @@ -1674,6 +1681,18 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_namespace_and_as_option + form_for(@post, namespace: 'namespace', as: 'custom_name') do |f| + concat f.text_field(:title) + end + + expected = whole_form('/posts/123', 'namespace_edit_custom_name', 'edit_custom_name', method: 'patch') do + "<input id='namespace_custom_name_title' name='custom_name[title]' type='text' value='Hello World' />" + end + + assert_dom_equal expected, output_buffer + end + def test_two_form_for_with_namespace form_for(@post, namespace: 'namespace_1') do |f| concat f.label(:title) diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index 8c90a58a84..a6977766d1 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'tzinfo' class Map < Hash def category @@ -7,8 +6,6 @@ class Map < Hash end end -TZInfo::Timezone.cattr_reader :loaded_zones - class FormOptionsHelperTest < ActionView::TestCase tests ActionView::Helpers::FormOptionsHelper @@ -22,7 +19,7 @@ class FormOptionsHelperTest < ActionView::TestCase def setup @fake_timezones = %w(A B C D E).map do |id| - tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id) + tz = stub(:name => id, :to_s => id) ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz) tz end @@ -302,6 +299,16 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_grouped_options_for_select_with_array_and_html_attributes + assert_dom_equal( + "<optgroup label=\"North America\" data-foo=\"bar\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\" disabled=\"disabled\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>", + grouped_options_for_select([ + ["North America", [['United States','US'],"Canada"], :data => { :foo => 'bar' }], + ["Europe", [["Great Britain","GB"], "Germany"], :disabled => 'disabled'] + ]) + ) + end + def test_grouped_options_for_select_with_optional_divider assert_dom_equal( "<optgroup label=\"----------\"><option value=\"US\">US</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"----------\"><option value=\"GB\">GB</option>\n<option value=\"Germany\">Germany</option></optgroup>", diff --git a/actionview/test/template/javascript_helper_test.rb b/actionview/test/template/javascript_helper_test.rb index de6a6eaab3..4703111741 100644 --- a/actionview/test/template/javascript_helper_test.rb +++ b/actionview/test/template/javascript_helper_test.rb @@ -51,6 +51,13 @@ class JavaScriptHelperTest < ActionView::TestCase assert_equal 'foo', output_buffer, 'javascript_tag without a block should not concat to output_buffer' end + # Setting the :extname option will control what extension (if any) is appended to the url for assets + def test_javascript_include_tag + assert_dom_equal "<script src='/foo.js'></script>", javascript_include_tag('/foo') + assert_dom_equal "<script src='/foo'></script>", javascript_include_tag('/foo', extname: false ) + assert_dom_equal "<script src='/foo.bar'></script>", javascript_include_tag('/foo', extname: '.bar' ) + end + def test_javascript_tag_with_options assert_dom_equal "<script id=\"the_js_tag\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", javascript_tag("alert('hello')", :id => "the_js_tag") diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 073bd14783..203ad6d910 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -68,7 +68,7 @@ class LookupContextTest < ActiveSupport::TestCase test "delegates changing the locale to the I18n configuration object if it contains a lookup_context object" do begin - I18n.config = AbstractController::I18nProxy.new(I18n.config, @lookup_context) + I18n.config = ActionView::I18nProxy.new(I18n.config, @lookup_context) @lookup_context.locale = :pt assert_equal :pt, I18n.locale assert_equal :pt, @lookup_context.locale diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 8cffe73cce..928dfb092d 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -41,6 +41,11 @@ module RenderTestCases assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml]) end + def test_rendered_format_without_format + @view.render(:inline => "test") + assert_equal :html, @view.lookup_context.rendered_format + end + def test_render_partial_implicitly_use_format_of_the_rendered_template @view.lookup_context.formats = [:json] assert_equal "Hello world", @view.render(:template => "test/one", :formats => [:html]) diff --git a/actionview/test/template/resolver_patterns_test.rb b/actionview/test/template/resolver_patterns_test.rb index 97b1bad055..575eb9bd28 100644 --- a/actionview/test/template/resolver_patterns_test.rb +++ b/actionview/test/template/resolver_patterns_test.rb @@ -20,7 +20,7 @@ class ResolverPatternsTest < ActiveSupport::TestCase assert_equal [:html], templates.first.formats end - def test_should_return_all_templates_when_ambigous_pattern + def test_should_return_all_templates_when_ambiguous_pattern templates = @resolver.find_all("another", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]}) assert_equal 2, templates.size, "expected two templates" assert_equal "Another template!", templates[0].source diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 1b2234f4e2..c2999fcb85 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -314,6 +314,9 @@ class TextHelperTest < ActionView::TestCase options = { :separator => "\n", :radius => 1 } assert_equal("...very\nvery long\nstring", excerpt("my very\nvery\nvery long\nstring", 'long', options)) + + assert_equal excerpt('This is a beautiful morning', 'a'), + excerpt('This is a beautiful morning', 'a', separator: nil) end def test_word_wrap diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 851ea8796f..e3440915a4 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'abstract_unit' +require 'minitest/mock' class UrlHelperTest < ActiveSupport::TestCase @@ -17,6 +18,7 @@ class UrlHelperTest < ActiveSupport::TestCase get "/" => "foo#bar" get "/other" => "foo#other" get "/article/:id" => "foo#article", :as => :article + get "/category/:category" => "foo#category" end include ActionView::Helpers::UrlHelper @@ -401,6 +403,26 @@ class UrlHelperTest < ActiveSupport::TestCase assert !current_page?('/events') end + def test_current_page_with_escaped_params + @request = request_for_url("/category/administra%c3%a7%c3%a3o") + + assert current_page?(controller: 'foo', action: 'category', category: 'administração') + end + + def test_current_page_with_escaped_params_with_different_encoding + @request = request_for_url("/") + @request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do + assert current_page?(:controller => 'foo', :action => 'category', category: 'administração') + assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o") + end + end + + def test_current_page_with_double_escaped_params + @request = request_for_url("/category/administra%c3%a7%c3%a3o?callback_url=http%3a%2f%2fexample.com%2ffoo") + + assert current_page?(controller: 'foo', action: 'category', category: 'administração', callback_url: 'http://example.com/foo') + end + def test_link_unless_current @request = request_for_url("/") |