diff --git a/lib/propshaft/asset.rb b/lib/propshaft/asset.rb index d819f73..3e0a6ed 100644 --- a/lib/propshaft/asset.rb +++ b/lib/propshaft/asset.rb @@ -30,7 +30,7 @@ def length end def digest - @digest ||= Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8) + @digest ||= perform_digest("#{content_with_compile_references}#{load_path.version}") end def digested_path @@ -57,4 +57,8 @@ def content_with_compile_references def already_digested? logical_path.to_s =~ /-([0-9a-zA-Z_-]{7,128})\.digested/ end + + def perform_digest(text) + Digest::SHA1.hexdigest(text).first(8) + end end diff --git a/test/propshaft/asset_test.rb b/test/propshaft/asset_test.rb index d7e34ab..4fa12e6 100644 --- a/test/propshaft/asset_test.rb +++ b/test/propshaft/asset_test.rb @@ -27,6 +27,19 @@ class Propshaft::AssetTest < ActiveSupport::TestCase assert_equal "f2e1ec14", find_asset("one.txt").digest end + test "digest override" do + original_digest = ::Propshaft::Asset.instance_method(:perform_digest) + module ::Propshaft + class Asset + def perform_digest(text) + Digest::SHA1.hexdigest(text).first(10) + end + end + end + assert_equal 10, find_asset("one.txt").digest.size + ::Propshaft::Asset.define_method(:perform_digest, original_digest) + end + test "fresh" do assert find_asset("one.txt").fresh?("f2e1ec14") assert_not find_asset("one.txt").fresh?("e206c34f")