Skip to content

Commit 7a6219e

Browse files
authored
Merge pull request #386 from tilo/HashWithIndifferentAccess
use HashWithIndifferentAccess, instead of symbolize_keys
2 parents da8a535 + ae3db38 commit 7a6219e

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- (#386)[https://github.com/JsonApiClient/json_api_client/pull/386] - use HashWithIndifferentAccess
6+
57
## 1.18.0
68
- [#372](https://github.com/JsonApiClient/json_api_client/pull/372) - Fix handling of dashed-types associations correctly
79

lib/json_api_client/query/builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def last
6767
end
6868

6969
def build(attrs = {})
70-
klass.new @path_params.merge(attrs.symbolize_keys)
70+
klass.new @path_params.merge(attrs.with_indifferent_access)
7171
end
7272

7373
def create(attrs = {})
74-
klass.create @path_params.merge(attrs.symbolize_keys)
74+
klass.create @path_params.merge(attrs.with_indifferent_access)
7575
end
7676

7777
def params

lib/json_api_client/resource.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _build_connection(rebuild = false)
348348
#
349349
# @param params [Hash] Attributes, links, and relationships
350350
def initialize(params = {})
351-
params = params.symbolize_keys
351+
params = params.with_indifferent_access
352352
@persisted = nil
353353
@destroyed = nil
354354
self.links = self.class.linker.new(params.delete(:links) || {})
@@ -538,7 +538,7 @@ def reset_request_select!(*resource_types)
538538
end
539539

540540
def path_attributes
541-
_belongs_to_params.merge attributes.slice( self.class.primary_key ).symbolize_keys
541+
_belongs_to_params.merge attributes.slice( self.class.primary_key ).with_indifferent_access
542542
end
543543

544544
protected

test/unit/query_builder_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ def test_build_propagate_only_path_params
308308
query = ArticleNested.where(author_id: '123', name: 'John')
309309
record = query.build
310310
assert_equal [], record.changed
311-
assert_equal({author_id: '123'}, record.__belongs_to_params)
311+
assert_equal(record.__belongs_to_params[:author_id], '123')
312+
assert_equal(record.__belongs_to_params['author_id'], '123')
312313
assert_equal '123', record.author_id
313314
assert_equal [], record.relationships.changed
314315
end

0 commit comments

Comments
 (0)