From 403b06e98ee88b96b6fbd8692f072fdfa7857639 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 24 Sep 2010 18:42:01 -0700 Subject: Ensure original exception message is present in both Template::Error#message and Template::Error#inspect. Previously, #inspect would produce #, which is not very useful. --- actionpack/test/template/template_error_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 actionpack/test/template/template_error_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/template_error_test.rb b/actionpack/test/template/template_error_test.rb new file mode 100644 index 0000000000..3a874082d9 --- /dev/null +++ b/actionpack/test/template/template_error_test.rb @@ -0,0 +1,13 @@ +require "abstract_unit" + +class TemplateErrorTest < ActiveSupport::TestCase + def test_provides_original_message + error = ActionView::Template::Error.new("test", {}, Exception.new("original")) + assert_equal "original", error.message + end + + def test_provides_useful_inspect + error = ActionView::Template::Error.new("test", {}, Exception.new("original")) + assert_equal "#", error.inspect + end +end -- cgit v1.2.3 From 09195f10bd3add1be1983a42760113ef2bd31602 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 16 Dec 2010 08:12:24 +0100 Subject: Do not use the same hash instance for expansions [#6114 state:resolved] Using the same hash instance makes using the same expansions for both javascripts and stylesheets. --- actionpack/test/template/asset_tag_helper_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index fbcc99a17a..39ecafd072 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -273,6 +273,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') } end + def test_custom_javascript_and_stylesheet_expansion_with_same_name + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :robbery => ["bank", "robber"] + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :robbery => ["money", "security"] + assert_dom_equal %(\n\n\n), javascript_include_tag('controls', :robbery, 'effects') + assert_dom_equal %(\n\n\n), stylesheet_link_tag('style', :robbery, 'print') + end + def test_reset_javascript_expansions JavascriptIncludeTag.expansions.clear assert_raise(ArgumentError) { javascript_include_tag(:defaults) } -- cgit v1.2.3 From 5853583f9b810d7186ad36801b3a97ed49f77799 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 22 Dec 2010 21:36:21 -0200 Subject: Allow registering javascript/stylesheet_expansions to existing symbols --- actionpack/test/template/asset_tag_helper_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 39ecafd072..4b4e13e1a7 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -54,6 +54,9 @@ class AssetTagHelperTest < ActionView::TestCase def teardown config.perform_caching = false ENV.delete('RAILS_ASSET_ID') + + JavascriptIncludeTag.expansions.clear + StylesheetIncludeTag.expansions.clear end AutoDiscoveryToTag = { @@ -268,6 +271,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_dom_equal %(\n\n\n\n\n\n\n\n\n), javascript_include_tag('controls',:defaults, :robbery, 'effects') end + def test_registering_javascript_expansions_merges_with_existing_expansions + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :can_merge => ['bank'] + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :can_merge => ['robber'] + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :can_merge => ['bank'] + assert_dom_equal %(\n), javascript_include_tag(:can_merge) + end + def test_custom_javascript_expansions_with_undefined_symbol ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => nil assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') } @@ -327,6 +338,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_raise(ArgumentError) { stylesheet_link_tag('first', :monkey, 'last') } end + def test_registering_stylesheet_expansions_merges_with_existing_expansions + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :can_merge => ['bank'] + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :can_merge => ['robber'] + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :can_merge => ['bank'] + assert_dom_equal %(\n), stylesheet_link_tag(:can_merge) + end + def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end -- cgit v1.2.3 From 6c5a3bb3125735760e92f49c3824d757ef87c61e Mon Sep 17 00:00:00 2001 From: artemave Date: Sun, 12 Dec 2010 20:40:40 +0000 Subject: all tests pass --- actionpack/test/template/log_subscriber_test.rb | 6 ++-- actionpack/test/template/lookup_context_test.rb | 48 ++++++++++++------------- actionpack/test/template/template_test.rb | 4 +-- 3 files changed, 29 insertions(+), 29 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb index 435936b19f..8b8b005a1d 100644 --- a/actionpack/test/template/log_subscriber_test.rb +++ b/actionpack/test/template/log_subscriber_test.rb @@ -57,7 +57,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase end def test_render_partial_with_implicit_path - @view.stubs(:controller_prefix).returns("test") + @view.stubs(:controller_prefixes).returns(%w(test)) @view.render(Customer.new("david"), :greeting => "hi") wait @@ -74,7 +74,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase end def test_render_collection_with_implicit_path - @view.stubs(:controller_prefix).returns("test") + @view.stubs(:controller_prefixes).returns(%w(test)) @view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi") wait @@ -83,7 +83,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase end def test_render_collection_template_without_path - @view.stubs(:controller_prefix).returns("test") + @view.stubs(:controller_prefixes).returns(%w(test)) @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi") wait diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index c9dd27cf2a..a629b3c046 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -80,18 +80,18 @@ class LookupContextTest < ActiveSupport::TestCase end test "find templates using the given view paths and configured details" do - template = @lookup_context.find("hello_world", "test") + template = @lookup_context.find("hello_world", %w(test)) assert_equal "Hello world!", template.source @lookup_context.locale = :da - template = @lookup_context.find("hello_world", "test") + template = @lookup_context.find("hello_world", %w(test)) assert_equal "Hey verden", template.source end test "found templates respects given formats if one cannot be found from template or handler" do ActionView::Template::Handlers::ERB.expects(:default_format).returns(nil) @lookup_context.formats = [:text] - template = @lookup_context.find("hello_world", "test") + template = @lookup_context.find("hello_world", %w(test)) assert_equal [:text], template.formats end @@ -137,44 +137,44 @@ class LookupContextTest < ActiveSupport::TestCase test "gives the key forward to the resolver, so it can be used as cache key" do @lookup_context.view_paths = ActionView::FixtureResolver.new("test/_foo.erb" => "Foo") - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source # Now we are going to change the template, but it won't change the returned template # since we will hit the cache. @lookup_context.view_paths.first.hash["test/_foo.erb"] = "Bar" - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source # This time we will change the locale. The updated template should be picked since # lookup_context generated a new key after we changed the locale. @lookup_context.locale = :da - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Bar", template.source # Now we will change back the locale and it will still pick the old template. # This is expected because lookup_context will reuse the previous key for :en locale. @lookup_context.locale = :en - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source # Finally, we can expire the cache. And the expected template will be used. @lookup_context.view_paths.first.clear_cache - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Bar", template.source end test "can disable the cache on demand" do @lookup_context.view_paths = ActionView::FixtureResolver.new("test/_foo.erb" => "Foo") - old_template = @lookup_context.find("foo", "test", true) + old_template = @lookup_context.find("foo", %w(test), true) - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal template, old_template assert @lookup_context.cache template = @lookup_context.disable_cache do assert !@lookup_context.cache - @lookup_context.find("foo", "test", true) + @lookup_context.find("foo", %w(test), true) end assert @lookup_context.cache @@ -182,11 +182,11 @@ class LookupContextTest < ActiveSupport::TestCase end test "data can be stored in cached templates" do - template = @lookup_context.find("hello_world", "test") + template = @lookup_context.find("hello_world", %w(test)) template.data["cached"] = "data" assert_equal "Hello world!", template.source - template = @lookup_context.find("hello_world", "test") + template = @lookup_context.find("hello_world", %w(test)) assert_equal "data", template.data["cached"] assert_equal "Hello world!", template.source end @@ -200,54 +200,54 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase end test "templates are always found in the resolver but timestamp is checked before being compiled" do - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source # Now we are going to change the template, but it won't change the returned template # since the timestamp is the same. @resolver.hash["test/_foo.erb"][0] = "Bar" - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source # Now update the timestamp. @resolver.hash["test/_foo.erb"][1] = Time.now.utc - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Bar", template.source end test "if no template was found in the second lookup, with no cache, raise error" do - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source @resolver.hash.clear assert_raise ActionView::MissingTemplate do - @lookup_context.find("foo", "test", true) + @lookup_context.find("foo", %w(test), true) end end test "if no template was cached in the first lookup, retrieval should work in the second call" do @resolver.hash.clear assert_raise ActionView::MissingTemplate do - @lookup_context.find("foo", "test", true) + @lookup_context.find("foo", %w(test), true) end @resolver.hash["test/_foo.erb"] = ["Foo", Time.utc(2000)] - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "Foo", template.source end test "data can be stored as long as template was not updated" do - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) template.data["cached"] = "data" assert_equal "Foo", template.source - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_equal "data", template.data["cached"] assert_equal "Foo", template.source @resolver.hash["test/_foo.erb"][1] = Time.now.utc - template = @lookup_context.find("foo", "test", true) + template = @lookup_context.find("foo", %w(test), true) assert_nil template.data["cached"] assert_equal "Foo", template.source end -end \ No newline at end of file +end diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 2ec640c84c..3432a02c3c 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -95,14 +95,14 @@ class TestERBTemplate < ActiveSupport::TestCase def test_refresh_with_templates @template = new_template("Hello", :virtual_path => "test/foo/bar") @template.locals = [:key] - @context.lookup_context.expects(:find_template).with("bar", "test/foo", false, [:key]).returns("template") + @context.lookup_context.expects(:find_template).with("bar", %w(test/foo), false, [:key]).returns("template") assert_equal "template", @template.refresh(@context) end def test_refresh_with_partials @template = new_template("Hello", :virtual_path => "test/_foo") @template.locals = [:key] - @context.lookup_context.expects(:find_template).with("foo", "test", true, [:key]).returns("partial") + @context.lookup_context.expects(:find_template).with("foo", %w(test), true, [:key]).returns("partial") assert_equal "partial", @template.refresh(@context) end -- cgit v1.2.3 From e5b84fd72358deddd29c515aacab7edf2643908e Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Wed, 24 Nov 2010 00:17:05 +0300 Subject: ActionController::Base.helpers.sanitize ignores case in protocol [#6044 state:committed] Signed-off-by: Santiago Pastorino --- actionpack/test/template/html-scanner/sanitizer_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/html-scanner/sanitizer_test.rb b/actionpack/test/template/html-scanner/sanitizer_test.rb index 3e80317b30..fcc3782f04 100644 --- a/actionpack/test/template/html-scanner/sanitizer_test.rb +++ b/actionpack/test/template/html-scanner/sanitizer_test.rb @@ -130,6 +130,13 @@ class SanitizerTest < ActionController::TestCase assert sanitizer.send(:contains_bad_protocols?, 'src', "#{proto}://bad") end end + + def test_should_accept_good_protocols_ignoring_case + sanitizer = HTML::WhiteListSanitizer.new + HTML::WhiteListSanitizer.allowed_protocols.each do |proto| + assert !sanitizer.send(:contains_bad_protocols?, 'src', "#{proto.capitalize}://good") + end + end def test_should_accept_good_protocols sanitizer = HTML::WhiteListSanitizer.new -- cgit v1.2.3 From 4c44f0468a0b6d2dd9b67d801da4336ad9a169a0 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 30 Dec 2010 14:11:14 +0100 Subject: added tests for the MissingTemplate exception message. --- actionpack/test/template/lookup_context_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index a629b3c046..4258f88071 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -251,3 +251,24 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase assert_equal "Foo", template.source end end + +class TestMissingTemplate < ActiveSupport::TestCase + def setup + @lookup_context = ActionView::LookupContext.new("/Path/to/views", {}) + @details = "{:handlers=>[:erb, :rjs, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]}" + end + + test "if no template was found we get a helpful error message including the inheritance chain" do + e = assert_raise ActionView::MissingTemplate do + @lookup_context.find("foo", %w(parent child)) + end + assert_equal "Missing template parent/foo, child/foo with #{@details}. Searched in:\n * \"/Path/to/views\"\n", e.message + end + + test "if no partial was found we get a helpful error message including the inheritance chain" do + e = assert_raise ActionView::MissingTemplate do + @lookup_context.find("foo", %w(parent child), true) + end + assert_equal "Missing partial parent/foo, child/foo with #{@details}. Searched in:\n * \"/Path/to/views\"\n", e.message + end +end -- cgit v1.2.3 From 8e5d91062f25f8c97a3bd8c6dc7dc45e38b54388 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 31 Dec 2010 11:17:37 +0100 Subject: Don't be so picky on MissingTemplate error details, this fails randomly on 1.8.7 because of not ordered hash --- actionpack/test/template/lookup_context_test.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index 4258f88071..f7a684779c 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -255,20 +255,19 @@ end class TestMissingTemplate < ActiveSupport::TestCase def setup @lookup_context = ActionView::LookupContext.new("/Path/to/views", {}) - @details = "{:handlers=>[:erb, :rjs, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]}" end test "if no template was found we get a helpful error message including the inheritance chain" do e = assert_raise ActionView::MissingTemplate do @lookup_context.find("foo", %w(parent child)) end - assert_equal "Missing template parent/foo, child/foo with #{@details}. Searched in:\n * \"/Path/to/views\"\n", e.message + assert_match %r{Missing template parent/foo, child/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message end - + test "if no partial was found we get a helpful error message including the inheritance chain" do e = assert_raise ActionView::MissingTemplate do @lookup_context.find("foo", %w(parent child), true) end - assert_equal "Missing partial parent/foo, child/foo with #{@details}. Searched in:\n * \"/Path/to/views\"\n", e.message + assert_match %r{Missing partial parent/foo, child/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message end end -- cgit v1.2.3 From 18605adec36f8487374d68cdb031e89e91379c56 Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Thu, 23 Dec 2010 22:43:46 +0330 Subject: HTML5 button_tag helper This tag is similar in nature to submit_tag, but allows more control. It also doesn't submit if submit type isn't used, allowing JavaScript to control the flow where required. For more information: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-button-element --- actionpack/test/template/form_tag_helper_test.rb | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index f3933a25b9..0d29b962d5 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -385,6 +385,34 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_button_tag + assert_dom_equal( + %(), + button_tag + ) + end + + def test_button_tag_with_submit_type + assert_dom_equal( + %(), + button_tag("Save", :type => "submit") + ) + end + + def test_button_tag_with_reset_type + assert_dom_equal( + %(), + button_tag("Reset", :type => "reset") + ) + end + + def test_button_tag_with_disabled_option + assert_dom_equal( + %(), + button_tag("Reset", :type => "reset", :disabled => true) + ) + end + def test_image_submit_tag_with_confirmation assert_dom_equal( %(), -- cgit v1.2.3 From 5d1d9bfb05dd84305369a8fc5a729d2b8ad912e2 Mon Sep 17 00:00:00 2001 From: John Allison Date: Wed, 5 Jan 2011 14:15:10 -0500 Subject: Improve select helpers by allowing a selected value of false. This is useful when using a select helper with a boolean attribute, and the attribute is false. (e.g. f.select :allow_comments) --- .../test/template/form_options_helper_test.rb | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index bc04398afa..69b1d4ff7b 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -7,7 +7,7 @@ class FormOptionsHelperTest < ActionView::TestCase tests ActionView::Helpers::FormOptionsHelper silence_warnings do - Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin) + Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin, :allow_comments) Continent = Struct.new('Continent', :continent_name, :countries) Country = Struct.new('Country', :country_id, :country_name) Firm = Struct.new('Firm', :time_zone) @@ -130,6 +130,13 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_boolean_array_options_for_select_with_selection_and_disabled_value + assert_dom_equal( + "\n", + options_for_select([ true, false ], :selected => false, :disabled => nil) + ) + end + def test_array_options_for_string_include_in_other_string_bug_fix assert_dom_equal( "\n", @@ -177,7 +184,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_preselected_value_as_string_and_option_value_is_integer - albums = [ Album.new(1, "first","rap"), Album.new(2, "second","pop")] + albums = [ Album.new(1, "first","rap"), Album.new(2, "second","pop")] assert_dom_equal( %(\n), options_from_collection_for_select(albums, "id", "genre", :selected => "1") @@ -185,7 +192,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_preselected_value_as_integer_and_option_value_is_string - albums = [ Album.new("1", "first","rap"), Album.new("2", "second","pop")] + albums = [ Album.new("1", "first","rap"), Album.new("2", "second","pop")] assert_dom_equal( %(\n), @@ -194,7 +201,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_preselected_value_as_string_and_option_value_is_float - albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] + albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] assert_dom_equal( %(\n), @@ -203,7 +210,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_preselected_value_as_nil - albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] + albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] assert_dom_equal( %(\n), @@ -212,7 +219,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_disabled_value_as_nil - albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] + albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] assert_dom_equal( %(\n), @@ -221,7 +228,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_disabled_value_as_array - albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] + albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop")] assert_dom_equal( %(\n), @@ -230,7 +237,7 @@ class FormOptionsHelperTest < ActionView::TestCase end def test_collection_options_with_preselected_values_as_string_array_and_option_value_is_float - albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop"), Album.new(3.0, "third","country") ] + albums = [ Album.new(1.0, "first","rap"), Album.new(2.0, "second","pop"), Album.new(3.0, "third","country") ] assert_dom_equal( %(\n\n), @@ -364,6 +371,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_boolean_method + @post = Post.new + @post.allow_comments = false + assert_dom_equal( + "", + select("post", "allow_comments", %w( true false )) + ) + end + def test_select_under_fields_for @post = Post.new @post.category = "" -- cgit v1.2.3 From 6062d434f174c84a18a121b025dcf4f11d6689f1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 Jan 2011 12:14:00 -0200 Subject: Allow view in AV::TestCase to access it's controller helpers methods --- actionpack/test/template/test_case_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index a745999622..203515d508 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -116,6 +116,27 @@ module ActionView end end + class ControllerHelperMethod < ActionView::TestCase + module SomeHelper + def some_method + render :partial => 'test/from_helper' + end + end + + helper SomeHelper + + test "can call a helper method defined on the current controller from a helper" do + @controller.singleton_class.class_eval <<-EOF, __FILE__, __LINE__ + 1 + def render_from_helper + 'controller_helper_method' + end + EOF + @controller.class.helper_method :render_from_helper + + assert_equal 'controller_helper_method', some_method + end + end + class AssignsTest < ActionView::TestCase setup do ActiveSupport::Deprecation.stubs(:warn) -- cgit v1.2.3 From 1de47a0d56328768dfba0e5f86e1ff9491e62c20 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 Jan 2011 22:05:52 -0200 Subject: button_tag should escape it content --- actionpack/test/template/form_tag_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 0d29b962d5..4a584b8db8 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -413,6 +413,13 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_button_tag_escape_content + assert_dom_equal( + %(), + button_tag("Reset", :type => "reset", :disabled => true) + ) + end + def test_image_submit_tag_with_confirmation assert_dom_equal( %(), -- cgit v1.2.3 From 1333020448e8b39cbf98b0292a9be9d3f8a14376 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Jan 2011 14:45:24 -0800 Subject: fixing space errors --- actionpack/test/template/test_case_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 203515d508..11c355dc6d 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -167,7 +167,7 @@ module ActionView end end end - + class HelperExposureTest < ActionView::TestCase helper(Module.new do def render_from_helper -- cgit v1.2.3 From 262b2ea8cda20999ddf8c4bf13b7a70453e996d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 19 Jan 2011 23:42:10 +0100 Subject: Solve SystemStackError when changing locale inside ActionMailer [#5329 state:resolved] --- actionpack/test/template/lookup_context_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index f7a684779c..f3b1335000 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -73,7 +73,7 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal :pt, I18n.locale assert_equal :pt, @lookup_context.locale ensure - I18n.config = I18n.config.i18n_config + I18n.config = I18n.config.original_config end assert_equal :pt, I18n.locale -- cgit v1.2.3 From 5dd803e9b1149f8e6d7de787e0c833c94f48d5a4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 25 Dec 2010 23:54:34 +0900 Subject: Accept String value for render_partial :as option [#6222 state:committed] Signed-off-by: Santiago Pastorino --- actionpack/test/template/render_test.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 38bedd2e4e..e02d69231f 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -146,7 +146,12 @@ module RenderTestCases assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) end - def test_render_partial_collection_as + def test_render_partial_collection_as_by_string + assert_equal "david david davidmary mary mary", + @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => 'customer') + end + + def test_render_partial_collection_as_by_symbol assert_equal "david david davidmary mary mary", @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer) end -- cgit v1.2.3 From cb9fa5283239e649483ea31ca372e99aaac2ca07 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 31 Aug 2010 04:58:54 +0900 Subject: auto_link: avoid recognizing full width chars as a part of URI scheme fixes regression by http://github.com/rails/rails/commit/133ada6ab0f0cb7bef2bd40dbc18f2d5bc6b964e [#5503 state:committed] Signed-off-by: Santiago Pastorino --- actionpack/test/template/text_helper_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 9e9ed9120d..d0d4286393 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -1,4 +1,4 @@ -# encoding: us-ascii +# encoding: utf-8 require 'abstract_unit' require 'testing_sandbox' @@ -415,6 +415,12 @@ class TextHelperTest < ActionView::TestCase link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/' link10_result = generate_result(link10_raw) assert_equal %(

