Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #614 #616

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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