Skip to content

Commit

Permalink
Merge pull request #1007 from jiajiawang/array_serializer_json_key_fix
Browse files Browse the repository at this point in the history
Bug fix for ArraySerializer json_key
  • Loading branch information
joaomdmoura committed Jul 16, 2015
2 parents 954e4c5 + 91ffec4 commit d714094
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_model/serializer/array_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def json_key
if @objects.first
@objects.first.json_key.pluralize
else
@resource.name.downcase.pluralize if @resource.try(:name)
@resource.name.underscore.pluralize if @resource.try(:name)
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/array_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def test_meta_and_meta_key_attr_readers
assert_equal @serializer.meta, "the meta"
assert_equal @serializer.meta_key, "the meta key"
end

def test_json_key_when_resource_is_empty
Array.class_eval do
def name
'PostComment'
end
end
@post_comments = []
@serializer = ArraySerializer.new(@post_comments)
assert_equal @serializer.json_key, "post_comments"
end
end
end
end

0 comments on commit d714094

Please sign in to comment.