diff --git a/CHANGELOG.md b/CHANGELOG.md index a45a905..1942b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- (#386)[https://github.com/JsonApiClient/json_api_client/pull/386] - use HashWithIndifferentAccess + ## 1.18.0 - [#372](https://github.com/JsonApiClient/json_api_client/pull/372) - Fix handling of dashed-types associations correctly diff --git a/lib/json_api_client/query/builder.rb b/lib/json_api_client/query/builder.rb index 0740bbb..9d60dd2 100644 --- a/lib/json_api_client/query/builder.rb +++ b/lib/json_api_client/query/builder.rb @@ -67,11 +67,11 @@ def last end def build(attrs = {}) - klass.new @path_params.merge(attrs.symbolize_keys) + klass.new @path_params.merge(attrs.with_indifferent_access) end def create(attrs = {}) - klass.create @path_params.merge(attrs.symbolize_keys) + klass.create @path_params.merge(attrs.with_indifferent_access) end def params diff --git a/lib/json_api_client/resource.rb b/lib/json_api_client/resource.rb index b0b0110..12f7c90 100644 --- a/lib/json_api_client/resource.rb +++ b/lib/json_api_client/resource.rb @@ -348,7 +348,7 @@ def _build_connection(rebuild = false) # # @param params [Hash] Attributes, links, and relationships def initialize(params = {}) - params = params.symbolize_keys + params = params.with_indifferent_access @persisted = nil @destroyed = nil self.links = self.class.linker.new(params.delete(:links) || {}) @@ -538,7 +538,7 @@ def reset_request_select!(*resource_types) end def path_attributes - _belongs_to_params.merge attributes.slice( self.class.primary_key ).symbolize_keys + _belongs_to_params.merge attributes.slice( self.class.primary_key ).with_indifferent_access end protected diff --git a/test/unit/query_builder_test.rb b/test/unit/query_builder_test.rb index 4fdeaa2..6fbb134 100644 --- a/test/unit/query_builder_test.rb +++ b/test/unit/query_builder_test.rb @@ -308,7 +308,8 @@ def test_build_propagate_only_path_params query = ArticleNested.where(author_id: '123', name: 'John') record = query.build assert_equal [], record.changed - assert_equal({author_id: '123'}, record.__belongs_to_params) + assert_equal(record.__belongs_to_params[:author_id], '123') + assert_equal(record.__belongs_to_params['author_id'], '123') assert_equal '123', record.author_id assert_equal [], record.relationships.changed end