Skip to content

Commit

Permalink
ActiveModelSerializers::Model successor initialized with string keys fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhene committed Aug 16, 2016
1 parent 5f3bdcc commit 4480a08
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features:
Fixes:

- [#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:

Expand Down
2 changes: 1 addition & 1 deletion lib/active_model_serializers/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Model
attr_reader :attributes, :errors

def initialize(attributes = {})
@attributes = attributes
@attributes = attributes && attributes.symbolize_keys
@errors = ActiveModel::Errors.new(self)
super
end
Expand Down
11 changes: 11 additions & 0 deletions test/active_model_serializers/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@ class ModelTest < ActiveSupport::TestCase
def setup
@resource = ActiveModelSerializers::Model.new
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

0 comments on commit 4480a08

Please sign in to comment.