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

#from_hash in the HashConverter does not accept HashWithIndifferentAccess data type #104

Open
bghalami-rc opened this issue Apr 12, 2024 · 0 comments

Comments

@bghalami-rc
Copy link
Contributor

bghalami-rc commented Apr 12, 2024

There are inconsistencies with how Ruby on Rails and how this gem interpret what is and what isn't a valid Hash which trigger the argument error in the hash_converter.rb

pry(main)> ActiveSupport::HashWithIndifferentAccess.new({}).is_a?(Hash)
=> true
pry(main)> children = ActiveSupport::HashWithIndifferentAccess.new({})
=> {}
pry(main)> [Hash, NilClass].include?(children.class)
=> false

Example

[33] pry(main)> test_arr = [
  {
    title: 'string hash (indifferent, new key, hash value)',
    hash: { 'key' => nil }.with_indifferent_access.tap do |h|
      h['key2'] = { 'key3' => nil }
    end
  }
]
=> [{:title=>"string hash (indifferent, new key, hash value)", :hash=>{"key"=>nil, "key2"=>{"key3"=>nil}}}]

[34] pry(main)> test_arr.each do |test|
  puts test[:title]
  puts JSON.pretty_generate(test[:hash])
  Tree::TreeNode.new(:root).tap do |tree|
    tree.add_from_hash(sorted_hash_for_tree_load(test[:hash]))
  end.print_tree; 0
rescue => e
  puts e.message
string hash (indifferent, new key, hash value)
{
  "key": null,
  "key2": {
    "key3": null
  }
}
Invalid child. Must be nil or hash.
=> [{:title=>"string hash (indifferent, new key, hash value)", :hash=>{"key"=>nil, "key2"=>{"key3"=>nil}}}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant