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

camelize_keys doesnt' camelize nested keys #701

Open
apuntovanini opened this issue Nov 2, 2017 · 0 comments
Open

camelize_keys doesnt' camelize nested keys #701

apuntovanini opened this issue Nov 2, 2017 · 0 comments

Comments

@apuntovanini
Copy link

#652 introduced camelize_keys, which is great especially if you expose rabl results to react component for instance. The problem is that it doesn't camelize nested keys.
I added failing tests

context "when keys are camelized" do
  setup do
    Rabl.configuration.camelize_keys = true
    builder(nil, { :attributes => [ { :name => :first_pets_name }], :node => [{ :name => :preferences, :block => lambda { |u| { has_visible_profile: true } } }] })
  end
  asserts "that the key is camelized" do
    topic.to_hash(User.new)
  end.equivalent_to({ :firstPetsName => 'jack', preferences: { hasVisibleProfile: true } })
  teardown do
    Rabl.configuration.camelize_keys = false
  end
end

context "when keys are camelized with upper case first letter" do
  setup do
    Rabl.configuration.camelize_keys = :upper
    builder(nil, { :attributes => [ { :name => :first_pets_name }], :node => [{ :name => :preferences, :block => lambda { |u| { has_visible_profile: true } } }] })
  end
  asserts "that the key is camelized with upper case first letter" do
    topic.to_hash(User.new)
  end.equivalent_to({ :FirstPetsName => 'jack', Preferences: { HasVisibleProfile: true } })
  teardown do
    Rabl.configuration.camelize_keys = false
  end
end

I can't trace where the hash is parsed and names are set, can anyone help me out with this?
Thanks!

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