Sprockets should ignore :cache and :concat options #6834

Closed
wants to merge 2 commits into
from
@@ -23,6 +23,8 @@ def javascript_include_tag(*sources)
body = options.key?(:body) ? options.delete(:body) : false
digest = options.key?(:digest) ? options.delete(:digest) : digest_assets?
+ options.except!(:cache, :concat)
+
sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'js')
asset.to_a.map { |dep|
@@ -40,6 +42,8 @@ def stylesheet_link_tag(*sources)
body = options.key?(:body) ? options.delete(:body) : false
digest = options.key?(:digest) ? options.delete(:digest) : digest_assets?
+ options.except!(:cache, :concat)
+
sources.collect do |source|
if debug && asset = asset_paths.asset_for(source, 'css')
asset.to_a.map { |dep|
@@ -268,6 +268,38 @@ def compute_host(source, request, options = {})
javascript_include_tag(:application)
end
+ test "javascript_include_tag with cache option" do
+ @config.assets.debug = false
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => true)
+
+ @config.assets.debug = true
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => true)
+
+ @config.perform_caching = false
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => true)
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => "foobar")
+ end
+
+ test "javascript_include_tag with concat option" do
+ @config.assets.debug = false
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => "foobar")
+
+ @config.assets.debug = true
+
+ assert_match %r{\A<script src="/assets/jquery.plugin.js" type="text/javascript"></script>\n<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\Z},
+ javascript_include_tag('jquery.plugin', 'xmlhr', :cache => "foobar")
+ end
+
test "stylesheet path through asset_path" do
assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css")
@@ -328,6 +360,38 @@ def compute_host(source, request, options = {})
stylesheet_link_tag(:application, :media => "print")
end
+ test "stylesheet_link_tag with cache option" do
+ @config.assets.debug = false
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :cache => true)
+
+ @config.assets.debug = true
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :cache => true)
+
+ @config.perform_caching = false
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :cache => true)
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :cache => "foobar")
+ end
+
+ test "stylesheet_link_tag with concat option" do
+ @config.assets.debug = false
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :concat => "foobar")
+
+ @config.assets.debug = true
+
+ assert_match %r{\A<link href="/assets/extra-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("extra", "style", :concat => "foobar")
+ end
+
test "alternate asset prefix" do
stubs(:asset_prefix).returns("/themes/test")
assert_match %r{/themes/test/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")