#{link10_result} Link

), auto_link("

#{link10_raw} Link

") + + link11_raw = 'http://asakusa.rubyist.net/' + link11_result = generate_result(link11_raw) + with_kcode 'u' do + assert_equal %(浅草.rbの公式サイトはこちら#{link11_result}), auto_link("浅草.rbの公式サイトはこちら#{link11_raw}") + end end def test_auto_link_should_sanitize_input_when_sanitize_option_is_not_false -- cgit v1.2.3 From 15ad707852159f405e5f6dc61581cb9dbb2864c7 Mon Sep 17 00:00:00 2001 From: Andrei Bocan Date: Fri, 19 Nov 2010 20:25:21 +0200 Subject: Allow customization of form class for button_to Signed-off-by: Santiago Pastorino --- actionpack/test/template/url_helper_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 4a8cea36d4..42232316e8 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -50,6 +50,10 @@ class UrlHelperTest < ActiveSupport::TestCase assert_dom_equal "
", button_to("Hello", "http://www.example.com") end + def test_button_to_with_form_class + assert_dom_equal "
", button_to("Hello", "http://www.example.com", :form_class => 'custom-class') + end + def test_button_to_with_query assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") end -- cgit v1.2.3 From 86dc5987b23047f8c3345552341c15dd0e5e245d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 1 Feb 2011 19:17:13 -0200 Subject: add test to check class is being escaped in form_class --- actionpack/test/template/url_helper_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 42232316e8..2e1661a0ac 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -54,6 +54,10 @@ class UrlHelperTest < ActiveSupport::TestCase assert_dom_equal "
", button_to("Hello", "http://www.example.com", :form_class => 'custom-class') end + def test_button_to_with_form_class_escapes + assert_dom_equal "
", button_to("Hello", "http://www.example.com", :form_class => '') + end + def test_button_to_with_query assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") end -- cgit v1.2.3 From c1c6f29214d3c280f5d1d4abb49d0b90424fcbd7 Mon Sep 17 00:00:00 2001 From: Anton Astashov Date: Thu, 3 Feb 2011 19:09:21 +0700 Subject: Add a test for 'render :layout' To make sure it will show block contents if it is placed after 'render :partial' [#5557 state:resolved] Signed-off-by: Santiago Pastorino --- actionpack/test/template/render_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index e02d69231f..034fb6c210 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -209,6 +209,11 @@ module RenderTestCases @view.formats = nil end + def test_render_layout_with_block_and_other_partial_inside + render = @view.render(:layout => "test/layout_with_partial_and_yield.html.erb") { "Yield!" } + assert_equal "Before\npartial html\nYield!\nAfter\n", render + end + def test_render_inline assert_equal "Hello, World!", @view.render(:inline => "Hello, World!") end -- cgit v1.2.3 From d3cfee118245a8806436bbf904bbad36dd810012 Mon Sep 17 00:00:00 2001 From: Franco Brusatti Date: Thu, 3 Feb 2011 19:14:10 -0300 Subject: removing generation of id in submit helper [#6369 state:committed] Signed-off-by: Santiago Pastorino --- actionpack/test/template/form_helper_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 2c60096475..e27ed20b81 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -630,7 +630,7 @@ class FormHelperTest < ActionView::TestCase "" + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -709,7 +709,7 @@ class FormHelperTest < ActionView::TestCase "" + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -843,7 +843,7 @@ class FormHelperTest < ActionView::TestCase end expected = whole_form('/posts', 'new_post', 'new_post') do - "" + "" end assert_dom_equal expected, output_buffer @@ -859,7 +859,7 @@ class FormHelperTest < ActionView::TestCase end expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do - "" + "" end assert_dom_equal expected, output_buffer @@ -875,7 +875,7 @@ class FormHelperTest < ActionView::TestCase end expected = whole_form do - "" + "" end assert_dom_equal expected, output_buffer @@ -891,7 +891,7 @@ class FormHelperTest < ActionView::TestCase end expected = whole_form('/posts/123', 'another_post_edit', 'another_post_edit', :method => 'put') do - "" + "" end assert_dom_equal expected, output_buffer -- cgit v1.2.3 From 631e23ec6c1e482abcc242ae1d772a1831288465 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 8 Feb 2011 01:00:59 -0200 Subject: Add tests showing the LH issue #6381: fields_for with inline blocks and nested attributes already persisted Signed-off-by: Santiago Pastorino --- actionpack/test/template/form_helper_test.rb | 86 +++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index e27ed20b81..b3220d6aa6 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -731,7 +731,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - + def test_form_for_with_search_field # Test case for bug which would emit an "object" attribute # when used with form_for using a search_field form helper @@ -1084,6 +1084,44 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_using_erb_and_inline_block + @post.author = Author.new(321) + + form_for(@post) do |f| + concat f.text_field(:title) + concat f.fields_for(:author) { |af| + af.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '' + + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_using_erb_and_multiline_block + @post.author = Author.new(321) + + form_for(@post) do |f| + concat f.text_field(:title) + concat f.fields_for(:author) { |af| + concat af.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '' + + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement @post.author = Author.new(321) @@ -1127,6 +1165,52 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_using_erb_and_inline_block + @post.comments = Array.new(2) { |id| Comment.new(id + 1) } + + form_for(@post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + cf.text_field(:name) + } + end + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '' + + '' + + '' + + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_using_erb_and_multiline_block + @post.comments = Array.new(2) { |id| Comment.new(id + 1) } + + form_for(@post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + concat f.fields_for(:comments, comment) { |cf| + concat cf.text_field(:name) + } + end + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '' + + '' + + '' + + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_explicit_hidden_field_placement @post.comments = Array.new(2) { |id| Comment.new(id + 1) } -- cgit v1.2.3 From 3ddd7f7ec9b156e4b7de4c23d448c2db98f30504 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Tue, 7 Dec 2010 16:27:55 +1300 Subject: Be sure to javascript_escape the email address to prevent apostrophes inadvertently causing javascript errors. This fixes CVE-2011-0446 --- actionpack/test/template/url_helper_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 2e1661a0ac..fc330f7a73 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -20,6 +20,7 @@ class UrlHelperTest < ActiveSupport::TestCase include routes.url_helpers include ActionView::Helpers::UrlHelper + include ActionView::Helpers::JavaScriptHelper include ActionDispatch::Assertions::DomAssertions include ActionView::Context include RenderERBUtils @@ -367,13 +368,13 @@ class UrlHelperTest < ActiveSupport::TestCase def test_mail_to_with_javascript snippet = mail_to("me@domain.com", "My email", :encode => "javascript") - assert_dom_equal "", snippet + assert_dom_equal "", snippet assert snippet.html_safe? end def test_mail_to_with_javascript_unicode snippet = mail_to("unicode@example.com", "únicode", :encode => "javascript") - assert_dom_equal "", snippet + assert_dom_equal "", snippet assert snippet.html_safe end @@ -399,8 +400,8 @@ class UrlHelperTest < ActiveSupport::TestCase assert_dom_equal "me(at)domain.com", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)") assert_dom_equal "My email", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)") assert_dom_equal "me(at)domain(dot)com", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)") - assert_dom_equal "", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") - assert_dom_equal "", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") + assert_dom_equal "", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") + assert_dom_equal "", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") end # TODO: button_to looks at this ... why? -- cgit v1.2.3 From 6b1018526fb304727ee4191afc2d8a5e29e49eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 28 Nov 2010 22:40:32 +0100 Subject: Use Mime::Type references. --- actionpack/test/template/lookup_context_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index f3b1335000..8d063e66b0 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -47,7 +47,7 @@ class LookupContextTest < ActiveSupport::TestCase end test "handles */* formats" do - @lookup_context.formats = [:"*/*"] + @lookup_context.formats = ["*/*"] assert_equal Mime::SET, @lookup_context.formats end -- cgit v1.2.3 From 98c0c5db50a7679b3d58769ac22cb0a27a62c930 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 10 Feb 2011 23:01:02 +0800 Subject: Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same. --- .../test/template/output_safety_helper_test.rb | 55 ++++++++++++++++++++++ actionpack/test/template/raw_output_helper_test.rb | 21 --------- 2 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 actionpack/test/template/output_safety_helper_test.rb delete mode 100644 actionpack/test/template/raw_output_helper_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/output_safety_helper_test.rb b/actionpack/test/template/output_safety_helper_test.rb new file mode 100644 index 0000000000..3c52b63d40 --- /dev/null +++ b/actionpack/test/template/output_safety_helper_test.rb @@ -0,0 +1,55 @@ +require 'abstract_unit' +require 'testing_sandbox' + +class OutputSafetyHelperTest < ActionView::TestCase + tests ActionView::Helpers::OutputSafetyHelper + include TestingSandbox + + def setup + @string = "hello" + end + + test "raw returns the safe string" do + result = raw(@string) + assert_equal @string, result + assert result.html_safe? + end + + test "raw handles nil values correctly" do + assert_equal "", raw(nil) + end + + test "joining safe elements without a separator is safe" do + array = 5.times.collect { "some string".html_safe } + assert safe_join(array).html_safe? + end + + test "Joining safe elements with a safe separator is safe" do + array = 5.times.collect { "some string".html_safe } + assert safe_join(array, "-".html_safe).html_safe? + end + + test "Joining safe elements with an unsafe separator is unsafe" do + array = 5.times.collect { "some string".html_safe } + assert !safe_join(array, "-").html_safe? + end + + test "Joining is unsafe if any element is unsafe even with a safe separator" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !safe_join(array, "-".html_safe).html_safe? + end + + test "Joining is unsafe if any element is unsafe and no separator is given" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !safe_join(array).html_safe? + end + + test "Joining is unsafe if any element is unsafe and the separator is unsafe" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !safe_join(array, "-").html_safe? + end + +end \ No newline at end of file diff --git a/actionpack/test/template/raw_output_helper_test.rb b/actionpack/test/template/raw_output_helper_test.rb deleted file mode 100644 index 598aa5b1d8..0000000000 --- a/actionpack/test/template/raw_output_helper_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'abstract_unit' -require 'testing_sandbox' - -class RawOutputHelperTest < ActionView::TestCase - tests ActionView::Helpers::RawOutputHelper - include TestingSandbox - - def setup - @string = "hello" - end - - test "raw returns the safe string" do - result = raw(@string) - assert_equal @string, result - assert result.html_safe? - end - - test "raw handles nil values correctly" do - assert_equal "", raw(nil) - end -end \ No newline at end of file -- cgit v1.2.3 From 89a5f1463d7e9546ed7a0cf482afea99ba2040e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Feb 2011 16:50:35 +0100 Subject: Revert "Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same." Applied the wrong version. This reverts commit 98c0c5db50a7679b3d58769ac22cb0a27a62c930. --- .../test/template/output_safety_helper_test.rb | 55 ---------------------- actionpack/test/template/raw_output_helper_test.rb | 21 +++++++++ 2 files changed, 21 insertions(+), 55 deletions(-) delete mode 100644 actionpack/test/template/output_safety_helper_test.rb create mode 100644 actionpack/test/template/raw_output_helper_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/output_safety_helper_test.rb b/actionpack/test/template/output_safety_helper_test.rb deleted file mode 100644 index 3c52b63d40..0000000000 --- a/actionpack/test/template/output_safety_helper_test.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'abstract_unit' -require 'testing_sandbox' - -class OutputSafetyHelperTest < ActionView::TestCase - tests ActionView::Helpers::OutputSafetyHelper - include TestingSandbox - - def setup - @string = "hello" - end - - test "raw returns the safe string" do - result = raw(@string) - assert_equal @string, result - assert result.html_safe? - end - - test "raw handles nil values correctly" do - assert_equal "", raw(nil) - end - - test "joining safe elements without a separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert safe_join(array).html_safe? - end - - test "Joining safe elements with a safe separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert safe_join(array, "-".html_safe).html_safe? - end - - test "Joining safe elements with an unsafe separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - assert !safe_join(array, "-").html_safe? - end - - test "Joining is unsafe if any element is unsafe even with a safe separator" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !safe_join(array, "-".html_safe).html_safe? - end - - test "Joining is unsafe if any element is unsafe and no separator is given" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !safe_join(array).html_safe? - end - - test "Joining is unsafe if any element is unsafe and the separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !safe_join(array, "-").html_safe? - end - -end \ No newline at end of file diff --git a/actionpack/test/template/raw_output_helper_test.rb b/actionpack/test/template/raw_output_helper_test.rb new file mode 100644 index 0000000000..598aa5b1d8 --- /dev/null +++ b/actionpack/test/template/raw_output_helper_test.rb @@ -0,0 +1,21 @@ +require 'abstract_unit' +require 'testing_sandbox' + +class RawOutputHelperTest < ActionView::TestCase + tests ActionView::Helpers::RawOutputHelper + include TestingSandbox + + def setup + @string = "hello" + end + + test "raw returns the safe string" do + result = raw(@string) + assert_equal @string, result + assert result.html_safe? + end + + test "raw handles nil values correctly" do + assert_equal "", raw(nil) + end +end \ No newline at end of file -- cgit v1.2.3 From 1814298d7590988d354955efdb0bc495b359293b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 10 Feb 2011 16:45:39 +0100 Subject: Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same. This also changes how safe_join works, if items or the separator are not html_safe they are html_escape'd, a html_safe string is always returned. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../test/template/output_safety_helper_test.rb | 30 ++++++++++++++++++++++ actionpack/test/template/raw_output_helper_test.rb | 21 --------------- 2 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 actionpack/test/template/output_safety_helper_test.rb delete mode 100644 actionpack/test/template/raw_output_helper_test.rb (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/output_safety_helper_test.rb b/actionpack/test/template/output_safety_helper_test.rb new file mode 100644 index 0000000000..fc127c24e9 --- /dev/null +++ b/actionpack/test/template/output_safety_helper_test.rb @@ -0,0 +1,30 @@ +require 'abstract_unit' +require 'testing_sandbox' + +class OutputSafetyHelperTest < ActionView::TestCase + tests ActionView::Helpers::OutputSafetyHelper + include TestingSandbox + + def setup + @string = "hello" + end + + test "raw returns the safe string" do + result = raw(@string) + assert_equal @string, result + assert result.html_safe? + end + + test "raw handles nil values correctly" do + assert_equal "", raw(nil) + end + + test "safe_join should html_escape any items, including the separator, if they are not html_safe" do + joined = safe_join(["

foo

".html_safe, "

bar

"], "
") + assert_equal "

foo

<br /><p>bar</p>", joined + + joined = safe_join(["

foo

".html_safe, "

bar

".html_safe], "
".html_safe) + assert_equal "

foo


bar

", joined + end + +end \ No newline at end of file diff --git a/actionpack/test/template/raw_output_helper_test.rb b/actionpack/test/template/raw_output_helper_test.rb deleted file mode 100644 index 598aa5b1d8..0000000000 --- a/actionpack/test/template/raw_output_helper_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'abstract_unit' -require 'testing_sandbox' - -class RawOutputHelperTest < ActionView::TestCase - tests ActionView::Helpers::RawOutputHelper - include TestingSandbox - - def setup - @string = "hello" - end - - test "raw returns the safe string" do - result = raw(@string) - assert_equal @string, result - assert result.html_safe? - end - - test "raw handles nil values correctly" do - assert_equal "", raw(nil) - end -end \ No newline at end of file -- cgit v1.2.3 From 03749d6c88ae8312dc959b7683851dbf8c969326 Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Sat, 12 Feb 2011 11:34:49 +0000 Subject: Make type="submit" the default for button_tag helper "submit" is the default value of the ), + %(), button_tag ) end @@ -399,6 +399,13 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_button_tag_with_button_type + assert_dom_equal( + %(), + button_tag("Button", :type => "button") + ) + end + def test_button_tag_with_reset_type assert_dom_equal( %(), -- cgit v1.2.3 From 829de9d98e59f9b083ed96a9031cd9841c83ae47 Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Sat, 12 Feb 2011 12:07:47 +0000 Subject: Add block support to button_tag helper As per the HTML 4.01 spec: Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to "image", but the BUTTON element type allows content. Since rich content is the main purpose of the ', button_tag { 'Content' }) + end + + def test_button_tag_with_block_and_options + output = button_tag(:name => 'temptation', :type => 'button') { content_tag(:strong, 'Do not press me') } + assert_dom_equal('', output) + end + def test_image_submit_tag_with_confirmation assert_dom_equal( %(), -- cgit v1.2.3 From ad5b4d980aec128e028b721156aa4433199e30ab Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 12 Feb 2011 14:45:58 -0200 Subject: Remove duplicated action pack tests added to fix issue with fields_for, nested attributes and erb Signed-off-by: Santiago Pastorino --- actionpack/test/template/form_helper_test.rb | 42 ---------------------------- 1 file changed, 42 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b3220d6aa6..31da26de7f 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1103,25 +1103,6 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_using_erb_and_multiline_block - @post.author = Author.new(321) - - form_for(@post) do |f| - concat f.text_field(:title) - concat f.fields_for(:author) { |af| - concat af.text_field(:name) - } - end - - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do - '' + - '' + - '' - end - - assert_dom_equal expected, output_buffer - end - def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement @post.author = Author.new(321) @@ -1188,29 +1169,6 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_using_erb_and_multiline_block - @post.comments = Array.new(2) { |id| Comment.new(id + 1) } - - form_for(@post) do |f| - concat f.text_field(:title) - @post.comments.each do |comment| - concat f.fields_for(:comments, comment) { |cf| - concat cf.text_field(:name) - } - end - end - - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do - '' + - '' + - '' + - '' + - '' - end - - assert_dom_equal expected, output_buffer - end - def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_explicit_hidden_field_placement @post.comments = Array.new(2) { |id| Comment.new(id + 1) } -- cgit v1.2.3 From 1363bb8f7215fadb65e9296217be2ae96e82dd7e Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Feb 2011 05:00:30 +0800 Subject: This corrects two issues with javascript_include_tag, the order at which they are expanded, and removing duplicates. When individual js assets are specified, they will override the order of the same asset specified in an expansion. [#5938 state:resolved] --- actionpack/test/template/asset_tag_helper_test.rb | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 4b4e13e1a7..49e47a2aed 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -95,6 +95,7 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n\n), %(javascript_include_tag(:all, :recursive => true)) => %(\n\n\n\n\n\n\n\n), %(javascript_include_tag(:defaults, "bank")) => %(\n\n\n\n\n\n), + %(javascript_include_tag(:defaults, "application")) => %(\n\n\n\n\n), %(javascript_include_tag("bank", :defaults)) => %(\n\n\n\n\n\n), %(javascript_include_tag("http://example.com/all")) => %(), @@ -265,10 +266,32 @@ class AssetTagHelperTest < ActionView::TestCase assert_dom_equal %(\n\n\n), javascript_include_tag('controls', :robbery, 'effects') end + def test_custom_javascript_expansions_return_unique_set + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_javascript_expansion :defaults => %w(prototype effects dragdrop controls rails application) + assert_dom_equal %(\n\n\n\n\n), javascript_include_tag(:defaults) + end + def test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end ENV["RAILS_ASSET_ID"] = "" ActionView::Helpers::AssetTagHelper::register_javascript_expansion :robbery => ["bank", "robber"] - assert_dom_equal %(\n\n\n\n\n\n\n\n\n), javascript_include_tag('controls',:defaults, :robbery, 'effects') + assert_dom_equal %(\n\n\n\n\n\n\n), javascript_include_tag('controls',:defaults, :robbery, 'effects') + end + + def test_javascript_include_tag_should_not_output_the_same_asset_twice + ENV["RAILS_ASSET_ID"] = "" + assert_dom_equal %(\n\n\n\n\n), javascript_include_tag('prototype', 'effects', :defaults) + end + + def test_javascript_include_tag_should_not_output_the_same_expansion_twice + ENV["RAILS_ASSET_ID"] = "" + assert_dom_equal %(\n\n\n\n\n), javascript_include_tag(:defaults, :defaults) + end + + def test_single_javascript_asset_keys_should_take_precedence_over_expansions + ENV["RAILS_ASSET_ID"] = "" + assert_dom_equal %(\n\n\n\n\n), javascript_include_tag('controls', :defaults, 'effects') + assert_dom_equal %(\n\n\n\n\n), javascript_include_tag('controls', 'effects', :defaults) end def test_registering_javascript_expansions_merges_with_existing_expansions -- cgit v1.2.3 From e2b99eb1a77b1b2d8c1ede5239a2f72ef0898cd0 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Feb 2011 05:39:27 +0800 Subject: Applied changes to stylesheet_link_tag from javascript_include_tag which corrects issues with ordering and duplicates. --- actionpack/test/template/asset_tag_helper_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 49e47a2aed..a1a6b5f1d0 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -356,6 +356,29 @@ class AssetTagHelperTest < ActionView::TestCase assert_dom_equal %(\n\n\n), stylesheet_link_tag('version.1.0', :robbery, 'subdir/subdir') end + def test_custom_stylesheet_expansions_return_unique_set + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :cities => %w(wellington amsterdam london) + assert_dom_equal %(\n\n), stylesheet_link_tag(:cities) + end + + def test_stylesheet_link_tag_should_not_output_the_same_asset_twice + ENV["RAILS_ASSET_ID"] = "" + assert_dom_equal %(\n), stylesheet_link_tag('wellington', 'wellington', 'amsterdam') + end + + def test_stylesheet_link_tag_should_not_output_the_same_expansion_twice + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :cities => %w(wellington amsterdam london) + assert_dom_equal %(\n\n), stylesheet_link_tag(:cities, :cities) + end + + def test_single_stylesheet_asset_keys_should_take_precedence_over_expansions + ENV["RAILS_ASSET_ID"] = "" + ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :cities => %w(wellington amsterdam london) + assert_dom_equal %(\n\n), stylesheet_link_tag('london', :cities) + end + def test_custom_stylesheet_expansions_with_undefined_symbol ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => nil assert_raise(ArgumentError) { stylesheet_link_tag('first', :monkey, 'last') } -- cgit v1.2.3 From 95a5bd87cb542c534b7f2490dcfa687a1bfeec43 Mon Sep 17 00:00:00 2001 From: Sjoerd Andringa Date: Sun, 13 Feb 2011 00:56:04 +0100 Subject: Added time_tag helper to AP for HTML5 time tag [#5919 state:resolved] Signed-off-by: Santiago Pastorino --- actionpack/test/template/date_helper_test.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 55c384e68f..bb72185595 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -2699,7 +2699,27 @@ class DateHelperTest < ActionView::TestCase assert date_select("post", "written_on", :default => Time.local(2006, 9, 19, 15, 16, 35), :include_blank => true).html_safe? assert time_select("post", "written_on", :ignore_date => true).html_safe? end - + + def test_time_tag_with_date + date = Date.today + expected = "" + assert_equal expected, time_tag(date) + end + + def test_time_tag_with_time + time = Time.now + expected = "" + assert_equal expected, time_tag(time) + end + + def test_time_tag_pubdate_option + assert_match /.*<\/time>/, time_tag(Time.now, :pubdate => true) + end + + def test_time_tag_with_given_text + assert_match /Right now<\/time>/, time_tag(Time.now, 'Right now') + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz -- cgit v1.2.3 From 33cc36678b7ff5ac84407df17475e1b3ffc9a2d8 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Feb 2011 01:13:03 +0100 Subject: Allow for the format of time_tag in AP to be changed via an option argument. Signed-off-by: Santiago Pastorino --- actionpack/test/template/date_helper_test.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index bb72185595..3334f4ffb0 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -2699,27 +2699,33 @@ class DateHelperTest < ActionView::TestCase assert date_select("post", "written_on", :default => Time.local(2006, 9, 19, 15, 16, 35), :include_blank => true).html_safe? assert time_select("post", "written_on", :ignore_date => true).html_safe? end - + def test_time_tag_with_date date = Date.today expected = "" assert_equal expected, time_tag(date) end - + def test_time_tag_with_time time = Time.now expected = "" assert_equal expected, time_tag(time) end - + def test_time_tag_pubdate_option assert_match /.*<\/time>/, time_tag(Time.now, :pubdate => true) end - + def test_time_tag_with_given_text assert_match /Right now<\/time>/, time_tag(Time.now, 'Right now') end - + + def test_time_tag_with_different_format + time = Time.now + expected = "" + assert_equal expected, time_tag(time, :format => :short) + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz -- cgit v1.2.3