From 88367da9702c241e1dc9c4b60350b152c118effa Mon Sep 17 00:00:00 2001 From: Nate Pinsky Date: Tue, 24 Oct 2017 15:30:57 -0700 Subject: [PATCH] Add warnings about global adapter config to docs (#2176) --- CHANGELOG.md | 2 ++ docs/general/adapters.md | 6 ++++++ docs/howto/add_root_key.md | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56059d96..bccdece0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ Fixes: Misc: +- #2176 Documentation for global adapter config (@mrpinsky) + ### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6) Fixes: diff --git a/docs/general/adapters.md b/docs/general/adapters.md index 84fc4e62..39d85f6b 100644 --- a/docs/general/adapters.md +++ b/docs/general/adapters.md @@ -36,6 +36,12 @@ The `Attributes` adapter does not include a root key. It is just the serialized Use either the `JSON` or `JSON API` adapters if you want the response document to have a root key. +***IMPORTANT***: Adapter configuration has *no effect* on a serializer instance +being used directly. That is, `UserSerializer.new(user).as_json` will *always* +behave as if the adapter were the 'Attributes' adapter. See [Outside Controller +Usage](../howto/outside_controller_use.md) for more details on recommended +usage. + ## Built in Adapters ### Attributes - Default diff --git a/docs/howto/add_root_key.md b/docs/howto/add_root_key.md index 82a4ab6f..6d8c3269 100644 --- a/docs/howto/add_root_key.md +++ b/docs/howto/add_root_key.md @@ -18,6 +18,13 @@ In order to add the root key you need to use the ```JSON``` Adapter, you can cha ActiveModelSerializers.config.adapter = :json ``` +Note that adapter configuration has no effect on a serializer that is called +directly, e.g. in a serializer unit test. Instead, something like +`UserSerializer.new(user).as_json` will *always* behave as if the adapter were +the 'Attributes' adapter. See [Outside Controller +Usage](../howto/outside_controller_use.md) for more details on recommended +usage. + You can also specify a class as adapter, as long as it complies with the ActiveModelSerializers adapters interface. It will add the root key to all your serialized endpoints.