Add symbol support for ActiveModel::Serializer.type method

The ActiveModel::Serializer.type method now accepts symbol as paremeter:
class AuthorSerializer < ActiveModel::Serializer
  type :profile
end
The test file for the type was also refactored.
This commit is contained in:
Yohan Robert
2016-02-13 14:08:40 +01:00
committed by Yohan Robert
parent f02f0849b1
commit 727d7631ae
5 changed files with 83 additions and 73 deletions

View File

@@ -107,12 +107,30 @@ end
#### ::type
e.g.
The `::type` method defines the JSONAPI [type](http://jsonapi.org/format/#document-resource-object-identification) that will be rendered for this serializer.
It either takes a `String` or `Symbol` as parameter.
Note: This method is useful only when using the `:json_api` adapter.
Examples:
```ruby
class UserProfileSerializer < ActiveModel::Serializer
type 'profile'
end
class AuthorProfileSerializer < ActiveModel::Serializer
type :profile
end
```
With the `:json_api` adapter, the previous serializers would be rendered as:
``` json
{
"data": {
"id": "1",
"type": "profile"
}
}
```
#### ::link