aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-08-12 20:18:03 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-08-12 20:18:03 -0700
commit1b127fcdea28d6c6ab2f2c6370125c8817ba99d6 (patch)
treebf175900629b88ceb709a1f4df8aca9ec533cacc /actionpack
parent45b79d933cd2433b30ae98e7dadc4ae060e170c9 (diff)
downloadrails-1b127fcdea28d6c6ab2f2c6370125c8817ba99d6.tar.gz
rails-1b127fcdea28d6c6ab2f2c6370125c8817ba99d6.tar.bz2
rails-1b127fcdea28d6c6ab2f2c6370125c8817ba99d6.zip
Set asset-cached file ctime and mtime to the max mtime of the combined files. Allows for consistent ETag generation without having a shared filesystem.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb5
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb3
2 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 1e44b166d9..c2b4f51c9c 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -618,6 +618,11 @@ module ActionView
def write_asset_file_contents(joined_asset_path, asset_paths)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
+
+ # Set mtime to the latest of the combined files to allow for
+ # consistent ETag without a shared filesystem.
+ mt = asset_paths.map { |p| File.mtime(File.join(ASSETS_DIR, p)) }.max
+ File.utime(mt, mt, joined_asset_path)
end
def collect_asset_files(*path)
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 8410e82c3c..7e40a55dc5 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -425,7 +425,8 @@ class AssetTagHelperTest < ActionView::TestCase
stylesheet_link_tag(:all, :cache => true)
)
- assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
+ expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max
+ assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
assert_dom_equal(
%(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),