public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed AssetTag cache with with relative_url_root [#1022 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
martinrehfeld (author)
Mon Sep 22 11:23:23 -0700 2008
josh (committer)
Mon Sep 22 11:23:23 -0700 2008
commit  10380a22a65d93bee6775a0ffe93071b798bf249
tree    ddcf661c8c3054653c694291a95a2f9297004bd3
parent  900fd6eca9dd97d2341e89bcb27d7a82d62965bf
...
601
602
603
604
 
605
606
607
...
601
602
603
 
604
605
606
607
0
@@ -601,7 +601,7 @@ module ActionView
0
 
0
             def prepend_relative_url_root(source)
0
               relative_url_root = ActionController::Base.relative_url_root
0
-              if request? && source !~ %r{^#{relative_url_root}/}
0
+              if request? && @include_host && source !~ %r{^#{relative_url_root}/}
0
                 "#{relative_url_root}#{source}"
0
               else
0
                 source
...
392
393
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
396
397
...
462
463
464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
466
467
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
0
@@ -392,6 +392,31 @@ class AssetTagHelperTest < ActionView::TestCase
0
     FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
0
   end
0
 
0
+  def test_caching_javascript_include_tag_with_relative_url_root
0
+    ENV["RAILS_ASSET_ID"] = ""
0
+    ActionController::Base.relative_url_root = "/collaboration/hieraki"
0
+    ActionController::Base.perform_caching = true
0
+
0
+    assert_dom_equal(
0
+      %(<script src="/collaboration/hieraki/javascripts/all.js" type="text/javascript"></script>),
0
+      javascript_include_tag(:all, :cache => true)
0
+    )
0
+
0
+    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
0
+
0
+    assert_dom_equal(
0
+      %(<script src="/collaboration/hieraki/javascripts/money.js" type="text/javascript"></script>),
0
+      javascript_include_tag(:all, :cache => "money")
0
+    )
0
+
0
+    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
0
+
0
+  ensure
0
+    ActionController::Base.relative_url_root = nil
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
0
+  end
0
+
0
   def test_caching_javascript_include_tag_when_caching_off
0
     ENV["RAILS_ASSET_ID"] = ""
0
     ActionController::Base.perform_caching = false
0
@@ -462,6 +487,31 @@ class AssetTagHelperTest < ActionView::TestCase
0
     FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
0
   end
0
 
0
+  def test_caching_stylesheet_link_tag_with_relative_url_root
0
+    ENV["RAILS_ASSET_ID"] = ""
0
+    ActionController::Base.relative_url_root = "/collaboration/hieraki"
0
+    ActionController::Base.perform_caching = true
0
+
0
+    assert_dom_equal(
0
+      %(<link href="/collaboration/hieraki/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
0
+      stylesheet_link_tag(:all, :cache => true)
0
+    )
0
+
0
+    expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max
0
+    assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
0
+
0
+    assert_dom_equal(
0
+      %(<link href="/collaboration/hieraki/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
0
+      stylesheet_link_tag(:all, :cache => "money")
0
+    )
0
+
0
+    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
0
+  ensure
0
+    ActionController::Base.relative_url_root = nil
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
0
+    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
0
+  end
0
+
0
   def test_caching_stylesheet_include_tag_when_caching_off
0
     ENV["RAILS_ASSET_ID"] = ""
0
     ActionController::Base.perform_caching = false

Comments