From e824aee1583163e6991edf98c126aa2f463c3b70 Mon Sep 17 00:00:00 2001 From: allenwei Date: Wed, 15 Jun 2011 13:45:02 +0800 Subject: [PATCH 1/4] fix asset cache hit bug --- lib/asset_id/cache.rb | 4 ++-- test/asset_test.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/asset_id/cache.rb b/lib/asset_id/cache.rb index ac96fe1..3f06f7f 100644 --- a/lib/asset_id/cache.rb +++ b/lib/asset_id/cache.rb @@ -8,7 +8,7 @@ def self.empty end def self.cache - @cache ||= YAML.load_file(cache_path) rescue {} + @cache ||= (YAML.load_file(cache_path) rescue {}) end def self.cache_path @@ -34,4 +34,4 @@ def self.save! end end -end \ No newline at end of file +end diff --git a/test/asset_test.rb b/test/asset_test.rb index 8c502d5..4c929cf 100644 --- a/test/asset_test.rb +++ b/test/asset_test.rb @@ -50,6 +50,12 @@ def test_parse_css_with_prefix asset.replace_css_images!(:prefix => 'https://example.com') assert_equal 'body { background: url(https://example.com/images/thundercats-id-982f2a3a4d905189959e848badb4f55b.jpg); }', asset.data end + + def test_cache_hit + assert !AssetID::Cache.hit?(@asset) + assert AssetID::Cache.hit?(@asset) + end + end @@ -57,4 +63,4 @@ class Rails def self.root File.expand_path(File.join(File.dirname(__FILE__), 'sandbox')) end -end \ No newline at end of file +end From b72fb1a27de6723c4352521b4ed943e693ac9e80 Mon Sep 17 00:00:00 2001 From: allenwei Date: Sat, 25 Jun 2011 01:42:14 +0800 Subject: [PATCH 2/4] fix gem spec warning --- asset_id.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/asset_id.gemspec b/asset_id.gemspec index 601c82f..6229826 100644 --- a/asset_id.gemspec +++ b/asset_id.gemspec @@ -10,7 +10,6 @@ Gem::Specification.new do |s| s.description = %q{asset_id is a library for uploading static assets to Amazon S3.} s.email = %q{moomerman@gmail.com} s.files = ["LICENSE", "README.textile","lib/asset_id.rb"] + Dir.glob('lib/asset_id/*.rb') + Dir.glob('lib/asset_id/backend/*.rb') - s.has_rdoc = false s.homepage = %q{http://github.com/moomerman/asset_id} s.rdoc_options = ["--inline-source", "--charset=UTF-8"] s.require_paths = ["lib"] From 021902a78e8d01fbd02f8746b6366a2617e66d82 Mon Sep 17 00:00:00 2001 From: allenwei Date: Mon, 27 Jun 2011 10:20:12 +0800 Subject: [PATCH 3/4] force reload css everytime --- lib/asset_id/cache.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/asset_id/cache.rb b/lib/asset_id/cache.rb index 3f06f7f..8275ff4 100644 --- a/lib/asset_id/cache.rb +++ b/lib/asset_id/cache.rb @@ -20,6 +20,7 @@ def self.get(asset) end def self.hit?(asset) + return false if asset.css? return true if cache[asset.relative_path] and cache[asset.relative_path][:fingerprint] == asset.fingerprint cache[asset.relative_path] = {:expires => asset.expiry_date.to_s, :fingerprint => asset.fingerprint} false From bbc0c2e3ddd914d010a4e318e3523a9b819625c3 Mon Sep 17 00:00:00 2001 From: allenwei Date: Tue, 28 Jun 2011 00:41:24 +0800 Subject: [PATCH 4/4] fix bug in fingerprint for css file --- lib/asset_id/backend/s3.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/asset_id/backend/s3.rb b/lib/asset_id/backend/s3.rb index 947b8a9..b90ddc1 100644 --- a/lib/asset_id/backend/s3.rb +++ b/lib/asset_id/backend/s3.rb @@ -47,6 +47,9 @@ def self.upload(options={}) :access => s3_permissions, }.merge(asset.cache_headers) + #load css md5 before replace_css_images + asset.md5 + asset.replace_css_images!(:prefix => s3_prefix) if asset.css? if asset.gzip_type? @@ -74,4 +77,4 @@ def self.upload(options={}) end end -end \ No newline at end of file +end