File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
lib/active_model_serializers
test/active_model_serializers Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ Features:
1212Fixes:
1313
1414- [ #1833 ] ( https://github.com/rails-api/active_model_serializers/pull/1833 ) Remove relationship links if they are null (@groyoh )
15+ - [ #1881 ] ( https://github.com/rails-api/active_model_serializers/pull/1881 ) ActiveModelSerializers::Model correctly works with string keys (@yevhene )
1516
1617Misc:
1718
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class Model
99 attr_reader :attributes , :errors
1010
1111 def initialize ( attributes = { } )
12- @attributes = attributes
12+ @attributes = attributes && attributes . symbolize_keys
1313 @errors = ActiveModel ::Errors . new ( self )
1414 super
1515 end
Original file line number Diff line number Diff line change @@ -7,5 +7,16 @@ class ModelTest < ActiveSupport::TestCase
77 def setup
88 @resource = ActiveModelSerializers ::Model . new
99 end
10+
11+ def test_initialization_with_string_keys
12+ klass = Class . new ( ActiveModelSerializers ::Model ) do
13+ attr_accessor :key
14+ end
15+ value = 'value'
16+
17+ model_instance = klass . new ( 'key' => value )
18+
19+ assert_equal model_instance . read_attribute_for_serialization ( :key ) , value
20+ end
1021 end
1122end
You can’t perform that action at this time.
0 commit comments