Skip to content

Commit a9cb097

Browse files
committed
Refactoring
1 parent 06fcd34 commit a9cb097

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/active_model_serializers/adapter/attributes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def serializable_hash(options = nil)
1616
self.class.transform_key_casing!(serialized_hash, instance_options)
1717
end
1818

19+
private
20+
1921
def fields_to_fieldset(fields)
2022
return fields if fields.nil?
2123
resource_fields = []
@@ -27,7 +29,7 @@ def fields_to_fieldset(fields)
2729
else fail ArgumentError, "Unknown conversion of fields to fieldset: '#{field.inspect}' in '#{fields.inspect}'"
2830
end
2931
end
30-
relationship_fields.merge(serializer.json_key.to_sym => resource_fields)
32+
relationship_fields.merge!(serializer.json_key.to_sym => resource_fields)
3133
end
3234
end
3335
end

test/adapter/json/fields_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Comment < ::Model
1717
end
1818

1919
class PostSerializer < ActiveModel::Serializer
20-
type 'posts'
20+
type 'post'
2121
attributes :title, :body
2222
belongs_to :author
2323
has_many :comments
@@ -28,7 +28,7 @@ class AuthorSerializer < ActiveModel::Serializer
2828
end
2929

3030
class CommentSerializer < ActiveModel::Serializer
31-
type 'comments'
31+
type 'comment'
3232
attributes :title, :body
3333
belongs_to :author
3434
end
@@ -47,15 +47,15 @@ def test_fields_attributes
4747
fields = [:title]
4848
hash = serializable(@post, adapter: :json, fields: fields, include: []).serializable_hash
4949
expected = { title: 'Title 1' }
50-
assert_equal(expected, hash[:posts])
50+
assert_equal(expected, hash[:post])
5151
end
5252

5353
def test_fields_included
5454
fields = [:title, { comments: [:body] }]
5555
hash = serializable(@post, adapter: :json, include: [:comments], fields: fields).serializable_hash
5656
expected = [{ body: @comment1.body }, { body: @comment2.body }]
5757

58-
assert_equal(expected, hash[:posts][:comments])
58+
assert_equal(expected, hash[:post][:comments])
5959
end
6060
end
6161
end

0 commit comments

Comments
 (0)