Skip to content

Commit f7fb4db

Browse files
committed
Merge pull request #909 from joaomdmoura/json-api-default
Defining Json-API Adapter as Default
2 parents a59cc4c + 9b502a4 commit f7fb4db

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ AMS does this through two components: **serializers** and **adapters**.
88
Serializers describe _which_ attributes and relationships should be serialized.
99
Adapters describe _how_ attributes and relationships should be serialized.
1010

11+
By default AMS will use the JsonApi Adapter that follows RC3 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
12+
Check how to change the adapter in the sections bellow.
13+
1114
# RELEASE CANDIDATE, PLEASE READ
1215

1316
This is the master branch of AMS. It will become the `0.10.0` release when it's
@@ -47,17 +50,17 @@ end
4750
```
4851

4952
Generally speaking, you as a user of AMS will write (or generate) these
50-
serializer classes. If you want to use a different adapter, such as a JsonApi, you can
53+
serializer classes. If you want to use a different adapter, such as a normal Json adapter without the JsonApi conventions, you can
5154
change this in an initializer:
5255

5356
```ruby
54-
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
57+
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Json
5558
```
5659

5760
or
5861

5962
```ruby
60-
ActiveModel::Serializer.config.adapter = :json_api
63+
ActiveModel::Serializer.config.adapter = :json
6164
```
6265

6366
You won't need to implement an adapter unless you wish to use a new format or

lib/active_model/serializer/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Configuration
66

77
included do |base|
88
base.config.array_serializer = ActiveModel::Serializer::ArraySerializer
9-
base.config.adapter = :json
9+
base.config.adapter = :json_api
1010
end
1111
end
1212
end

test/action_controller/adapter_selector_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ActionController
44
module Serialization
55
class AdapterSelectorTest < ActionController::TestCase
66
class MyController < ActionController::Base
7-
def render_using_default_adapter
7+
def render_using_the_initializer_defined_adapter
88
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
99
render json: @profile
1010
end
@@ -23,7 +23,7 @@ def render_skipping_adapter
2323
tests MyController
2424

2525
def test_render_using_default_adapter
26-
get :render_using_default_adapter
26+
get :render_using_the_initializer_defined_adapter
2727
assert_equal '{"name":"Name 1","description":"Description 1"}', response.body
2828
end
2929

test/fixtures/poro.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ActiveModel::Serializer.config.adapter = :json
2+
13
class Model
24
def initialize(hash={})
35
@attributes = hash
@@ -64,7 +66,7 @@ class ProfilePreviewSerializer < ActiveModel::Serializer
6466
Bio = Class.new(Model)
6567
Blog = Class.new(Model)
6668
Role = Class.new(Model)
67-
User = Class.new(Model)
69+
User = Class.new(Model)
6870
Location = Class.new(Model)
6971
Place = Class.new(Model)
7072

0 commit comments

Comments
 (0)