Skip to content
This repository
Browse code

Merge pull request #325 from petebrowne/dependency-paths-mtime

Include dependency paths when calculating mtime
  • Loading branch information...
commit fdb576f8dabcc7041cec2f5f171927ce725f100b 2 parents 13bef85 + 34ea8f4
Joshua Peek authored May 09, 2012
7  lib/sprockets/bundled_asset.rb
@@ -13,8 +13,9 @@ class BundledAsset < Asset
13 13
     def initialize(environment, logical_path, pathname)
14 14
       super(environment, logical_path, pathname)
15 15
 
16  
-      @processed_asset = environment.find_asset(pathname, :bundle => false)
17  
-      @required_assets = @processed_asset.required_assets
  16
+      @processed_asset  = environment.find_asset(pathname, :bundle => false)
  17
+      @required_assets  = @processed_asset.required_assets
  18
+      @dependency_paths = @processed_asset.dependency_paths
18 19
 
19 20
       @source = ""
20 21
 
@@ -26,7 +27,7 @@ def initialize(environment, logical_path, pathname)
26 27
       @source = context.evaluate(pathname, :data => @source,
27 28
                   :processors => environment.bundle_processors(content_type))
28 29
 
29  
-      @mtime  = to_a.map(&:mtime).max
  30
+      @mtime  = (to_a + @dependency_paths).map(&:mtime).max
30 31
       @length = Rack::Utils.bytesize(source)
31 32
       @digest = environment.digest.update(source).hexdigest
32 33
     end
1  test/fixtures/asset/dependencies/a.js
... ...
@@ -0,0 +1 @@
  1
+var A = {};
1  test/fixtures/asset/dependencies/b.js
... ...
@@ -0,0 +1 @@
  1
+var B = {};
1  test/fixtures/asset/dependencies/c.js
... ...
@@ -0,0 +1 @@
  1
+var C = {};
3  test/fixtures/asset/dependency_paths.js.erb
... ...
@@ -0,0 +1,3 @@
  1
+<% depend_on('dependencies/a.js') %>
  2
+<% depend_on('dependencies/b.js') %>
  3
+<% depend_on('dependencies/c.js') %>
3  test/fixtures/asset/required_assets.js
... ...
@@ -0,0 +1,3 @@
  1
+//= require dependencies/a
  2
+//= require dependencies/b
  3
+//= require dependencies/c
20  test/test_asset.rb
@@ -577,6 +577,26 @@ def setup
577 577
     assert_equal "var Project = {\n  find: function(id) {\n  }\n};\nvar Users = {\n  find: function(id) {\n  }\n};\n\n\n\ndocument.on('dom:loaded', function() {\n  $('search').focus();\n});\n", body
578 578
   end
579 579
 
  580
+  test "mtime is based on required assets" do
  581
+    required_asset = fixture_path('asset/dependencies/b.js')
  582
+
  583
+    sandbox required_asset do
  584
+      mtime = Time.now + 1
  585
+      File.utime mtime, mtime, required_asset
  586
+      assert_equal mtime.to_i, asset('required_assets.js').mtime.to_i
  587
+    end
  588
+  end
  589
+
  590
+  test "mtime is based on dependency paths" do
  591
+    asset_dependency = fixture_path('asset/dependencies/b.js')
  592
+
  593
+    sandbox asset_dependency do
  594
+      mtime = Time.now + 1
  595
+      File.utime mtime, mtime, asset_dependency
  596
+      assert_equal mtime.to_i, asset('dependency_paths.js').mtime.to_i
  597
+    end
  598
+  end
  599
+
580 600
   test "requiring the same file multiple times has no effect" do
581 601
     assert_equal read("project.js")+"\n\n\n", asset("multiple.js").to_s
582 602
   end

0 notes on commit fdb576f

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