Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Include dependency paths when calculating mtime
  • Loading branch information...
commit fdb576f8dabcc7041cec2f5f171927ce725f100b 2 parents 13bef85 + 34ea8f4
@josh josh authored
View
7 lib/sprockets/bundled_asset.rb
@@ -13,8 +13,9 @@ class BundledAsset < Asset
def initialize(environment, logical_path, pathname)
super(environment, logical_path, pathname)
- @processed_asset = environment.find_asset(pathname, :bundle => false)
- @required_assets = @processed_asset.required_assets
+ @processed_asset = environment.find_asset(pathname, :bundle => false)
+ @required_assets = @processed_asset.required_assets
+ @dependency_paths = @processed_asset.dependency_paths
@source = ""
@@ -26,7 +27,7 @@ def initialize(environment, logical_path, pathname)
@source = context.evaluate(pathname, :data => @source,
:processors => environment.bundle_processors(content_type))
- @mtime = to_a.map(&:mtime).max
+ @mtime = (to_a + @dependency_paths).map(&:mtime).max
@length = Rack::Utils.bytesize(source)
@digest = environment.digest.update(source).hexdigest
end
View
1  test/fixtures/asset/dependencies/a.js
@@ -0,0 +1 @@
+var A = {};
View
1  test/fixtures/asset/dependencies/b.js
@@ -0,0 +1 @@
+var B = {};
View
1  test/fixtures/asset/dependencies/c.js
@@ -0,0 +1 @@
+var C = {};
View
3  test/fixtures/asset/dependency_paths.js.erb
@@ -0,0 +1,3 @@
+<% depend_on('dependencies/a.js') %>
+<% depend_on('dependencies/b.js') %>
+<% depend_on('dependencies/c.js') %>
View
3  test/fixtures/asset/required_assets.js
@@ -0,0 +1,3 @@
+//= require dependencies/a
+//= require dependencies/b
+//= require dependencies/c
View
20 test/test_asset.rb
@@ -577,6 +577,26 @@ def setup
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
end
+ test "mtime is based on required assets" do
+ required_asset = fixture_path('asset/dependencies/b.js')
+
+ sandbox required_asset do
+ mtime = Time.now + 1
+ File.utime mtime, mtime, required_asset
+ assert_equal mtime.to_i, asset('required_assets.js').mtime.to_i
+ end
+ end
+
+ test "mtime is based on dependency paths" do
+ asset_dependency = fixture_path('asset/dependencies/b.js')
+
+ sandbox asset_dependency do
+ mtime = Time.now + 1
+ File.utime mtime, mtime, asset_dependency
+ assert_equal mtime.to_i, asset('dependency_paths.js').mtime.to_i
+ end
+ end
+
test "requiring the same file multiple times has no effect" do
assert_equal read("project.js")+"\n\n\n", asset("multiple.js").to_s
end
Please sign in to comment.
Something went wrong with that request. Please try again.