diff options
Diffstat (limited to 'actionpack/test/template/sprockets_helper_test.rb')
-rw-r--r-- | actionpack/test/template/sprockets_helper_test.rb | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 67aee86d02..8d3be09a4f 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -1,5 +1,8 @@ require 'abstract_unit' require 'sprockets' +require 'mocha' + +module Rails; end class SprocketsHelperTest < ActionView::TestCase tests ActionView::Helpers::SprocketsHelper @@ -22,6 +25,12 @@ class SprocketsHelperTest < ActionView::TestCase @assets = Sprockets::Environment.new @assets.paths << FIXTURES.join("sprockets/app/javascripts") @assets.paths << FIXTURES.join("sprockets/app/stylesheets") + @assets.paths << FIXTURES.join("sprockets/app/images") + + application = Object.new + Rails.stubs(:application).returns(application) + application.stubs(:config).returns(config) + application.stubs(:assets).returns(@assets) config.perform_caching = true end @@ -30,22 +39,40 @@ class SprocketsHelperTest < ActionView::TestCase "http://www.example.com" end + test "asset path" do + assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png", + asset_path("logo.png") + + assert_equal "/images/logo", + asset_path("/images/logo") + assert_equal "/images/logo.gif", + asset_path("/images/logo.gif") + + assert_equal "/dir/audio", + asset_path("/dir/audio") + + assert_equal "http://www.example.com/video/play", + asset_path("http://www.example.com/video/play") + assert_equal "http://www.example.com/video/play.mp4", + asset_path("http://www.example.com/video/play.mp4") + end + test "javascript path" do assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", - sprockets_javascript_path(:application) + asset_path(:application, "js") assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", - sprockets_javascript_path("xmlhr") + asset_path("xmlhr", "js") assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", - sprockets_javascript_path("dir/xmlhr.js") + asset_path("dir/xmlhr.js", "js") assert_equal "/dir/xmlhr.js", - sprockets_javascript_path("/dir/xmlhr") + asset_path("/dir/xmlhr", "js") - assert_equal "http://www.railsapplication.com/js/xmlhr", - sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr") - assert_equal "http://www.railsapplication.com/js/xmlhr.js", - sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr.js") + assert_equal "http://www.example.com/js/xmlhr", + asset_path("http://www.example.com/js/xmlhr", "js") + assert_equal "http://www.example.com/js/xmlhr.js", + asset_path("http://www.example.com/js/xmlhr.js", "js") end test "javascript include tag" do @@ -56,25 +83,21 @@ class SprocketsHelperTest < ActionView::TestCase sprockets_javascript_include_tag("xmlhr") assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>', sprockets_javascript_include_tag("xmlhr.js") - assert_equal '<script src="http://www.railsapplication.com/xmlhr" type="text/javascript"></script>', - sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr") + assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>', + sprockets_javascript_include_tag("http://www.example.com/xmlhr") end test "stylesheet path" do - assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", - sprockets_stylesheet_path(:application) - - assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", - sprockets_stylesheet_path("style") - assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", - sprockets_stylesheet_path("dir/style.css") - assert_equal "/dir/style.css", - sprockets_stylesheet_path("/dir/style.css") - - assert_equal "http://www.railsapplication.com/css/style", - sprockets_stylesheet_path("http://www.railsapplication.com/css/style") - assert_equal "http://www.railsapplication.com/css/style.css", - sprockets_stylesheet_path("http://www.railsapplication.com/css/style.css") + assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", asset_path(:application, "css") + + assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css") + assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css") + assert_equal "/dir/style.css", asset_path("/dir/style.css", "css") + + assert_equal "http://www.example.com/css/style", + asset_path("http://www.example.com/css/style", "css") + assert_equal "http://www.example.com/css/style.css", + asset_path("http://www.example.com/css/style.css", "css") end test "stylesheet link tag" do @@ -86,8 +109,8 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />', sprockets_stylesheet_link_tag("style.css") - assert_equal '<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />', - sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") + assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />', + sprockets_stylesheet_link_tag("http://www.example.com/style.css") assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />', sprockets_stylesheet_link_tag("style", :media => "all") assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />', |