Skip to content
This repository
Browse code

Ensure cache directory exists

Fixes #244
  • Loading branch information...
commit 4b5f0d505dac980e2b59e4f294f4aac15ab1562c 1 parent 1b1d6d6
Joshua Peek authored November 16, 2011
8  lib/sprockets/cache/file_store.rb
@@ -6,14 +6,11 @@ module Sprockets
6 6
   module Cache
7 7
     # A simple file system cache store.
8 8
     #
9  
-    #     environment.cache = Sprockets::Cache::FileStore.new("tmp/sprockets")
  9
+    #     environment.cache = Sprockets::Cache::FileStore.new("/tmp")
10 10
     #
11 11
     class FileStore
12 12
       def initialize(root)
13 13
         @root = Pathname.new(root)
14  
-
15  
-        # Ensure directory exists
16  
-        FileUtils.mkdir_p @root
17 14
       end
18 15
 
19 16
       # Lookup value in cache
@@ -24,6 +21,9 @@ def [](key)
24 21
 
25 22
       # Save value to cache
26 23
       def []=(key, value)
  24
+        # Ensure directory exists
  25
+        FileUtils.mkdir_p @root.join(key).dirname
  26
+
27 27
         @root.join(key).open('w') { |f| Marshal.dump(value, f)}
28 28
         value
29 29
       end
30  test/test_caching.rb
@@ -180,3 +180,33 @@ def setup
180 180
     end
181 181
   end
182 182
 end
  183
+
  184
+require 'tmpdir'
  185
+
  186
+class TestFileStore < Sprockets::TestCase
  187
+  def setup
  188
+    @cache = Sprockets::Cache::FileStore.new(Dir::tmpdir)
  189
+
  190
+    @env1 = Sprockets::Environment.new(fixture_path('default')) do |env|
  191
+      env.append_path(".")
  192
+      env.cache = @cache
  193
+    end
  194
+
  195
+    @env2 = Sprockets::Environment.new(fixture_path('symlink')) do |env|
  196
+      env.append_path(".")
  197
+      env.cache = @cache
  198
+    end
  199
+  end
  200
+
  201
+  test "shared cache objects are eql" do
  202
+    asset1 = @env1['gallery.js']
  203
+    asset2 = @env2['gallery.js']
  204
+
  205
+    assert asset1
  206
+    assert asset2
  207
+
  208
+    assert asset1.eql?(asset2)
  209
+    assert asset2.eql?(asset1)
  210
+    assert !asset1.equal?(asset2)
  211
+  end
  212
+end

0 notes on commit 4b5f0d5

Please sign in to comment.
Something went wrong with that request. Please try again.