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"] 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 diff --git a/lib/asset_id/cache.rb b/lib/asset_id/cache.rb index ac96fe1..8275ff4 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 @@ -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 @@ -34,4 +35,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