camel_snake_keys 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,19 +1,40 @@
1
- 0.0.6 4/07/2020
2
- ==============
1
+ 1.0.0 01/31/2024
2
+ ================
3
+
4
+ Don't let integer hash keys raise your enemies up. Test against Ruby 3.3.0.
5
+
6
+ 0.1.0 10/14/2022
7
+ ================
8
+
9
+ ActiveSupport::Inflector's camelize and underscore methods convert "::" to "/" and "/" to "::", which might be useful in Rails' internals, but in the context of a Grape API it corrupts the swagger docs' "paths" objects.
10
+
11
+ Implement our own camel and snake case methods that leave "::" and "/" unmolested, rather than relying on ActiveSupport, in which case we'll drop that dependency altogether by removing the (trivially re-implemented) indifferent access functionality.
12
+
13
+ We are not re-implmenting ActiveSupport's acronym inflections. Yet.
14
+
15
+ Replace travis etc. with github actions.
16
+
17
+ 0.0.7 02/08/2022
18
+ ================
19
+
20
+ Support Ruby 3+
21
+
22
+ 0.0.6 04/07/2020
23
+ ===============
3
24
 
4
25
  ### Bug fix
5
26
 
6
27
  Pass the indifferent access flag down the recursion.
7
28
 
8
- 0.0.3 5/11/2016
9
- ==============
29
+ 0.0.3 05/11/2016
30
+ ================
10
31
 
11
32
  ### Features
12
33
 
13
34
  Preserve any descendent of Hash that accepts a Hash in its initialize method, as with ActiveSupport::HashWithIndifferentAccess and Hashie::Mash
14
35
 
15
- 0.0.2 5/11/2016
16
- ==============
36
+ 0.0.2 05/11/2016
37
+ ================
17
38
 
18
39
  ### Features
19
40
 
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
- gem 'activesupport', '~> 4.2'
3
- gem 'coveralls', require: false
4
+ gemspec
5
+ gem 'activesupport'
6
+ gem 'brakeman'
7
+ gem 'byebug'
8
+ gem 'coveralls'
4
9
  gem 'hashie'
5
10
  gem 'rake'
6
11
  gem 'rspec'
12
+ gem 'rspec-core'
13
+ gem 'rubocop'
data/README.md CHANGED
@@ -1,29 +1,15 @@
1
1
  # camel_snake_keys
2
2
 
3
3
  [![Gem Version][GV img]][Gem Version]
4
- [![Build Status][BS img]][Build Status]
5
- [![Dependency Status][DS img]][Dependency Status]
6
- [![Coverage Status][CS img]][Coverage Status]
7
-
8
4
  [Gem Version]: https://rubygems.org/gems/camel_snake_keys
9
- [Build Status]: https://travis-ci.org/buermann/camel_snake_keys
10
- [travis pull requests]: https://travis-ci.org/buermann/camel_snake_keys/pull_requests
11
- [Dependency Status]: https://gemnasium.com/buermann/camel_snake_keys
12
- [Coverage Status]: https://coveralls.io/r/buermann/camel_snake_keys
13
-
14
- [GV img]: https://badge.fury.io/rb/camel_snake_keys.png
15
- [BS img]: https://travis-ci.org/buermann/camel_snake_keys.png
16
- [DS img]: https://gemnasium.com/buermann/camel_snake_keys.png
17
- [CS img]: https://coveralls.io/repos/buermann/camel_snake_keys/badge.png?branch=master
18
-
19
5
 
20
6
  Add recursive with_snake_keys and with_camel_keys refinements to Array and Hash. Preserve strings and symbols and treat hash descendents such as ActiveSupport::HashWithIndifferentAccess and Hashie::Mash agnostically.
21
7
 
22
8
  ## Documentation
23
9
 
24
- Add `gem 'camel_snake_keys'` to your Gemfile or gem install camel_snake_keys. Where you want to add `with_snake_keys` and `with_camel_keys` to your objects invoke `using CamelSnakeKeys`, or invoke the class methods, `CamelSnakeKeys.camel_keys(object, with_indifference)` and `CamelSnakeKeys.snake_keys(object, with_indifference)`.
10
+ Add `gem 'camel_snake_keys'` to your Gemfile or "gem install camel_snake_keys".
25
11
 
26
- If with_indifference is set to a true value hashes will be returned as ActiveSupport's HashWithIndifferentAccess.
12
+ Where you want to add `with_snake_keys` and `with_camel_keys` to your objects invoke `using CamelSnakeKeys`, or invoke the class methods, `CamelSnakeKeys.camel_keys(object)` and `CamelSnakeKeys.snake_keys(object)`.
27
13
 
