A platform for community discussion. Free, open, simple.
DEV: Handle `nil` keys in `SetStore` implementations
Gerhard Schlagerb7a1b3239519
diff --git a/migrations/lib/common/set_store/key_value_set.rb b/migrations/lib/common/set_store/key_value_set.rbindex e819fd11e5a..de0e6815d9e 100644--- a/migrations/lib/common/set_store/key_value_set.rb+++ b/migrations/lib/common/set_store/key_value_set.rb@@ -23,7 +23,7 @@ module Migrations::SetStoreenddef bulk_add(records)- current_key = nil+ current_key = :__uninitialized__current_set = nilrecords.each do |record|diff --git a/migrations/lib/common/set_store/simple_set.rb b/migrations/lib/common/set_store/simple_set.rbindex e776e6f53e4..e6eae11fd8c 100644--- a/migrations/lib/common/set_store/simple_set.rb+++ b/migrations/lib/common/set_store/simple_set.rb@@ -29,5 +29,9 @@ module Migrations::SetStoredef empty?@store.empty?end++ def each+ @store.each+ endendenddiff --git a/migrations/lib/common/set_store/three_key_set.rb b/migrations/lib/common/set_store/three_key_set.rbindex 7153f284c04..5bdcf08a607 100644--- a/migrations/lib/common/set_store/three_key_set.rb+++ b/migrations/lib/common/set_store/three_key_set.rb@@ -31,9 +31,9 @@ module Migrations::SetStoreenddef bulk_add(records)- current_key1 = nil- current_key2 = nil- current_key3 = nil+ current_key1 = :__uninitialized__+ current_key2 = :__uninitialized__+ current_key3 = :__uninitialized__current_h1 = nilcurrent_h2 = nilcurrent_set = nildiff --git a/migrations/lib/common/set_store/two_key_set.rb b/migrations/lib/common/set_store/two_key_set.rbindex e3add6e47e4..c2ca1168a84 100644--- a/migrations/lib/common/set_store/two_key_set.rb+++ b/migrations/lib/common/set_store/two_key_set.rb@@ -28,8 +28,8 @@ module Migrations::SetStoreenddef bulk_add(records)- current_key1 = nil- current_key2 = nil+ current_key1 = :__uninitialized__+ current_key2 = :__uninitialized__current_h1 = nilcurrent_set = nildiff --git a/migrations/spec/lib/common/set_store/key_value_set_spec.rb b/migrations/spec/lib/common/set_store/key_value_set_spec.rbindex ab1faed2909..54174740ae5 100644--- a/migrations/spec/lib/common/set_store/key_value_set_spec.rb+++ b/migrations/spec/lib/common/set_store/key_value_set_spec.rb@@ -54,6 +54,13 @@ describe Migrations::SetStore::KeyValueSet doexpect(set.include?("key2", 2)).to be trueend+ it "handles nil keys correctly" do+ set.bulk_add([[nil, 1], [nil, 2], ["key1", 3]])+ expect(set.include?(nil, 1)).to be true+ expect(set.include?(nil, 2)).to be true+ expect(set.include?("key1", 3)).to be true+ end+it "returns nil" doexpect(set.bulk_add([["key1", 1]])).to be_nilenddiff --git a/migrations/spec/lib/common/set_store/three_key_set_spec.rb b/migrations/spec/lib/common/set_store/three_key_set_spec.rbindex 131e9182529..d68086cdd43 100644--- a/migrations/spec/lib/common/set_store/three_key_set_spec.rb+++ b/migrations/spec/lib/common/set_store/three_key_set_spec.rb@@ -73,6 +73,13 @@ describe Migrations::SetStore::ThreeKeySet doexpect(set.include?("key4", "key5", "key6", 2)).to be trueend+ it "handles nil keys correctly" do+ set.bulk_add([[nil, "key2", "key3", 1], ["key1", nil, "key3", 2], ["key1", "key2", nil, 3]])+ expect(set.include?(nil, "key2", "key3", 1)).to be true+ expect(set.include?("key1", nil, "key3", 2)).to be true+ expect(set.include?("key1", "key2", nil, 3)).to be true+ end+it "returns nil" doexpect(set.bulk_add([["key1", "key2", "key3", 1]])).to be_nilenddiff --git a/migrations/spec/lib/common/set_store/two_key_set_spec.rb b/migrations/spec/lib/common/set_store/two_key_set_spec.rbindex 7a9b6600a5f..583b75756b9 100644--- a/migrations/spec/lib/common/set_store/two_key_set_spec.rb+++ b/migrations/spec/lib/common/set_store/two_key_set_spec.rb@@ -66,6 +66,13 @@ describe Migrations::SetStore::TwoKeySet doexpect(set.include?("key3", "key4", 2)).to be trueend+ it "handles nil keys correctly" do+ set.bulk_add([[nil, "key2", 1], [nil, "key3", 2], ["key1", nil, 3]])+ expect(set.include?(nil, "key2", 1)).to be true+ expect(set.include?(nil, "key3", 2)).to be true+ expect(set.include?("key1", nil, 3)).to be true+ end+it "returns nil" doexpect(set.bulk_add([["key1", "key2", 1]])).to be_nilend