The following code which is part of
test_caching_stylesheet_link_tag_when_caching_on and
test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
does nothing more than check that the mtime of
all.css is the same as the mtime of
all.css because the directory wildcard used actually
includes 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'))
The wildcard should be changed to exclude all.css
thus
expected =
Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/[^all]*.css"].map {|p| File.mtime(p) }.max
assert_equal expected,
File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
I've also added a bit more to the test case to ensure that the
size of all.css is the size of all the stylesheets to
be joined plus the two new lines per file minus two, as added by
the .join("\n\n")
bytes_added_by_join = "\n\n".size * files_to_be_joined.size - "\n\n".size
expected_size = files_to_be_joined.sum { |p| File.size(p) } + bytes_added_by_join
assert_equal expected_size, File.size(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
This second improvement is really only necessary for the test
case added by my related patch #2738 [PATCH] Fix zero length stylesheet cache files bug in case of missing CSS files but
benefits the above two test cases as well.