Skip to content

Commit

Permalink
Merge pull request rails#325 from petebrowne/dependency-paths-mtime
Browse files Browse the repository at this point in the history
Include dependency paths when calculating mtime
  • Loading branch information
josh committed May 10, 2012
2 parents 13bef85 + 34ea8f4 commit fdb576f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/sprockets/bundled_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/asset/dependencies/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var A = {};
1 change: 1 addition & 0 deletions test/fixtures/asset/dependencies/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var B = {};
1 change: 1 addition & 0 deletions test/fixtures/asset/dependencies/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var C = {};
3 changes: 3 additions & 0 deletions test/fixtures/asset/dependency_paths.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% depend_on('dependencies/a.js') %>
<% depend_on('dependencies/b.js') %>
<% depend_on('dependencies/c.js') %>
3 changes: 3 additions & 0 deletions test/fixtures/asset/required_assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= require dependencies/a
//= require dependencies/b
//= require dependencies/c
20 changes: 20 additions & 0 deletions test/test_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdb576f

Please sign in to comment.