Skip to content

Commit

Permalink
Merge pull request #404 from lime/version-affects-digest
Browse files Browse the repository at this point in the history
Make environment version affect asset digest
  • Loading branch information
schneems authored Oct 17, 2016
2 parents 3856945 + 64fadf9 commit 0488a02
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md

## Next Release

- Changing the version now busts the digest of all assets [#404]

## 4.0.0.beta3

- Source Map fixes [#255] [#367]
Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def load_from_unloaded(unloaded)
source = result.delete(:data)
metadata = result
metadata[:charset] = source.encoding.name.downcase unless metadata.key?(:charset)
metadata[:digest] = digest(source)
metadata[:digest] = digest(self.version + source)
metadata[:length] = source.bytesize
else
dependencies << build_file_digest_uri(unloaded.filename)
Expand Down
4 changes: 2 additions & 2 deletions test/test_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@ def setup
assert_equal 2, asset.metadata[:selector_count]
end

test "changing version doesn't affect the assets digest" do
test "changing version changes the digest of the asset" do
old_asset_digest = @env["gallery.js"].hexdigest
@env.version = 'v2'
assert old_asset_digest == @env["gallery.js"].hexdigest
assert old_asset_digest != @env["gallery.js"].hexdigest
end

test "bundled asset is stale if its mtime is updated or deleted" do
Expand Down

0 comments on commit 0488a02

Please sign in to comment.