diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c6bc87a..2a059da 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "name": "Ruby", "build": { "dockerfile": "Dockerfile", - "args": { + "args": { // Update 'VARIANT' to pick a Ruby version: 3, 3.0, 2, 2.7, 2.6 // Append -bullseye or -buster to pin to an OS version. // Use -bullseye variants on local on arm64/Apple Silicon. @@ -14,14 +14,17 @@ } }, - // Set *default* container specific settings.json values on container create. - "settings": {}, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "Shopify.ruby-lsp" + ] + } + }, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "rebornix.Ruby" - ], - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92c9e54..2d4abb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: continue-on-error: ${{ matrix.continue-on-error }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Ruby uses: ruby/setup-ruby@v1 diff --git a/Gemfile.lock b/Gemfile.lock index 0ce96c0..e891d66 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - propshaft (0.7.0) + propshaft (0.8.0) actionpack (>= 7.0.0) activesupport (>= 7.0.0) rack diff --git a/README.md b/README.md index f5f2c41..bdb83bb 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ But for greenfield apps using the default import-map approach, Propshaft can als ## Will Propshaft replace Sprockets as the Rails default? -Most likely, but Sprockets need to be supported as well for a long time to come. Plenty of apps and gems were built on Sprocket features, and they won't be migrating soon. Still working out the compatibility story. This is very much beta software at the moment. +Most likely, but Sprockets needs to be supported as well for a long time to come. Plenty of apps and gems were built on Sprocket features, and they won't be migrating soon. Still working out the compatibility story. This is very much beta software at the moment. ## License diff --git a/UPGRADING.md b/UPGRADING.md index 8f5b1c1..2609807 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -253,8 +253,8 @@ Rails.application.assets.load_path.find('logo.svg').content As Rails escapes html tags in views by default, in order to output a rendered svg you will need to specify rails not to escape the string using [html_safe](https://api.rubyonrails.org/classes/String.html#method-i-html_safe) or [raw](https://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw). ```ruby -Rails.application.assets.load_path.find('logo.svg').html_safe -raw Rails.application.assets.load_path.find('logo.svg') +Rails.application.assets.load_path.find('logo.svg').content.html_safe +raw Rails.application.assets.load_path.find('logo.svg').content ``` **Precompilation in development** diff --git a/lib/propshaft/asset.rb b/lib/propshaft/asset.rb index 6278df0..759523f 100644 --- a/lib/propshaft/asset.rb +++ b/lib/propshaft/asset.rb @@ -21,7 +21,7 @@ def length end def digest - @digest ||= Digest::SHA1.hexdigest("#{content}#{version}") + @digest ||= Digest::SHA1.hexdigest("#{content}#{version}").first(8) end def digested_path @@ -42,6 +42,6 @@ def ==(other_asset) private def already_digested? - logical_path.to_s =~ /-([0-9a-zA-Z]{7,128})\.digested/ + logical_path.to_s =~ /-([0-9a-zA-Z_-]{7,128})\.digested/ end end diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index 0a32d90..a0b678d 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -6,7 +6,7 @@ class Propshaft::Compiler::SourceMappingUrls < Propshaft::Compiler SOURCE_MAPPING_PATTERN = %r{(//|/\*)# sourceMappingURL=(.+\.map)(\s*?\*\/)?\s*?\Z} def compile(logical_path, input) - input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset_path($2, logical_path), $1, $3) } + input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(logical_path, asset_path($2, logical_path), $1, $3) } end private @@ -18,11 +18,11 @@ def asset_path(source_mapping_url, logical_path) end end - def source_mapping_url(resolved_path, comment_start, comment_end) + def source_mapping_url(logical_path, resolved_path, comment_start, comment_end) if asset = assembly.load_path.find(resolved_path) "#{comment_start}# sourceMappingURL=#{url_prefix}/#{asset.digested_path}#{comment_end}" else - Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{resolved_path}" + Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{logical_path}" "#{comment_start}#{comment_end}" end end diff --git a/lib/propshaft/processor.rb b/lib/propshaft/processor.rb index 8352584..c4f8560 100644 --- a/lib/propshaft/processor.rb +++ b/lib/propshaft/processor.rb @@ -20,8 +20,8 @@ def clobber FileUtils.rm_r(output_path) if File.exist?(output_path) end - def clean - Propshaft::OutputPath.new(output_path, load_path.manifest).clean(2, 1.hour) + def clean(count) + Propshaft::OutputPath.new(output_path, load_path.manifest).clean(count, 1.hour) end private diff --git a/lib/propshaft/railties/assets.rake b/lib/propshaft/railties/assets.rake index 6af2f04..ce804b9 100644 --- a/lib/propshaft/railties/assets.rake +++ b/lib/propshaft/railties/assets.rake @@ -14,8 +14,9 @@ namespace :assets do end desc "Removes old files in config.assets.output_path" - task clean: :environment do - Rails.application.assets.processor.clean + task :clean, [:count] => [:environment] do |_, args| + count = args.fetch(:count, 2) + Rails.application.assets.processor.clean(count.to_i) end desc "Print all the assets available in config.assets.paths" diff --git a/lib/propshaft/server.rb b/lib/propshaft/server.rb index 254120c..9267fcd 100644 --- a/lib/propshaft/server.rb +++ b/lib/propshaft/server.rb @@ -1,4 +1,5 @@ require "rack/utils" +require "rack/version" class Propshaft::Server def initialize(assembly) diff --git a/lib/propshaft/version.rb b/lib/propshaft/version.rb index 71c5bf1..70b773b 100644 --- a/lib/propshaft/version.rb +++ b/lib/propshaft/version.rb @@ -1,3 +1,3 @@ module Propshaft - VERSION = "0.7.0" + VERSION = "0.8.0" end diff --git a/test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789.digested.css b/test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789_-.digested.css similarity index 100% rename from test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789.digested.css rename to test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789_-.digested.css diff --git a/test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789.digested.debug.css b/test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789_-.digested.debug.css similarity index 100% rename from test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789.digested.debug.css rename to test/fixtures/assets/first_path/file-already-abcdefVWXYZ0123456789_-.digested.debug.css diff --git a/test/fixtures/output/.manifest.json b/test/fixtures/output/.manifest.json index 0b8b48a..ec2b100 100644 --- a/test/fixtures/output/.manifest.json +++ b/test/fixtures/output/.manifest.json @@ -1 +1 @@ -{ "one.txt": "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt" } +{ "one.txt": "one-f2e1ec14.txt" } diff --git a/test/fixtures/output/one-f2e1ec14d6856e1958083094170ca6119c529a73.txt b/test/fixtures/output/one-f2e1ec14.txt similarity index 100% rename from test/fixtures/output/one-f2e1ec14d6856e1958083094170ca6119c529a73.txt rename to test/fixtures/output/one-f2e1ec14.txt diff --git a/test/propshaft/asset_test.rb b/test/propshaft/asset_test.rb index 702a209..6d27ec1 100644 --- a/test/propshaft/asset_test.rb +++ b/test/propshaft/asset_test.rb @@ -18,27 +18,27 @@ class Propshaft::AssetTest < ActiveSupport::TestCase end test "digest" do - assert_equal "f2e1ec14d6856e1958083094170ca6119c529a73", find_asset("one.txt").digest + assert_equal "f2e1ec14", find_asset("one.txt").digest end test "fresh" do - assert find_asset("one.txt").fresh?("f2e1ec14d6856e1958083094170ca6119c529a73") - assert_not find_asset("one.txt").fresh?("e206c34fe404c8e2f25d60dd8303f61c02b8d381") + assert find_asset("one.txt").fresh?("f2e1ec14") + assert_not find_asset("one.txt").fresh?("e206c34f") - assert find_asset("file-already-abcdefVWXYZ0123456789.digested.css").fresh?(nil) + assert find_asset("file-already-abcdefVWXYZ0123456789_-.digested.css").fresh?(nil) end test "digested path" do - assert_equal "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt", + assert_equal "one-f2e1ec14.txt", find_asset("one.txt").digested_path.to_s - assert_equal "file-already-abcdefVWXYZ0123456789.digested.css", - find_asset("file-already-abcdefVWXYZ0123456789.digested.css").digested_path.to_s + assert_equal "file-already-abcdefVWXYZ0123456789_-.digested.css", + find_asset("file-already-abcdefVWXYZ0123456789_-.digested.css").digested_path.to_s - assert_equal "file-already-abcdefVWXYZ0123456789.digested.debug.css", - find_asset("file-already-abcdefVWXYZ0123456789.digested.debug.css").digested_path.to_s + assert_equal "file-already-abcdefVWXYZ0123456789_-.digested.debug.css", + find_asset("file-already-abcdefVWXYZ0123456789_-.digested.debug.css").digested_path.to_s - assert_equal "file-not.digested-e206c34fe404c8e2f25d60dd8303f61c02b8d381.css", + assert_equal "file-not.digested-e206c34f.css", find_asset("file-not.digested.css").digested_path.to_s end diff --git a/test/propshaft/compiler/css_asset_urls_test.rb b/test/propshaft/compiler/css_asset_urls_test.rb index 1047a2d..4187682 100644 --- a/test/propshaft/compiler/css_asset_urls_test.rb +++ b/test/propshaft/compiler/css_asset_urls_test.rb @@ -15,62 +15,62 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase test "basic" do compiled = compile_asset_with_content(%({ background: url(file.jpg); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "blank spaces around name" do compiled = compile_asset_with_content(%({ background: url( file.jpg ); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "quotes around name" do compiled = compile_asset_with_content(%({ background: url("file.jpg"); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "single quotes around name" do compiled = compile_asset_with_content(%({ background: url('file.jpg'); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "root directory" do compiled = compile_asset_with_content(%({ background: url('/file.jpg'); })) - assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "same directory" do compiled = compile_asset_with_content(%({ background: url('./file.jpg'); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "subdirectory" do compiled = compile_asset_with_content(%({ background: url('./images/file.jpg'); })) - assert_match(/{ background: url\("\/assets\/foobar\/source\/images\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/source\/images\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "parent directory" do compiled = compile_asset_with_content(%({ background: url('../file.jpg'); })) - assert_match(/{ background: url\("\/assets\/foobar\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "grandparent directory" do compiled = compile_asset_with_content(%({ background: url('../../file.jpg'); })) - assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "sibling directory" do compiled = compile_asset_with_content(%({ background: url('../sibling/file.jpg'); })) - assert_match(/{ background: url\("\/assets\/foobar\/sibling\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/foobar\/sibling\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end test "mixed" do compiled = compile_asset_with_content(%({ mask-image: image(url(file.jpg), skyblue, linear-gradient(rgba(0, 0, 0, 1.0), transparent)); })) - assert_match(/{ mask-image: image\(url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\), skyblue, linear-gradient\(rgba\(0, 0, 0, 1.0\), transparent\)\); }/, compiled) + assert_match(/{ mask-image: image\(url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\), skyblue, linear-gradient\(rgba\(0, 0, 0, 1.0\), transparent\)\); }/, compiled) end test "multiple" do compiled = compile_asset_with_content(%({ content: url(file.svg) url(file.svg); })) - assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.svg"\) url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.svg"\); }/, compiled) + assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.svg"\) url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.svg"\); }/, compiled) end test "url" do @@ -95,12 +95,12 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase test "fingerprint" do compiled = compile_asset_with_content(%({ background: url('/file.jpg?30af91bf14e37666a085fb8a161ff36d'); })) - assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{40}.jpg\?30af91bf14e37666a085fb8a161ff36d"\); }/, compiled) + assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{8}.jpg\?30af91bf14e37666a085fb8a161ff36d"\); }/, compiled) end test "svg anchor" do compiled = compile_asset_with_content(%({ content: url(file.svg#rails); })) - assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.svg#rails"\); }/, compiled) + assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.svg#rails"\); }/, compiled) end test "svg mask encoded anchor" do @@ -110,7 +110,7 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase test "non greedy anchors" do compiled = compile_asset_with_content(%({ content: url(file.svg#demo) url(file.svg#demo); })) - assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.svg#demo"\) url\("\/assets\/foobar\/source\/file-[a-z0-9]{40}.svg#demo"\); }/, compiled) + assert_match(/{ content: url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.svg#demo"\) url\("\/assets\/foobar\/source\/file-[a-z0-9]{8}.svg#demo"\); }/, compiled) end test "missing asset" do @@ -122,7 +122,7 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase @options.relative_url_root = "/url-root" compiled = compile_asset_with_content(%({ background: url(file.jpg); })) - assert_match(/{ background: url\("\/url-root\/assets\/foobar\/source\/file-[a-z0-9]{40}.jpg"\); }/, compiled) + assert_match(/{ background: url\("\/url-root\/assets\/foobar\/source\/file-[a-z0-9]{8}.jpg"\); }/, compiled) end private diff --git a/test/propshaft/compiler/source_mapping_urls_test.rb b/test/propshaft/compiler/source_mapping_urls_test.rb index 1b10e4b..c881f4d 100644 --- a/test/propshaft/compiler/source_mapping_urls_test.rb +++ b/test/propshaft/compiler/source_mapping_urls_test.rb @@ -14,14 +14,14 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase end test "matching source map" do - assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{40}\.map}, + assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{8}\.map}, compile_asset(find_asset("source.js", fixture_path: "mapped")) - assert_match %r{/\*# sourceMappingURL=/assets/source.css-[a-z0-9]{40}\.map}, + assert_match %r{/\*# sourceMappingURL=/assets/source.css-[a-z0-9]{8}\.map}, compile_asset(find_asset("source.css", fixture_path: "mapped")) end test "matching nested source map" do - assert_match %r{//# sourceMappingURL=/assets/nested/another-source.js-[a-z0-9]{40}\.map}, + assert_match %r{//# sourceMappingURL=/assets/nested/another-source.js-[a-z0-9]{8}\.map}, compile_asset(find_asset("nested/another-source.js", fixture_path: "mapped")) end @@ -38,9 +38,9 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase end test "sourceMappingURL not at the beginning of the line, but at end of file, is processed" do - assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-not-at-start.js-[a-z0-9]{40}\.map}, + assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-not-at-start.js-[a-z0-9]{8}\.map}, compile_asset(find_asset("sourceMappingURL-not-at-start.js", fixture_path: "mapped")) - assert_match %r{/\*# sourceMappingURL=/assets/sourceMappingURL-not-at-start.css-[a-z0-9]{40}\.map \*/}, + assert_match %r{/\*# sourceMappingURL=/assets/sourceMappingURL-not-at-start.css-[a-z0-9]{8}\.map \*/}, compile_asset(find_asset("sourceMappingURL-not-at-start.css", fixture_path: "mapped")) end @@ -56,7 +56,7 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase test "relative url root" do @options.relative_url_root = "/url-root" - assert_match %r{//# sourceMappingURL=/url-root/assets/source.js-[a-z0-9]{40}\.map}, + assert_match %r{//# sourceMappingURL=/url-root/assets/source.js-[a-z0-9]{8}\.map}, compile_asset(find_asset("source.js", fixture_path: "mapped")) end diff --git a/test/propshaft/compilers_test.rb b/test/propshaft/compilers_test.rb index 83a4fb2..c604c70 100644 --- a/test/propshaft/compilers_test.rb +++ b/test/propshaft/compilers_test.rb @@ -14,7 +14,7 @@ class Propshaft::CompilersTest < ActiveSupport::TestCase test "replace asset-path function in css with digested url" do @assembly.compilers.register "text/css", Propshaft::Compiler::CssAssetUrls - assert_match(/"\/assets\/archive-[a-z0-9]{40}.svg/, @assembly.compilers.compile(find_asset("another.css"))) + assert_match(/"\/assets\/archive-[a-z0-9]{8}.svg/, @assembly.compilers.compile(find_asset("another.css"))) end private diff --git a/test/propshaft/load_path_test.rb b/test/propshaft/load_path_test.rb index 8ab8cf4..88bb003 100644 --- a/test/propshaft/load_path_test.rb +++ b/test/propshaft/load_path_test.rb @@ -38,16 +38,16 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase test "manifest" do @load_path.manifest.tap do |manifest| - assert_equal "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt", manifest["one.txt"] - assert_equal "nested/three-6c2b86a0206381310375abdd9980863c2ea7b2c3.txt", manifest["nested/three.txt"] + assert_equal "one-f2e1ec14.txt", manifest["one.txt"] + assert_equal "nested/three-6c2b86a0.txt", manifest["nested/three.txt"] end end test "manifest with version" do @load_path = Propshaft::LoadPath.new(@load_path.paths, version: "1") @load_path.manifest.tap do |manifest| - assert_equal "one-c9373b685d5a63e4a1de7c6836a73239df552e2b.txt", manifest["one.txt"] - assert_equal "nested/three-a41a5d38da5afe428eca74b243f50405f28a6b54.txt", manifest["nested/three.txt"] + assert_equal "one-c9373b68.txt", manifest["one.txt"] + assert_equal "nested/three-a41a5d38.txt", manifest["nested/three.txt"] end end diff --git a/test/propshaft/output_path_test.rb b/test/propshaft/output_path_test.rb index d4af55b..b651ad3 100644 --- a/test/propshaft/output_path_test.rb +++ b/test/propshaft/output_path_test.rb @@ -8,7 +8,7 @@ class Propshaft::OutputPathTest < ActiveSupport::TestCase setup do @manifest = { ".manifest.json": ".manifest.json", - "one.txt": "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt" + "one.txt": "one-f2e1ec14.txt" }.stringify_keys @output_path = Propshaft::OutputPath.new(Pathname.new("#{__dir__}/../fixtures/output"), @manifest) end @@ -16,9 +16,9 @@ class Propshaft::OutputPathTest < ActiveSupport::TestCase test "files" do files = @output_path.files - file = files["one-f2e1ec14d6856e1958083094170ca6119c529a73.txt"] + file = files["one-f2e1ec14.txt"] assert_equal "one.txt", file[:logical_path] - assert_equal "f2e1ec14d6856e1958083094170ca6119c529a73", file[:digest] + assert_equal "f2e1ec14", file[:digest] assert file[:mtime].is_a?(Time) end diff --git a/test/propshaft/processor_test.rb b/test/propshaft/processor_test.rb index fb9a7aa..d1c5985 100644 --- a/test/propshaft/processor_test.rb +++ b/test/propshaft/processor_test.rb @@ -16,17 +16,17 @@ class Propshaft::ProcessorTest < ActiveSupport::TestCase test "manifest is written" do processed do |processor| - assert_equal "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt", + assert_equal "one-f2e1ec14.txt", JSON.parse(processor.output_path.join(".manifest.json").read)["one.txt"] end end test "assets are copied" do processed do |processor| - digested_asset_name = "one-f2e1ec14d6856e1958083094170ca6119c529a73.txt" + digested_asset_name = "one-f2e1ec14.txt" assert processor.output_path.join(digested_asset_name).exist? - nested_digested_asset_name = "nested/three-6c2b86a0206381310375abdd9980863c2ea7b2c3.txt" + nested_digested_asset_name = "nested/three-6c2b86a0.txt" assert processor.output_path.join(nested_digested_asset_name).exist? end end diff --git a/test/propshaft/resolver/dynamic_test.rb b/test/propshaft/resolver/dynamic_test.rb index 467d0e4..7cb60f1 100644 --- a/test/propshaft/resolver/dynamic_test.rb +++ b/test/propshaft/resolver/dynamic_test.rb @@ -8,7 +8,7 @@ class Propshaft::Resolver::DynamicTest < ActiveSupport::TestCase end test "resolving present asset returns uri path" do - assert_equal "/assets/one-f2e1ec14d6856e1958083094170ca6119c529a73.txt", + assert_equal "/assets/one-f2e1ec14.txt", @resolver.resolve("one.txt") end diff --git a/test/propshaft/resolver/static_test.rb b/test/propshaft/resolver/static_test.rb index 778a47e..34e4a06 100644 --- a/test/propshaft/resolver/static_test.rb +++ b/test/propshaft/resolver/static_test.rb @@ -12,7 +12,7 @@ class Propshaft::Resolver::StaticTest < ActiveSupport::TestCase test "resolving present asset returns uri path" do assert_equal \ - "/assets/one-f2e1ec14d6856e1958083094170ca6119c529a73.txt", + "/assets/one-f2e1ec14.txt", @resolver.resolve("one.txt") end diff --git a/test/propshaft/server_test.rb b/test/propshaft/server_test.rb index f68e966..1b49978 100644 --- a/test/propshaft/server_test.rb +++ b/test/propshaft/server_test.rb @@ -37,13 +37,18 @@ class Propshaft::ServerTest < ActiveSupport::TestCase get "/#{asset.digested_path}" assert_equal 200, last_response.status + assert_equal "62", last_response.headers['content-length'] + assert_equal "text/css", last_response.headers['content-type'] + assert_equal "Accept-Encoding", last_response.headers['vary'] + assert_equal asset.digest, last_response.headers['etag'] + assert_equal "public, max-age=31536000, immutable", last_response.headers['cache-control'] assert_nil last_response.headers['service-worker-allowed'] - assert_equal ".hero { background: url(\"/foobar/source/file-3e6a129785ee3caf8eff23db339997e85334bfa9.jpg\") }\n", - last_response.body + assert_equal ".hero { background: url(\"/foobar/source/file-3e6a1297.jpg\") }\n", + last_response.body end test "serve a predigested file" do - asset = @assembly.load_path.find("file-already-abcdefVWXYZ0123456789.digested.css") + asset = @assembly.load_path.find("file-already-abcdefVWXYZ0123456789_-.digested.css") get "/#{asset.digested_path}" assert_equal 200, last_response.status end diff --git a/test/propshaft_integration_test.rb b/test/propshaft_integration_test.rb index 6ad87a1..80205f6 100644 --- a/test/propshaft_integration_test.rb +++ b/test/propshaft_integration_test.rb @@ -6,10 +6,10 @@ class PropshaftIntegrationTest < ActionDispatch::IntegrationTest assert_response :success - assert_select 'link[href="/assets/hello_world-4137140a1298c3924d5f7135617c23e23fb167a8.css"]' - assert_select 'link[href="/assets/goodbye-b1dc9940e9800d8bc96f7434617c043e58277419.css"]' + assert_select 'link[href="/assets/hello_world-4137140a.css"]' + assert_select 'link[href="/assets/goodbye-b1dc9940.css"]' - assert_select 'script[src="/assets/hello_world-888761f849ba63a95a56f6ef898a9eb70ca4c46e.js"]' + assert_select 'script[src="/assets/hello_world-888761f8.js"]' end test "should raise an exception when resolving nonexistent assets" do