From ed9567401dfc7b476bf9ccac82826fc63283f708 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 8 Oct 2012 22:22:47 +0200 Subject: recognizes when a partial was rendered twice. Closes #3675 --- actionpack/test/fixtures/test/render_two_partials.html.erb | 2 ++ actionpack/test/template/test_case_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 actionpack/test/fixtures/test/render_two_partials.html.erb (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/test/render_two_partials.html.erb b/actionpack/test/fixtures/test/render_two_partials.html.erb new file mode 100644 index 0000000000..3db6025860 --- /dev/null +++ b/actionpack/test/fixtures/test/render_two_partials.html.erb @@ -0,0 +1,2 @@ +<%= render :partial => 'partial', :locals => {'first' => '1'} %> +<%= render :partial => 'partial', :locals => {'second' => '2'} %> diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 5265ae6b3a..c7231d9cd5 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -321,6 +321,14 @@ module ActionView assert_template :partial => "_partial_for_use_in_layout", :locals => { :name => "Somebody Else" } end end + + test 'supports different locals on the same partial' do + controller.controller_path = "test" + render(:template => "test/render_two_partials") + assert_template partial: '_partial', locals: { 'first' => '1' } + assert_template partial: '_partial', locals: { 'second' => '2' } + end + end module AHelperWithInitialize -- cgit v1.2.3 From 2938ef7a65be5527905174b348b58c98a06d20e4 Mon Sep 17 00:00:00 2001 From: Andy Shipman Date: Thu, 11 Oct 2012 17:36:58 +0100 Subject: Allow for deep directory path for view templates. --- actionpack/test/fixtures/digestor/level/below/_header.html.erb | 0 actionpack/test/fixtures/digestor/level/below/index.html.erb | 1 + actionpack/test/template/digestor_test.rb | 6 ++++++ 3 files changed, 7 insertions(+) create mode 100644 actionpack/test/fixtures/digestor/level/below/_header.html.erb create mode 100644 actionpack/test/fixtures/digestor/level/below/index.html.erb (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/digestor/level/below/_header.html.erb b/actionpack/test/fixtures/digestor/level/below/_header.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/digestor/level/below/index.html.erb b/actionpack/test/fixtures/digestor/level/below/index.html.erb new file mode 100644 index 0000000000..b92f49a8f8 --- /dev/null +++ b/actionpack/test/fixtures/digestor/level/below/index.html.erb @@ -0,0 +1 @@ +<%= render partial: "header" %> diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 01b101cb49..8181aa11f7 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -59,6 +59,12 @@ class TemplateDigestorTest < ActionView::TestCase change_template("comments/_comment") end end + + def test_directory_depth_dependency + assert_digest_difference("level/below/index") do + change_template("level/below/_header") + end + end def test_logging_of_missing_template assert_logged "Couldn't find template for digesting: messages/something_missing.html" do -- cgit v1.2.3 From bdd105d8b91c5d0881ab78e36a65a79fdca4a7fb Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 12 Oct 2012 00:50:20 -0200 Subject: When executing permit with just a key that points to a hash, DO NOT allow all the hash params.require(:person).permit(:projects_attributes) was returning => {"projects_attributes"=>{"0"=>{"name"=>"Project 1"}}} When should return => {} You should be doing ... params.require(:person).permit(projects_attributes: :name) to get just the projects attributes you want to allow --- actionpack/test/controller/parameters/nested_parameters_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/nested_parameters_test.rb b/actionpack/test/controller/parameters/nested_parameters_test.rb index 41f5b6e127..d287e79cba 100644 --- a/actionpack/test/controller/parameters/nested_parameters_test.rb +++ b/actionpack/test/controller/parameters/nested_parameters_test.rb @@ -15,18 +15,22 @@ class NestedParametersTest < ActiveSupport::TestCase details: { pages: 200, genre: "Tragedy" + }, + id: { + isbn: 'x' } }, magazine: "Mjallo!" }) - permitted = params.permit book: [ :title, { authors: [ :name ] }, { details: :pages } ] + permitted = params.permit book: [ :title, { authors: [ :name ] }, { details: :pages }, :id ] assert permitted.permitted? assert_equal "Romeo and Juliet", permitted[:book][:title] assert_equal "William Shakespeare", permitted[:book][:authors][0][:name] assert_equal "Christopher Marlowe", permitted[:book][:authors][1][:name] assert_equal 200, permitted[:book][:details][:pages] + assert_nil permitted[:book][:id] assert_nil permitted[:book][:details][:genre] assert_nil permitted[:book][:authors][0][:born] assert_nil permitted[:magazine] -- cgit v1.2.3 From ab9140ff0274ade509d6905c20e1d2546112616e Mon Sep 17 00:00:00 2001 From: dfens Date: Fri, 12 Oct 2012 09:56:39 +0200 Subject: Cleanup trailing whitespaces --- actionpack/test/controller/parameters/parameters_permit_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 18bb51c5a3..ad970f0a9a 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -3,7 +3,7 @@ require 'action_controller/metal/strong_parameters' class ParametersPermitTest < ActiveSupport::TestCase setup do - @params = ActionController::Parameters.new({ person: { + @params = ActionController::Parameters.new({ person: { age: "32", name: { first: "David", last: "Heinemeier Hansson" } }}) end -- cgit v1.2.3 From bd38d9f2118b1005718f8db4292b21a73879409e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 12 Oct 2012 14:57:38 -0500 Subject: Add asset_path and asset_url helpers --- actionpack/test/template/asset_tag_helper_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 754622c883..ac73e9515c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -55,6 +55,19 @@ class AssetTagHelperTest < ActionView::TestCase ENV.delete('RAILS_ASSET_ID') end + AssetPathToTag = { + %(asset_path("foo")) => %(/foo), + %(asset_path("style.css")) => %(/style.css), + %(asset_path("xmlhr.js")) => %(/xmlhr.js), + %(asset_path("xml.png")) => %(/xml.png), + %(asset_path("dir/xml.png")) => %(/dir/xml.png), + %(asset_path("/dir/xml.png")) => %(/dir/xml.png), + + %(asset_path("style", type: :stylesheet)) => %(/stylesheets/style.css), + %(asset_path("xmlhr", type: :javascript)) => %(/javascripts/xmlhr.js), + %(asset_path("xml.png", type: :image)) => %(/images/xml.png) + } + AutoDiscoveryToTag = { %(auto_discovery_link_tag) => %(), %(auto_discovery_link_tag(:rss)) => %(), @@ -293,6 +306,11 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal expected, result end + def test_asset_path_tag + ENV["RAILS_ASSET_ID"] = "" + AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } + end + def test_auto_discovery_link_tag AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end -- cgit v1.2.3 From 1e2b0ce95e48463361111ceae6eed7d4ad5462f0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 12 Oct 2012 16:56:00 -0500 Subject: Refactor AssetUrlHelper to make it friendly for plugins and extensions Add asset_path/url helper for a consolidated entry point Expose compute_asset_path as a public API Expose compute_asset_host as a public API Move RAILS_ASSET_ID to its own module, AssetIdHelper Removed AV::AssetPaths --- actionpack/test/template/asset_tag_helper_test.rb | 36 ++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index ac73e9515c..2059501fcc 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -42,6 +42,7 @@ class AssetTagHelperTest < ActionView::TestCase def protocol() 'http://' end def ssl?() false end def host_with_port() 'localhost' end + def base_url() 'http://www.example.com' end end.new @controller.request = @request @@ -602,7 +603,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase @controller = BasicController.new @controller.config.relative_url_root = "/collaboration/hieraki" - @request = Struct.new(:protocol).new("gopher://") + @request = Struct.new(:protocol, :base_url).new("gopher://", "gopher://www.example.com") @controller.request = @request end @@ -617,10 +618,33 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png")) end + def test_should_return_nothing_if_asset_host_isnt_configured + assert_equal nil, compute_asset_host("foo") + end + + def test_should_current_request_host_is_always_returned_for_request + assert_equal "gopher://www.example.com", compute_asset_host("foo", :protocol => :request) + end + def test_should_ignore_relative_root_path_on_complete_url assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png")) end + def test_should_return_simple_string_asset_host + @controller.config.asset_host = "assets.example.com" + assert_equal "gopher://assets.example.com", compute_asset_host("foo") + end + + def test_should_return_relative_asset_host + @controller.config.asset_host = "assets.example.com" + assert_equal "//assets.example.com", compute_asset_host("foo", :protocol => :relative) + end + + def test_should_return_custom_protocol_asset_host + @controller.config.asset_host = "assets.example.com" + assert_equal "ftp://assets.example.com", compute_asset_host("foo", :protocol => "ftp") + end + def test_should_compute_proper_path_with_asset_host @controller.config.asset_host = "assets.example.com" assert_dom_equal(%(), auto_discovery_link_tag) @@ -653,6 +677,11 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/images/xml.png), image_url("xml.png")) end + def test_should_return_asset_host_with_protocol + @controller.config.asset_host = "http://assets.example.com" + assert_equal "http://assets.example.com", compute_asset_host("foo") + end + def test_should_ignore_asset_host_on_complete_url @controller.config.asset_host = "http://assets.example.com" assert_dom_equal(%(), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css")) @@ -663,6 +692,11 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(), stylesheet_link_tag("//bar.example.com/stylesheets/style.css")) end + def test_should_wildcard_asset_host + @controller.config.asset_host = 'http://a%d.example.com' + assert_match(%r(http://a[0123].example.com), compute_asset_host("foo")) + end + def test_should_wildcard_asset_host_between_zero_and_four @controller.config.asset_host = 'http://a%d.example.com' assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')) -- cgit v1.2.3 From c3cff4d4219c556a5bfe4cbd72b96723b1633122 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 12 Oct 2012 17:07:17 -0500 Subject: Ensure AssetUrlHelper can be mixed into AC::Base --- actionpack/test/template/asset_tag_helper_test.rb | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 2059501fcc..08c927a4ab 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -13,6 +13,8 @@ end class AssetTagHelperTest < ActionView::TestCase tests ActionView::Helpers::AssetTagHelper + attr_reader :request + def setup super silence_warnings do @@ -598,6 +600,8 @@ end class AssetTagHelperNonVhostTest < ActionView::TestCase tests ActionView::Helpers::AssetTagHelper + attr_reader :request + def setup super @controller = BasicController.new @@ -720,3 +724,32 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase assert_dom_equal(%(/collaboration/hieraki/stylesheets/foo.css), stylesheet_path("foo")) end end + +class AssetUrlHelperControllerTest < ActionView::TestCase + tests ActionView::Helpers::AssetUrlHelper + + def setup + super + + @controller = BasicController.new + @controller.extend ActionView::Helpers::AssetUrlHelper + + @request = Class.new do + attr_accessor :script_name + def protocol() 'http://' end + def ssl?() false end + def host_with_port() 'www.example.com' end + def base_url() 'http://www.example.com' end + end.new + + @controller.request = @request + end + + def test_asset_path + assert_equal "/foo", @controller.asset_path("foo") + end + + def test_asset_url + assert_equal "http://www.example.com/foo", @controller.asset_url("foo") + end +end -- cgit v1.2.3 From dee3a192744ee11bf3fe5ac69aa099a328288e81 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 12 Oct 2012 17:09:32 -0500 Subject: JAVASCRIPTS_DIR, STYLESHEETS_DIR, ASSETS_DIR don't even exist anymore --- actionpack/test/template/asset_tag_helper_test.rb | 28 ----------------------- 1 file changed, 28 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 08c927a4ab..43737b81e6 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -17,25 +17,6 @@ class AssetTagHelperTest < ActionView::TestCase def setup super - silence_warnings do - ActionView::Helpers::AssetTagHelper.send( - :const_set, - :JAVASCRIPTS_DIR, - File.dirname(__FILE__) + "/../fixtures/public/javascripts" - ) - - ActionView::Helpers::AssetTagHelper.send( - :const_set, - :STYLESHEETS_DIR, - File.dirname(__FILE__) + "/../fixtures/public/stylesheets" - ) - - ActionView::Helpers::AssetTagHelper.send( - :const_set, - :ASSETS_DIR, - File.dirname(__FILE__) + "/../fixtures/public" - ) - end @controller = BasicController.new @@ -353,15 +334,6 @@ class AssetTagHelperTest < ActionView::TestCase assert javascript_include_tag("prototype").html_safe? end - def test_all_javascript_expansion_not_include_application_js_if_not_exists - FileUtils.mv(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'application.js'), - File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'application.bak')) - assert_no_match(/application\.js/, javascript_include_tag(:all)) - ensure - FileUtils.mv(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'application.bak'), - File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'application.js')) - end - def test_stylesheet_path ENV["RAILS_ASSET_ID"] = "" StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } -- cgit v1.2.3 From 5dfeb1b852c6c4a7b9c4aa3fa8dc5f25b516f9f1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 13 Oct 2012 09:59:57 -0500 Subject: Add a few more compute_asset_path tests --- actionpack/test/template/asset_tag_helper_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 43737b81e6..5dc854d561 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -295,6 +295,14 @@ class AssetTagHelperTest < ActionView::TestCase AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end + def test_compute_asset_public_path + assert_equal "/robots.txt", compute_asset_path("robots.txt") + assert_equal "/robots.txt", compute_asset_path("/robots.txt") + assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", :type => :javascript) + assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", :type => :javascript) + assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", :type => :stylesheet) + end + def test_auto_discovery_link_tag AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end -- cgit v1.2.3 From 60a4fffd83e94ad4471570b16f9d954f04bc0300 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 13 Oct 2012 10:13:47 -0500 Subject: Allow asset url config to be undefined --- actionpack/test/template/asset_tag_helper_test.rb | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 5dc854d561..8435db3166 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -733,3 +733,44 @@ class AssetUrlHelperControllerTest < ActionView::TestCase assert_equal "http://www.example.com/foo", @controller.asset_url("foo") end end + +class AssetUrlHelperEmptyModuleTest < ActionView::TestCase + tests ActionView::Helpers::AssetUrlHelper + + def setup + super + + @module = Module.new + @module.extend ActionView::Helpers::AssetUrlHelper + end + + def test_asset_path + assert_equal "/foo", @module.asset_path("foo") + end + + def test_asset_url + assert_equal "/foo", @module.asset_url("foo") + end + + def test_asset_url_with_request + @module.instance_eval do + def request + Struct.new(:base_url, :script_name).new("http://www.example.com", nil) + end + end + + assert @module.request + assert_equal "http://www.example.com/foo", @module.asset_url("foo") + end + + def test_asset_url_with_config_asset_host + @module.instance_eval do + def config + Struct.new(:asset_host).new("http://www.example.com") + end + end + + assert @module.config.asset_host + assert_equal "http://www.example.com/foo", @module.asset_url("foo") + end +end -- cgit v1.2.3 From a0f97e467dba3c21a08e7e590317f4752eab1ff1 Mon Sep 17 00:00:00 2001 From: Ayrton De Craene Date: Mon, 15 Oct 2012 11:30:14 +0200 Subject: Minor cleanup, helper method was only used once --- actionpack/test/template/sanitize_helper_test.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/sanitize_helper_test.rb b/actionpack/test/template/sanitize_helper_test.rb index 7626cdf386..12d5260a9d 100644 --- a/actionpack/test/template/sanitize_helper_test.rb +++ b/actionpack/test/template/sanitize_helper_test.rb @@ -17,7 +17,7 @@ class SanitizeHelperTest < ActionView::TestCase end def test_sanitize_form - assert_sanitized "
", '' + assert_equal '', sanitize("
") end def test_should_sanitize_illegal_style_properties @@ -48,8 +48,4 @@ class SanitizeHelperTest < ActionView::TestCase def test_sanitize_is_marked_safe assert sanitize("").html_safe? end - - def assert_sanitized(text, expected = nil) - assert_equal((expected || text), sanitize(text)) - end end -- cgit v1.2.3 From 3db69909b9d4549128984c4c76f8a51eca3d79e6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Oct 2012 09:47:16 -0500 Subject: :fire: Rails asset id support --- actionpack/test/template/asset_tag_helper_test.rb | 81 +---------------------- 1 file changed, 1 insertion(+), 80 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 8435db3166..30bd5c159c 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -35,10 +35,6 @@ class AssetTagHelperTest < ActionView::TestCase "http://www.example.com" end - def teardown - ENV.delete('RAILS_ASSET_ID') - end - AssetPathToTag = { %(asset_path("foo")) => %(/foo), %(asset_path("style.css")) => %(/style.css), @@ -291,7 +287,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_asset_path_tag - ENV["RAILS_ASSET_ID"] = "" AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -323,8 +318,7 @@ class AssetTagHelperTest < ActionView::TestCase UrlToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - def test_javascript_include_tag_with_blank_asset_id - ENV["RAILS_ASSET_ID"] = "" + def test_javascript_include_tag JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -343,7 +337,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_path - ENV["RAILS_ASSET_ID"] = "" StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -352,7 +345,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_url - ENV["RAILS_ASSET_ID"] = "" StyleUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -361,7 +353,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag - ENV["RAILS_ASSET_ID"] = "" StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -376,7 +367,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag_is_html_safe - ENV["RAILS_ASSET_ID"] = "" assert stylesheet_link_tag('dir/file').html_safe? assert stylesheet_link_tag('dir/other/file', 'dir/file2').html_safe? end @@ -386,7 +376,6 @@ class AssetTagHelperTest < ActionView::TestCase 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 @@ -428,21 +417,6 @@ class AssetTagHelperTest < ActionView::TestCase FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end - def test_image_tag_windows_behaviour - old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1" - # This simulates the behavior of File#exist? on windows when testing a file ending in "." - # If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".") - # OS X, linux etc will return false in this case. - File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true) - assert_equal 'Rails', image_tag('rails.png') - ensure - if old_asset_id - ENV["RAILS_ASSET_ID"] = old_asset_id - else - ENV.delete("RAILS_ASSET_ID") - end - end - def test_video_path VideoPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -491,27 +465,6 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal({:autoplay => true}, options) end - def test_timebased_asset_id - expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s - assert_equal %(Rails), image_tag("rails.png") - end - - def test_string_asset_id - @controller.config.asset_path = "/assets.v12345%s" - - expected_path = "/assets.v12345/images/rails.png" - assert_equal %(Rails), image_tag("rails.png") - end - - def test_proc_asset_id - @controller.config.asset_path = Proc.new do |asset_path| - "/assets.v12345#{asset_path}" - end - - expected_path = "/assets.v12345/images/rails.png" - assert_equal %(Rails), image_tag("rails.png") - end - def test_image_tag_interpreting_email_cid_correctly # An inline image has no need for an alt tag to be automatically generated from the cid: assert_equal '', image_tag("cid:thi%25%25sis@acontentid") @@ -521,37 +474,6 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal 'Image', image_tag("cid:thi%25%25sis@acontentid", :alt => "Image") end - def test_timebased_asset_id_with_relative_url_root - @controller.config.relative_url_root = "/collaboration/hieraki" - expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s - assert_equal %(Rails), image_tag("rails.png") - end - - # Same as above, but with script_name - def test_timebased_asset_id_with_script_name - @request.script_name = "/collaboration/hieraki" - expected_time = File.mtime(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).to_i.to_s - assert_equal %(Rails), image_tag("rails.png") - end - - def test_should_skip_asset_id_on_complete_url - assert_equal %(Rails), image_tag("http://www.example.com/rails.png") - end - - def test_should_skip_asset_id_on_scheme_relative_url - assert_equal %(Rails), image_tag("//www.example.com/rails.png") - end - - def test_should_use_preset_asset_id - ENV["RAILS_ASSET_ID"] = "4500" - assert_equal %(Rails), image_tag("rails.png") - end - - def test_preset_empty_asset_id - ENV["RAILS_ASSET_ID"] = "" - assert_equal %(Rails), image_tag("rails.png") - end - def test_should_not_modify_source_string source = '/images/rails.png' copy = source.dup @@ -560,7 +482,6 @@ class AssetTagHelperTest < ActionView::TestCase end def test_caching_image_path_with_caching_and_proc_asset_host_using_request - ENV['RAILS_ASSET_ID'] = '' @controller.config.asset_host = Proc.new do |source, request| if request.ssl? "#{request.protocol}#{request.host_with_port}" -- cgit v1.2.3 From 6601917ad96aa7e0fdaf96058cafe01fbf00bc12 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Oct 2012 10:57:32 -0500 Subject: Extract compute_asset_extname and allow extname to be disabled --- actionpack/test/template/asset_tag_helper_test.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 30bd5c159c..26a229e2ba 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -43,6 +43,11 @@ class AssetTagHelperTest < ActionView::TestCase %(asset_path("dir/xml.png")) => %(/dir/xml.png), %(asset_path("/dir/xml.png")) => %(/dir/xml.png), + %(asset_path("script.min")) => %(/script.min), + %(asset_path("script.min.js")) => %(/script.min.js), + %(asset_path("style.min")) => %(/style.min), + %(asset_path("style.min.css")) => %(/style.min.css), + %(asset_path("style", type: :stylesheet)) => %(/stylesheets/style.css), %(asset_path("xmlhr", type: :javascript)) => %(/javascripts/xmlhr.js), %(asset_path("xml.png", type: :image)) => %(/images/xml.png) @@ -66,7 +71,9 @@ class AssetTagHelperTest < ActionView::TestCase JavascriptPathToTag = { %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js), %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js), - %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js) + %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js), + %(javascript_path("xmlhr.min")) => %(/javascripts/xmlhr.min.js), + %(javascript_path("xmlhr.min.js")) => %(/javascripts/xmlhr.min.js) } PathToJavascriptToTag = { @@ -91,7 +98,6 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_include_tag("bank")) => %(), %(javascript_include_tag("bank.js")) => %(), %(javascript_include_tag("bank", :lang => "vbscript")) => %(), - %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), %(javascript_include_tag("http://example.com/all")) => %(), %(javascript_include_tag("http://example.com/all.js")) => %(), @@ -102,14 +108,17 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_path("bank")) => %(/stylesheets/bank.css), %(stylesheet_path("bank.css")) => %(/stylesheets/bank.css), %(stylesheet_path('subdir/subdir')) => %(/stylesheets/subdir/subdir.css), - %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css) + %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css), + %(stylesheet_path("style.min")) => %(/stylesheets/style.min.css), + %(stylesheet_path("style.min.css")) => %(/stylesheets/style.min.css) } PathToStyleToTag = { %(path_to_stylesheet("style")) => %(/stylesheets/style.css), %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css), %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css), - %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss) + %(path_to_stylesheet('/dir/file.rcss', :extname => false)) => %(/dir/file.rcss), + %(path_to_stylesheet('/dir/file', :extname => '.rcss')) => %(/dir/file.rcss) } StyleUrlToTag = { @@ -123,7 +132,8 @@ class AssetTagHelperTest < ActionView::TestCase %(url_to_stylesheet("style")) => %(http://www.example.com/stylesheets/style.css), %(url_to_stylesheet("style.css")) => %(http://www.example.com/stylesheets/style.css), %(url_to_stylesheet('dir/file')) => %(http://www.example.com/stylesheets/dir/file.css), - %(url_to_stylesheet('/dir/file.rcss')) => %(http://www.example.com/dir/file.rcss) + %(url_to_stylesheet('/dir/file.rcss', :extname => false)) => %(http://www.example.com/dir/file.rcss), + %(url_to_stylesheet('/dir/file', :extname => '.rcss')) => %(http://www.example.com/dir/file.rcss) } StyleLinkToTag = { @@ -132,7 +142,6 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_link_tag("/elsewhere/file")) => %(), %(stylesheet_link_tag("subdir/subdir")) => %(), %(stylesheet_link_tag("bank", :media => "all")) => %(), - %(stylesheet_link_tag("random.styles", "/elsewhere/file")) => %(\n), %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(), %(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(), -- cgit v1.2.3 From c4276ddf3860128d4f64c795c8b5cf5258aaeab8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Oct 2012 13:30:24 -0500 Subject: Ignore asset url query string or anchor when appending extensions and computing public path --- actionpack/test/template/asset_tag_helper_test.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 26a229e2ba..eb1a54a81f 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -73,7 +73,12 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js), %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js), %(javascript_path("xmlhr.min")) => %(/javascripts/xmlhr.min.js), - %(javascript_path("xmlhr.min.js")) => %(/javascripts/xmlhr.min.js) + %(javascript_path("xmlhr.min.js")) => %(/javascripts/xmlhr.min.js), + + %(javascript_path("xmlhr.js?123")) => %(/javascripts/xmlhr.js?123), + %(javascript_path("xmlhr.js?body=1")) => %(/javascripts/xmlhr.js?body=1), + %(javascript_path("xmlhr.js#hash")) => %(/javascripts/xmlhr.js#hash), + %(javascript_path("xmlhr.js?123#hash")) => %(/javascripts/xmlhr.js?123#hash) } PathToJavascriptToTag = { @@ -285,6 +290,14 @@ class AssetTagHelperTest < ActionView::TestCase %(audio_tag(["audio.mp3", "audio.ogg"], :autobuffer => true, :controls => true)) => %() } + FontPathToTag = { + %(font_path("font.eot")) => %(/fonts/font.eot), + %(font_path("font.eot#iefix")) => %(/fonts/font.eot#iefix), + %(font_path("font.woff")) => %(/fonts/font.woff), + %(font_path("font.ttf")) => %(/fonts/font.ttf), + %(font_path("font.ttf?123")) => %(/fonts/font.ttf?123) + } + def test_autodiscovery_link_tag_deprecated_types result = nil assert_deprecated do @@ -466,6 +479,10 @@ class AssetTagHelperTest < ActionView::TestCase AudioLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end + def test_font_path + FontPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } + end + def test_video_audio_tag_does_not_modify_options options = {:autoplay => true} video_tag('video', options) -- cgit v1.2.3 From d410ac5136ee2c654b3922622bb2c270954acc9b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 17 Oct 2012 11:30:08 -0700 Subject: use the tmp filesystem rather than our own thing. --- actionpack/test/template/digestor_test.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 8181aa11f7..b9d26da3af 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -13,20 +13,24 @@ end class FixtureFinder FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" - TMP_DIR = "#{File.dirname(__FILE__)}/../tmp" def find(logical_name, keys, partial, options) - FixtureTemplate.new("#{TMP_DIR}/digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") + FixtureTemplate.new("digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") end end class TemplateDigestorTest < ActionView::TestCase def setup - FileUtils.cp_r FixtureFinder::FIXTURES_DIR, FixtureFinder::TMP_DIR + @cwd = Dir.pwd + @tmp_dir = Dir.mktmpdir + + FileUtils.cp_r FixtureFinder::FIXTURES_DIR, @tmp_dir + Dir.chdir @tmp_dir end def teardown - FileUtils.rm_r File.join(FixtureFinder::TMP_DIR, "digestor") + Dir.chdir @cwd + FileUtils.rm_r @tmp_dir ActionView::Digestor.cache.clear end @@ -159,7 +163,7 @@ class TemplateDigestorTest < ActionView::TestCase end def change_template(template_name) - File.open("#{FixtureFinder::TMP_DIR}/digestor/#{template_name}.html.erb", "w") do |f| + File.open("digestor/#{template_name}.html.erb", "w") do |f| f.write "\nTHIS WAS CHANGED!" end end -- cgit v1.2.3 From 0c3ca0f013904d40bf11ac9da95ed0ef3d9ddc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 18 Oct 2012 00:31:46 -0300 Subject: Permit string and float values in the multiparameter attributes --- .../parameters/multi_parameter_attributes_test.rb | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb index 2214ec769c..15338059bc 100644 --- a/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb +++ b/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb @@ -5,18 +5,20 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase test "permitted multi-parameter attribute keys" do params = ActionController::Parameters.new({ book: { - "shipped_at(1i)" => "2012", - "shipped_at(2i)" => "3", - "shipped_at(3i)" => "25", - "shipped_at(4i)" => "10", - "shipped_at(5i)" => "15", - "published_at(1i)" => "1999", - "published_at(2i)" => "2", - "published_at(3i)" => "5" + "shipped_at(1i)" => "2012", + "shipped_at(2i)" => "3", + "shipped_at(3i)" => "25", + "shipped_at(4i)" => "10", + "shipped_at(5i)" => "15", + "published_at(1i)" => "1999", + "published_at(2i)" => "2", + "published_at(3i)" => "5", + "price(1)" => "R$", + "price(2f)" => "2.02" } }) - permitted = params.permit book: [ :shipped_at ] + permitted = params.permit book: [ :shipped_at, :price ] assert permitted.permitted? @@ -26,6 +28,9 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase assert_equal "10", permitted[:book]["shipped_at(4i)"] assert_equal "15", permitted[:book]["shipped_at(5i)"] + assert_equal "R$", permitted[:book]["price(1)"] + assert_equal "2.02", permitted[:book]["price(2f)"] + assert_nil permitted[:book]["published_at(1i)"] assert_nil permitted[:book]["published_at(2i)"] assert_nil permitted[:book]["published_at(3i)"] -- cgit v1.2.3 From a48ef9b879a29cb54e01ad295224e056fb0966e1 Mon Sep 17 00:00:00 2001 From: Pavel Nikitin Date: Wed, 17 Oct 2012 12:33:17 +0300 Subject: Extend date_select helper functionality. --- actionpack/test/template/date_helper_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index a4da7cd4b0..8bd8eff3c0 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1007,6 +1007,22 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), { :date_separator => " / ", :prefix => "date[first]", :use_hidden => true }) end + def test_select_date_with_css_classes_option + expected = %(\n" + + expected << %(\n" + + expected << %(\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]", :with_css_classes => true}) + end + def test_select_datetime expected = %(', check_box("post", "secret") ) + + @post.secret = Set.new(['1']) + assert_dom_equal( + '', + check_box("post", "secret") + ) end def test_check_box_with_include_hidden_false -- cgit v1.2.3