28
14
  ```
29
15
  require 'camel_snake_keys'
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -15,4 +17,3 @@ RDoc::Task.new(:rdoc) do |rdoc|
15
17
  end
16
18
 
17
19
  Bundler::GemHelper.install_tasks
18
-
data/camel_snake.gemspec CHANGED
@@ -1,25 +1,29 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
2
4
 
3
5
  # Maintain your gem's version:
4
- require "version"
6
+ require 'version'
5
7
 
6
8
  # Describe your gem and declare its dependencies:
7
9
  Gem::Specification.new do |s|
8
- s.name = "camel_snake_keys"
10
+ s.name = 'camel_snake_keys'
9
11
  s.version = CamelSnakeKeys::VERSION
10
- s.authors = ["Josh Buermann"]
11
- s.email = ["buermann@gmail.com"]
12
- s.homepage = "https://github.com/buermann/camel_snake_keys"
13
- s.summary = "Convert nested data structure hash keys between camel and snake case."
14
- s.description = ""
15
- s.license = "MIT"
12
+ s.authors = ['Josh Buermann']
13
+ s.email = ['buermann@gmail.com']
14
+ s.homepage = 'https://github.com/buermann/camel_snake_keys'
15
+ s.summary = 'Convert nested data structure hash keys between camel and snake case.'
16
+ s.description = ''
17
+ s.license = 'MIT'
16
18
 
17
- s.files = `git ls-files`.split("\n").sort
18
- s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.files = `git ls-files`.split("\n").sort
19
20
 
20
- s.required_ruby_version = '~> 2.0'
21
- s.add_dependency "activesupport"
21
+ s.required_ruby_version = '> 2.3'
22
+ s.add_dependency 'activesupport'
22
23
 
23
- s.add_development_dependency "rspec-rails", '>= 3.0'
24
- s.add_development_dependency "activesupport", '~> 4.2'
24
+ s.add_development_dependency 'activesupport'
25
+ s.add_development_dependency 'brakeman'
26
+ s.add_development_dependency 'byebug'
27
+ s.add_development_dependency 'rspec'
28
+ s.metadata['rubygems_mfa_required'] = 'true'
25
29
  end
@@ -1,64 +1,78 @@
1
- require 'active_support/core_ext/hash'
2
- require 'active_support/core_ext/string/inflections'
1
+ # frozen_string_literal: true
3
2
 
3
+ # Convert the keys of hashes in nested structures to camel or snake case.
4
4
  module CamelSnakeKeys
5
- [Hash,Array].each do |klass|
5
+ [Hash, Array].each do |klass|
6
6
  refine klass do
7
- def with_camel_keys(indifference=false)
8
- CamelSnakeKeys.camel_keys(self, indifference)
7
+ def with_camel_keys
8
+ CamelSnakeKeys.camel_keys(self)
9
9
  end
10
10
 
11
- def with_snake_keys(indifference=false)
12
- CamelSnakeKeys.snake_keys(self, indifference)
11
+ def with_snake_keys
12
+ CamelSnakeKeys.snake_keys(self)
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
17
  class << self
18
- def if_underscore(v)
19
- if v.is_a? Symbol
20
- v.to_s.underscore.to_sym
21
- elsif v.is_a? String
22
- v.underscore
18
+ def camelcase(obj)
19
+ string = +obj.to_s # unfreeze whatever it might be with a leading +
20
+ string.sub!(/^([A-Z])/) { $1.downcase }
21
+ string.gsub!(/_([a-z\d])/) { $1.capitalize }
22
+ string
23
+ end
24
+
25
+ def snakecase(obj)
26
+ string = +obj.to_s
27
+ string.gsub!(/([A-Z])/) { "_#{$1}" }
28
+ string.downcase!
29
+ string
30
+ end
31
+
32
+ def if_underscore(obj)
33
+ case obj
34
+ when Symbol
35
+ snakecase(obj.to_s).to_sym
36
+ when String
37
+ snakecase(obj)
23
38
  else
24
- v
39
+ obj
25
40
  end
26
41
  end
27
42
 
28
- def if_camelize(v)
29
- if v.is_a? Symbol
30
- v.to_s.camelize(:lower).to_sym
31
- elsif v.is_a? String
32
- v.camelize(:lower)
43
+ def if_camelize(obj)
44
+ case obj
45
+ when Symbol
46
+ camelcase(obj.to_s).to_sym
47
+ when String
48
+ camelcase(obj)
33
49
  else
34
- v
50
+ obj
35
51
  end
36
52
  end
37
53
 
38
- def snake_keys(data, indifference=false)
39
- if data.kind_of? Array
40
- data.map { |v| snake_keys(v, indifference) }
41
- elsif data.kind_of? Hash
42
- hash = Hash[data.sort_by {|k,_v| k =~ /_/ ? 0 : 1 }.map {|k, v| [if_underscore(k), snake_keys(v, indifference)] }]
43
- hash = hash.with_indifferent_access if indifference
44
- data.class == Hash ? hash : data.class.new(hash)
54
+ def snake_keys(data)
55
+ case data
56
+ when Array
57
+ data.map { |v| snake_keys(v) }
58
+ when Hash
59
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 0 : 1 }.to_h { |k, v| [if_underscore(k), snake_keys(v)] }
60
+ data.instance_of?(Hash) ? hash : data.class.new(hash)
45
61
  else
46
62
  data
47
63
  end
48
64
  end
49
65
 
50
- def camel_keys(data, indifference=false)
51
- if data.kind_of? Array
52
- data.map { |v| camel_keys(v, indifference) }
53
- elsif data.kind_of? Hash
54
- hash = Hash[data.sort_by {|k,_v| k =~ /_/ ? 1 : 0 }.map {|k, v| [if_camelize(k), camel_keys(v, indifference)] }]
55
- hash = hash.with_indifferent_access if indifference
56
- data.class == Hash ? hash : data.class.new(hash)
66
+ def camel_keys(data)
67
+ case data
68
+ when Array
69
+ data.map { |v| camel_keys(v) }
70
+ when Hash
71
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 1 : 0 }.to_h { |k, v| [if_camelize(k), camel_keys(v)] }
72
+ data.instance_of?(Hash) ? hash : data.class.new(hash)
57
73
  else
58
74
  data
59
75
  end
60
76
  end
61
77
  end
62
78
  end
63
-
64
-
data/lib/version.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Store the version of the gem here rather than the gemspec
1
4
  module CamelSnakeKeys
2
- VERSION = "0.0.6".freeze
5
+ VERSION = '1.0.0'
3
6
 
4
7
  def self.version
5
8
  VERSION
@@ -1,136 +1,186 @@
1
1
  require 'test_helper'
2
+ require 'byebug'
2
3
  require 'hashie/mash'
4
+ require 'active_support/core_ext/hash/indifferent_access'
3
5
 
4
6
  using CamelSnakeKeys
5
7
 
6
8
  RSpec.describe Enumerable do
7
9
 
8
- context "arrays" do
9
- let(:snaked) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}]] }
10
- let(:camelized) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}]] }
10
+ context 'camelize and underscore' do
11
+ let(:underscore_to_camel) {
12
+ {
13
+ "product" => "product",
14
+ "special_guest" => "specialGuest",
15
+ "application_controller" => "applicationController",
16
+ "area51_controller" => "area51Controller",
17
+ product: "product",
18
+ special_guest: "specialGuest",
19
+ application_controller: "applicationController",
20
+ area51_controller: "area51Controller",
21
+ "camel_snake/keys" => "camelSnake/keys",
22
+ "camel_snake::keys" => "camelSnake::keys"
23
+ }
24
+ }
25
+ it "converts strings and symbols to camel and snake case strings as expected" do
26
+ underscore_to_camel.each do |k,v|
27
+ CamelSnakeKeys.camelcase(k).should eq v.to_s
28
+ CamelSnakeKeys.snakecase(v).should eq k.to_s
29
+ end
30
+ end
31
+
32
+ it "handles nils gracefully" do
33
+ CamelSnakeKeys.camelcase(nil).should eq ""
34
+ CamelSnakeKeys.snakecase(nil).should eq ""
35
+ end
36
+ end
11
37
 
12
- it "should snake case keys of hashes" do
38
+ context 'arrays' do
39
+ let(:snaked) do
40
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
41
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }]]
42
+ end
43
+ let(:camelized) do
44
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
45
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }]]
46
+ end
47
+
48
+ it 'should snake case keys of hashes' do
13
49
  camelized.with_snake_keys.should eq snaked
14
50
  end
15
51
 
16
- it "should camel case keys of hashes" do
52
+ it 'should camel case keys of hashes' do
17
53
  snaked.with_camel_keys.should eq camelized
18
54
  end
19
-
20
55
  end
21
56
 
22
- context "hashes" do
23
- let(:snaked) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]} }
24
- let(:camelized) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]} }
57
+ context 'hashes' do
58
+ let(:snaked) do
59
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
60
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }
61
+ end
62
+ let(:camelized) do
63
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
64
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }
65
+ end
25
66
 
26
- it "should snake case keys of hashes" do
67
+ it 'should snake case keys of hashes' do
27
68
  hash = camelized.with_snake_keys
28
69
  hash.class.should eq Hash
29
70
  hash.should eq snaked
30
71
  end
31
72
 
32
- it "should camel case keys of hashes" do
73
+ it 'should camel case keys of hashes' do
33
74
  hash = snaked.with_camel_keys
34
75
  hash.class.should eq Hash
35
76
  hash.should eq camelized
36
77
  end
37
78
 
38
- it "should preserve symbol keys" do
79
+ it 'should preserve symbol keys' do
39
80
  camelized.with_snake_keys[:foo_bar].should_not be_nil
40
81
  camelized.with_snake_keys['foo_bar'].should be_nil
41
82
  snaked.with_camel_keys[:fooBar].should be_present
42
83
  snaked.with_camel_keys['fooBar'].should be_nil
43
84
  end
44
85
 
45
- it "should preserve string keys" do
86
+ it 'should preserve string keys' do
46
87
  camelized.with_snake_keys['dark_matter'].should be_present
47
88
  camelized.with_snake_keys[:dark_matter].should be_nil
48
89
  snaked.with_camel_keys['darkMatter'].should be_present
49
90
  snaked.with_camel_keys[:darkMatter].should be_nil
50
91
  end
51
92
 
52
- it "should snake case keys of hashes with indifference" do
53
- hash = camelized.with_snake_keys(true)
93
+ it 'should snake case keys of hashes with indifference' do
94
+ hash = camelized.with_indifferent_access.with_snake_keys
54
95
  hash.class.should eq HashWithIndifferentAccess
55
96
  hash.should eq snaked.with_indifferent_access
56
- hash[:foo_bar].should eq hash["foo_bar"]
97
+ hash[:foo_bar].should eq hash['foo_bar']
57
98
  end
58
99
 
59
- it "should camel case keys of hashes with indifference" do
60
- hash = snaked.with_camel_keys(true)
100
+ it 'should camel case keys of hashes with indifference' do
101
+ hash = snaked.with_indifferent_access.with_camel_keys
61
102
  hash.class.should eq HashWithIndifferentAccess
62
103
  hash.should eq camelized.with_indifferent_access
63
- hash["fooBar"].should eq hash[:fooBar]
104
+ hash['fooBar'].should eq hash[:fooBar]
64
105
  end
65
-
66
106
  end
67
107
 
68
- context "hashes with indifferent access" do
69
- let(:snaked) { {1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}.with_indifferent_access }
70
- let(:camelized) { { 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}.with_indifferent_access }
108
+ context 'hashes with indifferent access' do
109
+ let(:snaked) do
110
+ { 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
111
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }.with_indifferent_access
112
+ end
113
+ let(:camelized) do
114
+ { 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
115
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }.with_indifferent_access
116
+ end
71
117
 
72
- it "should snake case keys of hashes" do
118
+ it 'should snake case keys of hashes' do
73
119
  hash = camelized.with_snake_keys
74
120
  hash.class.should eq HashWithIndifferentAccess
75
121
  hash.should eq snaked
76
122
  end
77
123
 
78
- it "should camel case keys of hashes" do
124
+ it 'should camel case keys of hashes' do
79
125
  hash = snaked.with_camel_keys
80
126
  hash.class.should eq HashWithIndifferentAccess
81
127
  hash.should eq camelized
82
128
  end
83
129
 
84
- it "should snake case keys of hashes with indifference" do
85
- hash = camelized.with_snake_keys(true)
130
+ it 'should snake case keys of hashes with indifference' do
131
+ hash = camelized.with_indifferent_access.with_snake_keys
86
132
  hash.class.should eq HashWithIndifferentAccess
87
133
  hash.should eq snaked
88
134
  end
89
135
 
90
- it "should camel case keys of hashes with indifference" do
91
- hash = snaked.with_camel_keys(true)
136
+ it 'should camel case keys of hashes with indifference' do
137
+ hash = snaked.with_indifferent_access.with_camel_keys
92
138
  hash.class.should eq HashWithIndifferentAccess
93
139
  hash.should eq camelized
94
140
  end
95
-
96
141
  end
97
142
 
98
- context "mashes" do
99
- let(:snaked) { Hashie::Mash.new({1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}) }
100
- let(:camelized) { Hashie::Mash.new({ 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}) }
143
+ context 'mashes' do
144
+ let(:snaked) do
145
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
146
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] })
147
+ end
148
+ let(:camelized) do
149
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
150
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] })
151
+ end
101
152
 
102
- it "should snake case keys of hashes" do
153
+ it 'should snake case keys of hashes' do
103
154
  hash = camelized.with_snake_keys
104
155
  hash.class.should eq Hashie::Mash
105
156
  hash.should eq snaked
106
- hash["fooBar"].should eq hash[:fooBar]
157
+ hash['fooBar'].should eq hash[:fooBar]
107
158
  end
108
159
 
109
- it "should camel case keys of hashes" do
160
+ it 'should camel case keys of hashes' do
110
161
  hash = snaked.with_camel_keys
111
162
  hash.class.should eq Hashie::Mash
112
163
  hash.should eq camelized
113
- hash["foo_bar"].should eq hash[:foo_bar]
164
+ hash['foo_bar'].should eq hash[:foo_bar]
114
165
  end
115
-
116
- it "should snake case keys of hashes with redundant indifference" do
117
- hash = camelized.with_snake_keys(true)
166
+
167
+ it 'should snake case keys of hashes with redundant indifference' do
168
+ hash = Hashie::Mash.new(camelized.with_snake_keys.with_indifferent_access)
118
169
  hash.class.should eq Hashie::Mash
119
170
  hash.should eq snaked
120
- hash["foo_bar"].should eq hash[:foo_bar]
171
+ hash['foo_bar'].should eq hash[:foo_bar]
121
172
  end
122
173
 
123
- it "should camel case keys of hashes with redundant indifference" do
124
- hash = snaked.with_camel_keys(true)
174
+ it 'should camel case keys of hashes with redundant indifference' do
175
+ hash = Hashie::Mash.new(snaked.with_camel_keys.with_indifferent_access)
125
176
  hash.class.should eq Hashie::Mash
126
177
  hash.should eq camelized
127
- hash["foo_bar"].should eq hash[:foo_bar]
178
+ hash['foo_bar'].should eq hash[:foo_bar]
128
179
  end
129
-
130
180
  end
131
181
 
132
- context "hash merge conflicts should be resolved predictably" do
133
- it "should give camel case key values priority when snake casing" do
182
+ context 'hash merge conflicts should be resolved predictably' do
183
+ it 'should give camel case key values priority when snake casing' do
134
184
  hash = { foo_bar: 1, fooBar: 2 }
135
185
  result = { foo_bar: 2 }
136
186
  hash.with_snake_keys.should eq result
@@ -139,13 +189,40 @@ RSpec.describe Enumerable do
139
189
  hash.with_snake_keys.should eq result
140
190
  end
141
191
 
142
- it "should give snake case key values priority when camel casing" do
143
- hash = { foo_bar: 1, fooBar: 2 }
192
+ it 'should give snake case key values priority when camel casing' do
144
193
  result = { fooBar: 1 }
194
+
195
+ hash = { foo_bar: 1, fooBar: 2 }
145
196
  hash.with_camel_keys.should eq result
146
197
 
147
198
  hash = { fooBar: 2, foo_bar: 1 }
148
199
  hash.with_camel_keys.should eq result
149
200
  end
150
201
  end
202
+
203
+ context 'it should pass indifference down deeply nested structures' do
204
+ it 'camelizing an array of hashes' do
205
+ camelized = [a: { b: [{ c: :d }] }].with_camel_keys.map(&:with_indifferent_access)
206
+ camelized.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
207
+ camelized.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
208
+ end
209
+
210
+ it 'cazemlizing a hashes of arrays' do
211
+ camelized = { a: [{ b: { c: :d } }] }.with_camel_keys.with_indifferent_access
212
+ camelized.is_a?(HashWithIndifferentAccess).should be_truthy
213
+ camelized[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
214
+ end
215
+
216
+ it 'snaking an array of hashes' do
217
+ snaked = [a: { b: [{ c: :d }] }].with_snake_keys.map(&:with_indifferent_access)
218
+ snaked.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
219
+ snaked.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
220
+ end
221
+
222
+ it 'snaking a hashes of arrays' do
223
+ snaked = { a: [{ b: { c: :d } }] }.with_snake_keys.with_indifferent_access
224
+ snaked.is_a?(HashWithIndifferentAccess).should be_truthy
225
+ snaked[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
226
+ end
227
+ end
151
228
  end