Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure cache directory exists

Fixes #244
  • Loading branch information...
commit 4b5f0d505dac980e2b59e4f294f4aac15ab1562c 1 parent 1b1d6d6
Joshua Peek josh authored
Showing with 34 additions and 4 deletions.
  1. +4 −4 lib/sprockets/cache/file_store.rb
  2. +30 −0 test/test_caching.rb
8 lib/sprockets/cache/file_store.rb
View
@@ -6,14 +6,11 @@ module Sprockets
module Cache
# A simple file system cache store.
#
- # environment.cache = Sprockets::Cache::FileStore.new("tmp/sprockets")
+ # environment.cache = Sprockets::Cache::FileStore.new("/tmp")
#
class FileStore
def initialize(root)
@root = Pathname.new(root)
-
- # Ensure directory exists
- FileUtils.mkdir_p @root
end
# Lookup value in cache
@@ -24,6 +21,9 @@ def [](key)
# Save value to cache
def []=(key, value)
+ # Ensure directory exists
+ FileUtils.mkdir_p @root.join(key).dirname
+
@root.join(key).open('w') { |f| Marshal.dump(value, f)}
value
end
30 test/test_caching.rb
View
@@ -180,3 +180,33 @@ def setup
end
end
end
+
+require 'tmpdir'
+
+class TestFileStore < Sprockets::TestCase
+ def setup
+ @cache = Sprockets::Cache::FileStore.new(Dir::tmpdir)
+
+ @env1 = Sprockets::Environment.new(fixture_path('default')) do |env|
+ env.append_path(".")
+ env.cache = @cache
+ end
+
+ @env2 = Sprockets::Environment.new(fixture_path('symlink')) do |env|
+ env.append_path(".")
+ env.cache = @cache
+ end
+ end
+
+ test "shared cache objects are eql" do
+ asset1 = @env1['gallery.js']
+ asset2 = @env2['gallery.js']
+
+ assert asset1
+ assert asset2
+
+ assert asset1.eql?(asset2)
+ assert asset2.eql?(asset1)
+ assert !asset1.equal?(asset2)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.