mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
ActiveModelSerializers::Model successor initialized with string keys fix (#1881)
This commit is contained in:
parent
5f3bdcc87c
commit
1896e5a525
@ -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:
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user