Skip to content

Commit

Permalink
Environment#version will no longer affect asset digests
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 23, 2014
1 parent ca816ea commit 07e5e29
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 42 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ submit a pull request.

**3.0.0**

* Environment#version no longer affects asset digests. Only used for busting the asset cache.
* Removed builtin support for LESS.
* Removed include directive support.

Expand Down
23 changes: 1 addition & 22 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,6 @@ def version=(version)
@version = version
end

# Returns a `Digest` instance for the `Environment`.
#
# This value serves two purposes. If two `Environment`s have the
# same digest value they can be treated as equal. This is more
# useful for comparing environment states between processes rather
# than in the same. Two equal `Environment`s can share the same
# cached assets.
#
# The value also provides a seed digest for all `Asset`
# digests. Any change in the environment digest will affect all of
# its assets.
def digest
# Compute the initial digest using the implementation class. The
# Sprockets release version and custom environment version are
# mixed in. So any new releases will affect all your assets.
@digest ||= digest_class.new.update(version.to_s)

# Returned a dupped copy so the caller can safely mutate it with `.update`
@digest.dup
end

# Get and set `Logger` instance.
attr_accessor :logger

Expand Down Expand Up @@ -386,7 +365,7 @@ def build_static_asset_hash(asset)
type: 'static',
length: stat.size,
mtime: stat.mtime.to_i,
digest: digest.file(asset[:filename]).hexdigest,
digest: digest_class.file(asset[:filename]).hexdigest,
dependency_digest: dependencies_hexdigest([asset[:filename]]),
dependency_paths: [asset[:filename]]
})
Expand Down
1 change: 0 additions & 1 deletion lib/sprockets/cached_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def initialize(environment)
@context_class = environment.context_class
@cache = environment.cache
@trail = environment.trail.cached
@digest = environment.digest
@digest_class = environment.digest_class
@version = environment.version
@mime_types = environment.mime_types
Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def process(processors, filename, logical_path, content_type, data)
{
source: data,
length: data.bytesize,
digest: digest.update(data).hexdigest, # FIXME: Avoid Env#digest
digest: digest_class.hexdigest(data),
required_paths: required_paths,
stubbed_paths: stubbed_paths.to_a,
dependency_paths: dependency_paths.to_a
Expand Down
2 changes: 1 addition & 1 deletion test/test_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.test(name, &block)
end

test "digest is source digest" do
assert_equal @env.digest.update(@asset.to_s).hexdigest, @asset.digest
assert_equal Digest::SHA1.hexdigest(@asset.to_s), @asset.digest
end

test "length is source length" do
Expand Down
19 changes: 2 additions & 17 deletions test/test_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,25 +492,10 @@ def setup
assert_nil @env.css_compressor
end

test "changing digest implementation class" do
old_digest = @env.digest
test "changing version doesn't affect the assets digest" do
old_asset_digest = @env["gallery.js"].digest

@env.digest_class = Digest::MD5
@env.version = 'md5'

assert old_digest != @env.digest
assert old_asset_digest != @env["gallery.js"].digest
end

test "changing digest version" do
old_digest = @env.digest
old_asset_digest = @env["gallery.js"].digest

@env.version = 'v2'

assert old_digest != @env.digest
assert old_asset_digest != @env["gallery.js"].digest
assert old_asset_digest == @env["gallery.js"].digest
end

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

0 comments on commit 07e5e29

Please sign in to comment.