|
45 | 45 | store.write("my_key", "my_value") |
46 | 46 |
|
47 | 47 | # Calculate the expected hash |
48 | | - hash = Digest::SHA256.hexdigest("my_key") |
| 48 | + hash = ActiveSupport::Digest.hexdigest("my_key") |
49 | 49 | key_file = File.join(cache_path, "#{hash}.key") |
50 | 50 | value_file = File.join(cache_path, "#{hash}.value") |
51 | 51 |
|
|
57 | 57 | original_key = "my_special_key" |
58 | 58 | store.write(original_key, "value") |
59 | 59 |
|
60 | | - hash = Digest::SHA256.hexdigest(original_key) |
| 60 | + hash = ActiveSupport::Digest.hexdigest(original_key) |
61 | 61 | key_file = File.join(cache_path, "#{hash}.key") |
62 | 62 |
|
63 | 63 | expect(File.read(key_file)).to eq(original_key) |
|
82 | 82 |
|
83 | 83 | it "removes both .key and .value files" do |
84 | 84 | store.write("key", "value") |
85 | | - hash = Digest::SHA256.hexdigest("key") |
| 85 | + hash = ActiveSupport::Digest.hexdigest("key") |
86 | 86 | key_file = File.join(cache_path, "#{hash}.key") |
87 | 87 | value_file = File.join(cache_path, "#{hash}.value") |
88 | 88 |
|
|
149 | 149 | end |
150 | 150 |
|
151 | 151 | describe "key hashing" do |
152 | | - it "uses SHA256 for hashing keys" do |
| 152 | + it "uses ActiveSupport::Digest for hashing keys" do |
153 | 153 | key = "test_key" |
154 | | - expected_hash = Digest::SHA256.hexdigest(key) |
| 154 | + expected_hash = ActiveSupport::Digest.hexdigest(key) |
155 | 155 |
|
156 | 156 | store.write(key, "value") |
157 | 157 |
|
|
215 | 215 | store_with_delimiter.write("foo---bar---boo-ba", "27") |
216 | 216 |
|
217 | 217 | # Calculate expected hashes |
218 | | - foo_hash = Digest::SHA256.hexdigest("foo") |
219 | | - bar_hash = Digest::SHA256.hexdigest("bar") |
220 | | - boo_ba_hash = Digest::SHA256.hexdigest("boo-ba") |
| 218 | + foo_hash = ActiveSupport::Digest.hexdigest("foo") |
| 219 | + bar_hash = ActiveSupport::Digest.hexdigest("bar") |
| 220 | + boo_ba_hash = ActiveSupport::Digest.hexdigest("boo-ba") |
221 | 221 |
|
222 | 222 | # Check that directories exist |
223 | 223 | expect(File.directory?(File.join(cache_path_with_delimiter, foo_hash))).to be true |
|
228 | 228 | it "creates _key_chunk files with correct content" do |
229 | 229 | store_with_delimiter.write("foo---bar---boo-ba", "27") |
230 | 230 |
|
231 | | - foo_hash = Digest::SHA256.hexdigest("foo") |
232 | | - bar_hash = Digest::SHA256.hexdigest("bar") |
233 | | - boo_ba_hash = Digest::SHA256.hexdigest("boo-ba") |
| 231 | + foo_hash = ActiveSupport::Digest.hexdigest("foo") |
| 232 | + bar_hash = ActiveSupport::Digest.hexdigest("bar") |
| 233 | + boo_ba_hash = ActiveSupport::Digest.hexdigest("boo-ba") |
234 | 234 |
|
235 | 235 | # Check _key_chunk files |
236 | 236 | foo_chunk_file = File.join(cache_path_with_delimiter, foo_hash, "_key_chunk") |
|
245 | 245 | it "stores value in the final directory" do |
246 | 246 | store_with_delimiter.write("foo---bar---boo-ba", "27") |
247 | 247 |
|
248 | | - foo_hash = Digest::SHA256.hexdigest("foo") |
249 | | - bar_hash = Digest::SHA256.hexdigest("bar") |
250 | | - boo_ba_hash = Digest::SHA256.hexdigest("boo-ba") |
| 248 | + foo_hash = ActiveSupport::Digest.hexdigest("foo") |
| 249 | + bar_hash = ActiveSupport::Digest.hexdigest("bar") |
| 250 | + boo_ba_hash = ActiveSupport::Digest.hexdigest("boo-ba") |
251 | 251 |
|
252 | 252 | value_file = File.join(cache_path_with_delimiter, foo_hash, bar_hash, boo_ba_hash, "value") |
253 | 253 |
|
|
263 | 263 | it "handles single chunk keys (no delimiter present)" do |
264 | 264 | store_with_delimiter.write("single_key", "single_value") |
265 | 265 |
|
266 | | - single_hash = Digest::SHA256.hexdigest("single_key") |
| 266 | + single_hash = ActiveSupport::Digest.hexdigest("single_key") |
267 | 267 | value_file = File.join(cache_path_with_delimiter, single_hash, "value") |
268 | 268 |
|
269 | 269 | expect(File.exist?(value_file)).to be true |
|
314 | 314 | store_with_delimiter.write(key, "deep_value") |
315 | 315 | expect(store_with_delimiter.read(key)).to eq("deep_value") |
316 | 316 | end |
| 317 | + |
| 318 | + it "deletes only the specific entry without affecting others with common prefixes" do |
| 319 | + # Write two keys that share the first chunk |
| 320 | + store_with_delimiter.write("foo---bar", "value1") |
| 321 | + store_with_delimiter.write("foo---baz", "value2") |
| 322 | + |
| 323 | + # Verify both exist |
| 324 | + expect(store_with_delimiter.read("foo---bar")).to eq("value1") |
| 325 | + expect(store_with_delimiter.read("foo---baz")).to eq("value2") |
| 326 | + |
| 327 | + # Delete the first one |
| 328 | + store_with_delimiter.delete("foo---bar") |
| 329 | + |
| 330 | + # Verify only the deleted one is gone |
| 331 | + expect(store_with_delimiter.read("foo---bar")).to be_nil |
| 332 | + expect(store_with_delimiter.read("foo---baz")).to eq("value2") |
| 333 | + end |
317 | 334 | end |
318 | 335 | end |
0 commit comments