From d7cb352e272dca15497e425996471f9dd5832d3b Mon Sep 17 00:00:00 2001 From: Davy Malone Date: Tue, 27 Sep 2022 18:55:37 +0100 Subject: [PATCH] Allow nested arrays --- lib/intercom/lib/flat_store.rb | 2 +- spec/unit/intercom/lib/flat_store_spec.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/intercom/lib/flat_store.rb b/lib/intercom/lib/flat_store.rb index 6971ca75..08c30832 100644 --- a/lib/intercom/lib/flat_store.rb +++ b/lib/intercom/lib/flat_store.rb @@ -23,7 +23,7 @@ def [](key) private def validate_key_and_value(key, value) - raise ArgumentError.new("This does not support nested data structures (key: #{key}, value: #{value}") if value.is_a?(Array) || value.is_a?(Hash) + raise ArgumentError.new("This does not support nested hashes (key: #{key}, value: #{value}") if value.is_a?(Hash) raise ArgumentError.new("Key must be String or Symbol: #{key}") unless key.is_a?(String) || key.is_a?(Symbol) end end diff --git a/spec/unit/intercom/lib/flat_store_spec.rb b/spec/unit/intercom/lib/flat_store_spec.rb index 3188b579..762766cf 100644 --- a/spec/unit/intercom/lib/flat_store_spec.rb +++ b/spec/unit/intercom/lib/flat_store_spec.rb @@ -5,7 +5,6 @@ describe Intercom::Lib::FlatStore do it 'raises if you try to set or merge in nested hash structures' do data = Intercom::Lib::FlatStore.new - _(proc { data['thing'] = [1] }).must_raise ArgumentError _(proc { data['thing'] = { 1 => 2 } }).must_raise ArgumentError _(proc { Intercom::Lib::FlatStore.new(1 => { 2 => 3 }) }).must_raise ArgumentError end @@ -19,13 +18,21 @@ data = Intercom::Lib::FlatStore.new data['a'] = 1 data[:b] = 2 + data['array'] = [1] + data[:another_array] = [2] _(data[:a]).must_equal 1 _(data['b']).must_equal 2 _(data[:b]).must_equal 2 + _(data[:array]).must_equal [1] + _(data['another_array']).must_equal [2] data = Intercom::Lib::FlatStore.new('a' => 1, :b => 2) _(data['a']).must_equal 1 _(data[:a]).must_equal 1 _(data['b']).must_equal 2 _(data[:b]).must_equal 2 + _(data[:array]).must_equal [1] + _(data['array']).must_equal [1] + _(data[:another_array]).must_equal [2] + _(data['another_array']).must_equal [2] end end