Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested arrays #585

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/intercom/lib/flat_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion spec/unit/intercom/lib/flat_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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