Skip to content

Commit

Permalink
Merge pull request #616 from rails/schneems/test-cache-bug
Browse files Browse the repository at this point in the history
Test #614
  • Loading branch information
schneems authored Jul 9, 2019
2 parents 4d6805e + b76abde commit e27d2ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket

## Master

## 4.0.0.beta10

- Fix YACB (Yet Another Caching Bug) [Fix broken expansion of asset link paths](https://github.com/rails/sprockets/pull/614)

## 4.0.0.beta9

- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby verision of Rails [#604]
Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Sprockets
VERSION = "4.0.0.beta9"
VERSION = "4.0.0.beta10"
end
24 changes: 24 additions & 0 deletions test/test_caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,30 @@ def cache.set(key, value, local = false)
environment['schneems.js']
end

test "no relative paths are present in an asset loaded from cache by accident" do
environment = Sprockets::Environment.new(fixture_path('default')) do |env|
env.append_path(".")
env.cache = @cache
end
environment['schneems.js']
asset = environment['schneems.js']
asset_hash = asset.to_hash

refute has_relative_value?(asset_hash), "Expected asset from cache to have no relative paths, but it does:\n#{asset_hash}"
end

def has_relative_value?(elem)
if elem.is_a?(Hash)
return elem.values.detect {|e| has_relative_value?(e) }
end
if elem.respond_to?(:each)
return elem.each.detect {|e| has_relative_value?(e) }
end

return elem.to_s.match(/file:\/\/[^\/]/)
end


test "no absolute paths are retuned from cache" do
env1 = Sprockets::Environment.new(fixture_path('default')) do |env|
env.append_path(".")
Expand Down

0 comments on commit e27d2ff

Please sign in to comment.