From 56eaa61233f6b6e7c1a302bfb247c8385e7cf3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Schr=C3=B6der?= Date: Tue, 13 Aug 2013 15:17:16 +0200 Subject: [PATCH] add an example for how to test serializers easily off topic: please deactivate the WIKI if there is no content in it --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 65a3b79f..48885816 100644 --- a/README.md +++ b/README.md @@ -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: