Skip to content

Commit

Permalink
Fix NonStupidDigestAssets with String whitelist
Browse files Browse the repository at this point in the history
We need to support Strings as well as Regexp.

(cherry picked from commit de4c974)
  • Loading branch information
tvdeyen committed Aug 29, 2023
1 parent 07ecf3d commit 95948c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/non_stupid_digest_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def assets(assets)
def whitelisted_assets(assets)
assets.select do |logical_path, _digest_path|
whitelist.any? do |item|
item =~ logical_path
/#{item}/ =~ logical_path
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion spec/libraries/non_stupid_digest_assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
end

context "when the whitelist is not empty" do
it "returns the assets that match the whitelist" do
it "returns the assets that match the whitelist of regex" do
NonStupidDigestAssets.whitelist = [/foo/]
assets = {"foo.js" => "foo-123.js", "bar.js" => "bar-123.js"}
expect(NonStupidDigestAssets.assets(assets)).to eq("foo.js" => "foo-123.js")
end

it "returns the assets that match the whitelist of strings" do
NonStupidDigestAssets.whitelist = ["foo.js"]
assets = {"foo.js" => "foo-123.js", "bar.js" => "bar-123.js"}
expect(NonStupidDigestAssets.assets(assets)).to eq("foo.js" => "foo-123.js")
end
end
end
end

0 comments on commit 95948c2

Please sign in to comment.