add an example for how to test serializers easily

off topic: please deactivate the WIKI if there is no content in it
This commit is contained in:
Peter Schröder 2013-08-13 15:17:16 +02:00
parent 8ac4bf9006
commit 56eaa61233

View File

@ -676,6 +676,17 @@ for the current user, the advantage of this approach is that, by setting
`serialization_scope` to `nil`, the `index` action no longer will need to make
that query, only the `show` action will.
## Testing
In order to test a Serializer, you can just call `.new` on it, passing the object to serialize:
```ruby
post = Post.first
serializer = PostSerializer.new post
serializer.to_json
# => "{\"post\":{\"id\":1...}}"
```
## Caching
To cache a serializer, call `cached` and define a `cache_key` method: