Skip to content

Commit 5aa907a

Browse files
committed
Add a method to delete manifest entries
1 parent b17c7fc commit 5aa907a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

lib/propshaft/manifest.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ def [](logical_path)
134134
@entries[logical_path]
135135
end
136136

137+
# Removes a manifest entry by its logical path.
138+
#
139+
# ==== Parameters
140+
#
141+
# * +logical_path+ - The logical path of the asset to remove
142+
#
143+
# ==== Returns
144+
#
145+
# The removed manifest entry, or +nil+ if not found.
146+
def delete(logical_path)
147+
@entries.delete(logical_path)
148+
end
149+
137150
# Converts the manifest to JSON format.
138151
#
139152
# The JSON representation maps logical paths to hash representations of

test/propshaft/manifest_test.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,54 @@ class Propshaft::ManifestTest < ActiveSupport::TestCase
8989
assert_nil manifest["nonexistent.js"]
9090
end
9191

92+
test "delete method removes entry and returns it" do
93+
manifest = Propshaft::Manifest.new
94+
entry = Propshaft::Manifest::ManifestEntry.new(
95+
logical_path: "test.js",
96+
digested_path: "test-abc123.js",
97+
integrity: "sha384-test"
98+
)
99+
100+
manifest.push(entry)
101+
assert_equal entry, manifest["test.js"]
102+
103+
deleted_entry = manifest.delete("test.js")
104+
assert_equal entry, deleted_entry
105+
assert_nil manifest["test.js"]
106+
end
107+
108+
test "delete method returns nil for missing entries" do
109+
manifest = Propshaft::Manifest.new
110+
assert_nil manifest.delete("nonexistent.js")
111+
end
112+
113+
test "delete method with multiple entries" do
114+
manifest = Propshaft::Manifest.new
115+
116+
entry1 = Propshaft::Manifest::ManifestEntry.new(
117+
logical_path: "app.js",
118+
digested_path: "app-abc123.js",
119+
integrity: "sha384-test1"
120+
)
121+
122+
entry2 = Propshaft::Manifest::ManifestEntry.new(
123+
logical_path: "style.css",
124+
digested_path: "style-def456.css",
125+
integrity: "sha384-test2"
126+
)
127+
128+
manifest.push(entry1)
129+
manifest.push(entry2)
130+
131+
assert_equal entry1, manifest["app.js"]
132+
assert_equal entry2, manifest["style.css"]
133+
134+
deleted_entry = manifest.delete("app.js")
135+
assert_equal entry1, deleted_entry
136+
assert_nil manifest["app.js"]
137+
assert_equal entry2, manifest["style.css"]
138+
end
139+
92140
test "push_asset method creates entry from asset" do
93141
manifest = Propshaft::Manifest.new(integrity_hash_algorithm: "sha384")
94142
asset = find_asset("one.txt")

0 commit comments

Comments
 (0)