Skip to content

Commit

Permalink
Test for #141
Browse files Browse the repository at this point in the history
When mutating objects from the cache, sometimes those objects are placed back into the cache leading to accidental absolute paths.

This commit verifies that no absolute paths are accidentally stored in the cache.
  • Loading branch information
schneems committed Sep 25, 2015
1 parent 4447e6a commit 6cd8e04
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/test_caching.rb
Expand Up @@ -427,6 +427,41 @@ def teardown
end
end

test "history cache is not poluted" do
dependency_file = File.join(fixture_path('asset'), "dependencies", "a.js")
env1 = Sprockets::Environment.new(fixture_path('asset')) do |env|
env.append_path(".")
env.cache = @cache
end
env1['required_assets.js']

sandbox dependency_file do
write(dependency_file, "var aa = 2;")
env1['required_assets.js']

# We must use private APIs to test this behavior
# https://github.com/rails/sprockets/pull/141
cache_entries = @cache.send(:find_caches).map do |file, _|
key = file.gsub(/\.cache\z/, ''.freeze).split(@cache_dir).last
result = @cache.get(key)

if result.is_a?(Array)
result if result.first.is_a?(Set)
else
nil
end
end.compact

assert cache_entries.any?

cache_entries.each do |sets|
sets.each do |set|
refute set.any? {|uri| uri.include?(env1.root) }, "Expected entry in cache to not include absolute paths but did: #{set.inspect}"
end
end
end
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 6cd8e04

Please sign in to comment.