ActiveModelSerializers::Model successor initialized with string keys fix (#1881)

This commit is contained in:
Yevhen Shemet 2016-08-16 13:49:10 +03:00 committed by L. Preston Sego III
parent 5f3bdcc87c
commit 1896e5a525
3 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,7 @@ Features:
Fixes: Fixes:
- [#1833](https://github.com/rails-api/active_model_serializers/pull/1833) Remove relationship links if they are null (@groyoh) - [#1833](https://github.com/rails-api/active_model_serializers/pull/1833) Remove relationship links if they are null (@groyoh)
- [#1881](https://github.com/rails-api/active_model_serializers/pull/1881) ActiveModelSerializers::Model correctly works with string keys (@yevhene)
Misc: Misc:

View File

@ -9,7 +9,7 @@ module ActiveModelSerializers
attr_reader :attributes, :errors attr_reader :attributes, :errors
def initialize(attributes = {}) def initialize(attributes = {})
@attributes = attributes @attributes = attributes && attributes.symbolize_keys
@errors = ActiveModel::Errors.new(self) @errors = ActiveModel::Errors.new(self)
super super
end end

View File

@ -7,5 +7,16 @@ module ActiveModelSerializers
def setup def setup
@resource = ActiveModelSerializers::Model.new @resource = ActiveModelSerializers::Model.new
end end
def test_initialization_with_string_keys
klass = Class.new(ActiveModelSerializers::Model) do
attr_accessor :key
end
value = 'value'
model_instance = klass.new('key' => value)
assert_equal model_instance.read_attribute_for_serialization(:key), value
end
end end
end end