From 2c9c36e21f5e414855db00e26d3d6d70db64f446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 10 May 2015 03:58:18 -0300 Subject: [PATCH 1/3] adding json_api as default adapter --- lib/active_model/serializer/configuration.rb | 2 +- test/fixtures/poro.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_model/serializer/configuration.rb b/lib/active_model/serializer/configuration.rb index ef57262c4..b46cf8a54 100644 --- a/lib/active_model/serializer/configuration.rb +++ b/lib/active_model/serializer/configuration.rb @@ -6,7 +6,7 @@ module Configuration included do |base| base.config.array_serializer = ActiveModel::Serializer::ArraySerializer - base.config.adapter = :json + base.config.adapter = :json_api end end end diff --git a/test/fixtures/poro.rb b/test/fixtures/poro.rb index b66395c37..986178fe2 100644 --- a/test/fixtures/poro.rb +++ b/test/fixtures/poro.rb @@ -1,3 +1,5 @@ +ActiveModel::Serializer.config.adapter = :json + class Model def initialize(hash={}) @attributes = hash @@ -64,7 +66,7 @@ class ProfilePreviewSerializer < ActiveModel::Serializer Bio = Class.new(Model) Blog = Class.new(Model) Role = Class.new(Model) -User = Class.new(Model) +User = Class.new(Model) Location = Class.new(Model) Place = Class.new(Model) From 738894e5b4e7539177637acbe895112a10155255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Mon, 11 May 2015 16:21:14 -0300 Subject: [PATCH 2/3] updating readme declaring JsonApi as default adapter --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 25d70b85f..05d836694 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ AMS does this through two components: **serializers** and **adapters**. Serializers describe _which_ attributes and relationships should be serialized. Adapters describe _how_ attributes and relationships should be serialized. +By default AMS will use the JsonApi Adapter that follows RC3 of the format specified in [jsonapi.org/format](http://jsonapi.org/format). +Check how to change the adapter in the sections bellow. + # RELEASE CANDIDATE, PLEASE READ This is the master branch of AMS. It will become the `0.10.0` release when it's @@ -47,17 +50,17 @@ end ``` Generally speaking, you as a user of AMS will write (or generate) these -serializer classes. If you want to use a different adapter, such as a JsonApi, you can +serializer classes. If you want to use a different adapter, such as a normal Json adapter without the JsonApi conventions, you can change this in an initializer: ```ruby -ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi +ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Json ``` or ```ruby -ActiveModel::Serializer.config.adapter = :json_api +ActiveModel::Serializer.config.adapter = :json ``` You won't need to implement an adapter unless you wish to use a new format or From 9b502a4ae0ea8a0e5574a169d5c705083d88948a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Mon, 11 May 2015 16:23:38 -0300 Subject: [PATCH 3/3] changing tests name to support new default adapter --- test/action_controller/adapter_selector_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/action_controller/adapter_selector_test.rb b/test/action_controller/adapter_selector_test.rb index efa61f7b1..07bdf0a72 100644 --- a/test/action_controller/adapter_selector_test.rb +++ b/test/action_controller/adapter_selector_test.rb @@ -4,7 +4,7 @@ module ActionController module Serialization class AdapterSelectorTest < ActionController::TestCase class MyController < ActionController::Base - def render_using_default_adapter + def render_using_the_initializer_defined_adapter @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) render json: @profile end @@ -23,7 +23,7 @@ def render_skipping_adapter tests MyController def test_render_using_default_adapter - get :render_using_default_adapter + get :render_using_the_initializer_defined_adapter assert_equal '{"name":"Name 1","description":"Description 1"}', response.body end