Skip to content

Commit

Permalink
Merge pull request #2436 from tvdeyen/fix-non-stupid-assets
Browse files Browse the repository at this point in the history
Fix non_stupid_digest_assets
  • Loading branch information
tvdeyen authored Mar 7, 2023
2 parents 4fc5380 + 5384d9a commit 99b547f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/non_stupid_digest_assets.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "sprockets/manifest"
require "active_support/core_ext/module/attribute_accessors"

module NonStupidDigestAssets
mattr_accessor :whitelist
Expand All @@ -18,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
24 changes: 24 additions & 0 deletions spec/libraries/non_stupid_digest_assets_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "spec_helper"
require "non_stupid_digest_assets"

RSpec.describe NonStupidDigestAssets do
describe ".assets" do
context "when the whitelist is empty" do
it "returns the assets" do
NonStupidDigestAssets.whitelist = []
assets = { "foo.js" => "foo-123.js" }
expect(NonStupidDigestAssets.assets(assets)).to eq(assets)
end
end

context "when the whitelist is not empty" do
it "returns the assets that match the whitelist" 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
end
end
end

0 comments on commit 99b547f

Please sign in to comment.