Changeset 6164
- Timestamp:
- 02/18/07 23:54:20 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb (modified) (6 diffs)
- trunk/actionpack/test/controller/render_test.rb (modified) (1 diff)
- trunk/actionpack/test/fixtures/public/javascripts/bank.js (added)
- trunk/actionpack/test/fixtures/public/javascripts/robber.js (added)
- trunk/actionpack/test/fixtures/public/stylesheets (added)
- trunk/actionpack/test/fixtures/public/stylesheets/bank.css (added)
- trunk/actionpack/test/fixtures/public/stylesheets/robber.css (added)
- trunk/actionpack/test/template/asset_tag_helper_test.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6161 r6164 1 1 *SVN* 2 3 * Added caching option to AssetTagHelper#stylesheet_link_tag and AssetTagHelper#javascript_include_tag [DHH]. Examples: 4 5 stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false => 6 <link href="/stylesheets/style1.css" media="screen" rel="Stylesheet" type="text/css" /> 7 <link href="/stylesheets/styleB.css" media="screen" rel="Stylesheet" type="text/css" /> 8 <link href="/stylesheets/styleX2.css" media="screen" rel="Stylesheet" type="text/css" /> 9 10 stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true => 11 <link href="/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" /> 12 13 ...when caching is on, all.css is the concatenation of style1.css, styleB.css, and styleX2.css. 14 Same deal for JavaScripts. 2 15 3 16 * Work around the two connection per host browser limit: use asset%d.myapp.com to distribute asset requests among asset[0123].myapp.com. Use a DNS wildcard or CNAMEs to map these hosts to your asset server. See http://www.die.net/musings/page_load_time/ for background. [Jeremy Kemper] trunk/actionpack/lib/action_controller/base.rb
r6163 r6164 880 880 if text.is_a?(String) 881 881 if response.headers['Status'][0..2] == '200' && !response.body.empty? 882 response.headers['Etag'] ||= %("#{Digest::MD5.hexdigest(text)}")882 response.headers['Etag'] = %("#{Digest::MD5.hexdigest(text)}") 883 883 884 884 if request.headers['HTTP_IF_NONE_MATCH'] == response.headers['Etag'] trunk/actionpack/lib/action_view/helpers/asset_tag_helper.rb
r6162 r6164 29 29 # for background. 30 30 module AssetTagHelper 31 ASSETS_DIR = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/public" : "public" 32 JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts" 33 STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets" 34 31 35 # Returns a link tag that browsers and news readers can use to auto-detect 32 36 # an RSS or ATOM feed. The +type+ can either be <tt>:rss</tt> (default) or … … 94 98 # ... 95 99 # <script type="text/javascript" src="/javascripts/application.js"></script> *see below 100 # 101 # * = The application.js file is only referenced if it exists 102 # 103 # You can also include all javascripts in the javascripts directory using :all as the source: 104 # 105 # javascript_include_tag :all # => 106 # <script type="text/javascript" src="/javascripts/prototype.js"></script> 107 # <script type="text/javascript" src="/javascripts/effects.js"></script> 108 # ... 109 # <script type="text/javascript" src="/javascripts/application.js"></script> 110 # <script type="text/javascript" src="/javascripts/shop.js"></script> 111 # <script type="text/javascript" src="/javascripts/checkout.js"></script> 112 # 113 # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available for 114 # all subsequently included files. They 115 # 116 # == Caching multiple javascripts into one 117 # 118 # You can also cache multiple javascripts into one file, which requires less HTTP connections and can better be 119 # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching 120 # is set to true (which is the case by default for the Rails production environment, but not for the development 121 # environment). Examples: 122 # 123 # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false => 124 # <script type="text/javascript" src="/javascripts/prototype.js"></script> 125 # <script type="text/javascript" src="/javascripts/effects.js"></script> 126 # ... 127 # <script type="text/javascript" src="/javascripts/application.js"></script> 128 # <script type="text/javascript" src="/javascripts/shop.js"></script> 129 # <script type="text/javascript" src="/javascripts/checkout.js"></script> 130 # 131 # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true => 132 # <script type="text/javascript" src="/javascripts/all.js"></script> 133 # 134 # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => 135 # <script type="text/javascript" src="/javascripts/prototype.js"></script> 136 # <script type="text/javascript" src="/javascripts/cart.js"></script> 137 # <script type="text/javascript" src="/javascripts/checkout.js"></script> 138 # 139 # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => 140 # <script type="text/javascript" src="/javascripts/shop.js"></script> 96 141 def javascript_include_tag(*sources) 97 142 options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } 98 99 if sources.include?(:defaults) 100 sources = sources[0..(sources.index(:defaults))] + 101 @@javascript_default_sources.dup + 102 sources[(sources.index(:defaults) + 1)..sources.length] 103 104 sources.delete(:defaults) 105 sources << "application" if defined?(RAILS_ROOT) && File.exists?("#{RAILS_ROOT}/public/javascripts/application.js") 106 end 107 108 sources.collect do |source| 109 source = javascript_path(source) 110 content_tag("script", "", { "type" => "text/javascript", "src" => source }.merge(options)) 111 end.join("\n") 143 cache = options.delete("cache") 144 145 if ActionController::Base.perform_caching && cache 146 joined_javascript_name = (cache == true ? "all" : cache) + ".js" 147 joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name) 148 149 if !File.exists?(joined_javascript_path) 150 File.open(joined_javascript_path, "w+") do |cache| 151 javascript_paths = expand_javascript_sources(sources).collect { |source| javascript_path(source) } 152 cache.write(join_asset_file_contents(javascript_paths)) 153 end 154 end 155 156 content_tag("script", "", { 157 "type" => "text/javascript", "src" => javascript_path(joined_javascript_name) 158 }.merge(options)) 159 else 160 expand_javascript_sources(sources).collect do |source| 161 content_tag("script", "", { "type" => "text/javascript", "src" => javascript_path(source) }.merge(options)) 162 end.join("\n") 163 end 112 164 end 113 165 … … 149 201 # <link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" /> 150 202 # <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" /> 203 # 204 # You can also include all styles in the stylesheet directory using :all as the source: 205 # 206 # stylesheet_link_tag :all # => 207 # <link href="/stylesheets/style1.css" media="screen" rel="Stylesheet" type="text/css" /> 208 # <link href="/stylesheets/styleB.css" media="screen" rel="Stylesheet" type="text/css" /> 209 # <link href="/stylesheets/styleX2.css" media="screen" rel="Stylesheet" type="text/css" /> 210 # 211 # == Caching multiple stylesheets into one 212 # 213 # You can also cache multiple stylesheets into one file, which requires less HTTP connections and can better be 214 # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching 215 # is set to true (which is the case by default for the Rails production environment, but not for the development 216 # environment). Examples: 217 # 218 # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false => 219 # <link href="/stylesheets/style1.css" media="screen" rel="Stylesheet" type="text/css" /> 220 # <link href="/stylesheets/styleB.css" media="screen" rel="Stylesheet" type="text/css" /> 221 # <link href="/stylesheets/styleX2.css" media="screen" rel="Stylesheet" type="text/css" /> 222 # 223 # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true => 224 # <link href="/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" /> 225 # 226 # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false => 227 # <link href="/stylesheets/shop.css" media="screen" rel="Stylesheet" type="text/css" /> 228 # <link href="/stylesheets/cart.css" media="screen" rel="Stylesheet" type="text/css" /> 229 # <link href="/stylesheets/checkout.css" media="screen" rel="Stylesheet" type="text/css" /> 230 # 231 # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true => 232 # <link href="/stylesheets/payment.css" media="screen" rel="Stylesheet" type="text/css" /> 151 233 def stylesheet_link_tag(*sources) 152 234 options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } 153 sources.collect do |source| 154 source = stylesheet_path(source) 155 tag("link", { "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source }.merge(options)) 156 end.join("\n") 235 cache = options.delete("cache") 236 237 if ActionController::Base.perform_caching && cache 238 joined_stylesheet_name = (cache == true ? "all" : cache) + ".css" 239 joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name) 240 241 if !File.exists?(joined_stylesheet_path) 242 File.open(joined_stylesheet_path, "w+") do |cache| 243 stylesheet_paths = expand_stylesheet_sources(sources).collect { |source| stylesheet_path(source) } 244 cache.write(join_asset_file_contents(stylesheet_paths)) 245 end 246 end 247 248 tag("link", { 249 "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", 250 "href" => stylesheet_path(joined_stylesheet_name) 251 }.merge(options)) 252 else 253 options.delete("cache") 254 255 expand_stylesheet_sources(sources).collect do |source| 256 tag("link", { 257 "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => stylesheet_path(source) 258 }.merge(options)) 259 end.join("\n") 260 end 157 261 end 158 262 … … 217 321 def compute_public_path(source, dir, ext) 218 322 source += ".#{ext}" if File.extname(source).blank? 323 219 324 if source =~ %r{^[-a-z]+://} 220 325 source … … 246 351 def rails_asset_id(source) 247 352 ENV["RAILS_ASSET_ID"] || 248 File.mtime( "#{RAILS_ROOT}/public/#{source}").to_i.to_s rescue ""353 File.mtime(File.join(ASSETS_DIR, source)).to_i.to_s rescue "" 249 354 end 250 355 … … 253 358 def rewrite_asset_path!(source) 254 359 asset_id = rails_asset_id(source) 255 source << "?#{asset_id}" if defined?(RAILS_ROOT) && !asset_id.blank? 360 source << "?#{asset_id}" if !asset_id.blank? 361 end 362 363 def expand_javascript_sources(sources) 364 case 365 when sources.include?(:all) 366 all_javascript_files = Dir[File.join(JAVASCRIPTS_DIR, '*.js')].collect { |file| File.basename(file).split(".", 0).first } 367 sources = ((@@javascript_default_sources.dup & all_javascript_files) + all_javascript_files).uniq 368 369 when sources.include?(:defaults) 370 sources = sources[0..(sources.index(:defaults))] + 371 @@javascript_default_sources.dup + 372 sources[(sources.index(:defaults) + 1)..sources.length] 373 374 sources.delete(:defaults) 375 sources << "application" if File.exists?(File.join(JAVASCRIPTS_DIR, "application.js")) 376 end 377 378 sources 379 end 380 381 def expand_stylesheet_sources(sources) 382 if sources.first == :all 383 sources = Dir[File.join(STYLESHEETS_DIR, '*.css')].collect { |file| File.basename(file).split(".", 1).first } 384 else 385 sources 386 end 387 end 388 389 def join_asset_file_contents(paths) 390 paths.collect { |path| File.read(File.join(ASSETS_DIR, path.split("?").first)) }.join("\n\n") 256 391 end 257 392 end trunk/actionpack/test/controller/render_test.rb
r6163 r6164 336 336 end 337 337 338 def test_etag_should_govern_renders_with_layouts_too 339 get :builder_layout_test 340 assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['Etag'] 341 end 342 343 338 344 protected 339 345 def assert_deprecated_render(&block) trunk/actionpack/test/template/asset_tag_helper_test.rb
r6162 r6164 7 7 8 8 def setup 9 Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/") 9 silence_warnings do 10 ActionView::Helpers::AssetTagHelper.send( 11 :const_set, 12 :JAVASCRIPTS_DIR, 13 File.dirname(__FILE__) + "/../fixtures/public/javascripts" 14 ) 15 16 ActionView::Helpers::AssetTagHelper.send( 17 :const_set, 18 :STYLESHEETS_DIR, 19 File.dirname(__FILE__) + "/../fixtures/public/stylesheets" 20 ) 21 22 ActionView::Helpers::AssetTagHelper.send( 23 :const_set, 24 :ASSETS_DIR, 25 File.dirname(__FILE__) + "/../fixtures/public" 26 ) 27 end 10 28 11 29 @controller = Class.new do … … 24 42 25 43 def teardown 26 Object.send(:remove_const, :RAILS_ROOT) if defined?(RAILS_ROOT)44 ActionController::Base.perform_caching = false 27 45 ENV["RAILS_ASSET_ID"] = nil 28 46 end … … 54 72 %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>), 55 73 %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>), 56 %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>), 57 %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>), 58 %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>) 74 %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), 75 %(javascript_include_tag(:all)) => %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>), 76 %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), 77 %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>) 59 78 } 60 79 … … 72 91 %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="Stylesheet" type="text/css" />), 73 92 %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />), 93 %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="Stylesheet" type="text/css" />), 94 %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="Stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="Stylesheet" type="text/css" />), 74 95 %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />), 75 96 %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="Stylesheet" type="text/css" />) … … 107 128 108 129 def test_javascript_include_tag 109 Object.send(:remove_const, :RAILS_ROOT) if defined?(RAILS_ROOT)130 ENV["RAILS_ASSET_ID"] = "" 110 131 JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } 111 Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")112 132 113 133 ENV["RAILS_ASSET_ID"] = "1" … … 116 136 117 137 def test_register_javascript_include_default 118 Object.send(:remove_const, :RAILS_ROOT) if defined?(RAILS_ROOT)138 ENV["RAILS_ASSET_ID"] = "" 119 139 ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'slider' 120 assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script> ), javascript_include_tag(:defaults)140 assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults) 121 141 ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2' 122 assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script> ), javascript_include_tag(:defaults)142 assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults) 123 143 end 124 144 … … 128 148 129 149 def test_stylesheet_link_tag 150 ENV["RAILS_ASSET_ID"] = "" 130 151 StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } 131 152 end … … 169 190 image_tag(source) 170 191 assert_equal copy, source 192 end 193 194 195 def test_caching_javascript_include_tag_when_caching_on 196 ENV["RAILS_ASSET_ID"] = "" 197 ActionController::Base.perform_caching = true 198 199 assert_dom_equal( 200 %(<script src="/javascripts/all.js" type="text/javascript"></script>), 201 javascript_include_tag(:all, :cache => true) 202 ) 203 204 assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 205 206 assert_dom_equal( 207 %(<script src="/javascripts/money.js" type="text/javascript"></script>), 208 javascript_include_tag(:all, :cache => "money") 209 ) 210 211 assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 212 ensure 213 File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 214 File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 215 end 216 217 def test_caching_javascript_include_tag_when_caching_off 218 ENV["RAILS_ASSET_ID"] = "" 219 ActionController::Base.perform_caching = false 220 221 assert_dom_equal( 222 %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>), 223 javascript_include_tag(:all, :cache => true) 224 ) 225 226 assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 227 228 assert_dom_equal( 229 %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>), 230 javascript_include_tag(:all, :cache => "money") 231 ) 232 233 assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 234 end 235 236 def test_caching_stylesheet_link_tag_when_caching_on 237 ENV["RAILS_ASSET_ID"] = "" 238 ActionController::Base.perform_caching = true 239 240 assert_dom_equal( 241 %(<link href="/stylesheets/all.css" media="screen" rel="Stylesheet" type="text/css" />), 242 stylesheet_link_tag(:all, :cache => true) 243 ) 244 245 assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 246 247 assert_dom_equal( 248 %(<link href="/stylesheets/money.css" media="screen" rel="Stylesheet" type="text/css" />), 249 stylesheet_link_tag(:all, :cache => "money") 250 ) 251 252 assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 253 ensure 254 File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 255 File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 256 end 257 258 def test_caching_stylesheet_include_tag_when_caching_off 259 ENV["RAILS_ASSET_ID"] = "" 260 ActionController::Base.perform_caching = false 261 262 assert_dom_equal( 263 %(<link href="/stylesheets/bank.css" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="Stylesheet" type="text/css" />), 264 stylesheet_link_tag(:all, :cache => true) 265 ) 266 267 assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 268 269 assert_dom_equal( 270 %(<link href="/stylesheets/bank.css" media="screen" rel="Stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="Stylesheet" type="text/css" />), 271 stylesheet_link_tag(:all, :cache => "money") 272 ) 273 274 assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 171 275 end 172 276 end