active_model_serializers 0.10.0.rc2 → 0.10.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +82 -0
- data/.rubocop_todo.yml +315 -0
- data/.simplecov +99 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +9 -3
- data/Gemfile +39 -8
- data/README.md +55 -31
- data/Rakefile +29 -2
- data/active_model_serializers.gemspec +37 -13
- data/appveyor.yml +25 -0
- data/docs/README.md +29 -0
- data/docs/general/adapters.md +110 -0
- data/docs/general/configuration_options.md +11 -0
- data/docs/general/getting_started.md +73 -0
- data/docs/howto/add_pagination_links.md +112 -0
- data/docs/howto/add_root_key.md +51 -0
- data/docs/howto/outside_controller_use.md +42 -0
- data/lib/action_controller/serialization.rb +24 -33
- data/lib/active_model/serializable_resource.rb +70 -0
- data/lib/active_model/serializer.rb +50 -131
- data/lib/active_model/serializer/adapter.rb +84 -21
- data/lib/active_model/serializer/adapter/flatten_json.rb +9 -9
- data/lib/active_model/serializer/adapter/fragment_cache.rb +10 -13
- data/lib/active_model/serializer/adapter/json.rb +25 -28
- data/lib/active_model/serializer/adapter/json/fragment_cache.rb +2 -12
- data/lib/active_model/serializer/adapter/json_api.rb +100 -98
- data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +4 -14
- data/lib/active_model/serializer/adapter/json_api/pagination_links.rb +50 -0
- data/lib/active_model/serializer/adapter/null.rb +2 -8
- data/lib/active_model/serializer/array_serializer.rb +22 -17
- data/lib/active_model/serializer/association.rb +20 -0
- data/lib/active_model/serializer/associations.rb +97 -0
- data/lib/active_model/serializer/belongs_to_reflection.rb +10 -0
- data/lib/active_model/serializer/collection_reflection.rb +7 -0
- data/lib/active_model/serializer/configuration.rb +1 -0
- data/lib/active_model/serializer/fieldset.rb +7 -7
- data/lib/active_model/serializer/has_many_reflection.rb +10 -0
- data/lib/active_model/serializer/has_one_reflection.rb +10 -0
- data/lib/active_model/serializer/lint.rb +129 -0
- data/lib/active_model/serializer/railtie.rb +7 -0
- data/lib/active_model/serializer/reflection.rb +74 -0
- data/lib/active_model/serializer/singular_reflection.rb +7 -0
- data/lib/active_model/serializer/utils.rb +35 -0
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model_serializers.rb +28 -14
- data/lib/generators/serializer/serializer_generator.rb +7 -7
- data/lib/generators/serializer/templates/{serializer.rb → serializer.rb.erb} +2 -2
- data/lib/tasks/rubocop.rake +0 -0
- data/test/action_controller/adapter_selector_test.rb +3 -3
- data/test/action_controller/explicit_serializer_test.rb +9 -9
- data/test/action_controller/json_api/linked_test.rb +179 -0
- data/test/action_controller/json_api/pagination_test.rb +116 -0
- data/test/action_controller/serialization_scope_name_test.rb +10 -6
- data/test/action_controller/serialization_test.rb +149 -112
- data/test/active_record_test.rb +9 -0
- data/test/adapter/fragment_cache_test.rb +11 -1
- data/test/adapter/json/belongs_to_test.rb +4 -5
- data/test/adapter/json/collection_test.rb +30 -21
- data/test/adapter/json/has_many_test.rb +20 -9
- data/test/adapter/json_api/belongs_to_test.rb +38 -38
- data/test/adapter/json_api/collection_test.rb +22 -23
- data/test/adapter/json_api/has_many_embed_ids_test.rb +2 -2
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +4 -4
- data/test/adapter/json_api/has_many_test.rb +54 -19
- data/test/adapter/json_api/has_one_test.rb +28 -8
- data/test/adapter/json_api/json_api_test.rb +37 -0
- data/test/adapter/json_api/linked_test.rb +75 -75
- data/test/adapter/json_api/pagination_links_test.rb +115 -0
- data/test/adapter/json_api/resource_type_config_test.rb +59 -0
- data/test/adapter/json_test.rb +18 -5
- data/test/adapter_test.rb +10 -11
- data/test/array_serializer_test.rb +63 -5
- data/test/capture_warnings.rb +65 -0
- data/test/fixtures/active_record.rb +56 -0
- data/test/fixtures/poro.rb +60 -29
- data/test/generators/scaffold_controller_generator_test.rb +1 -2
- data/test/generators/serializer_generator_test.rb +17 -12
- data/test/lint_test.rb +37 -0
- data/test/logger_test.rb +18 -0
- data/test/poro_test.rb +9 -0
- data/test/serializable_resource_test.rb +27 -0
- data/test/serializers/adapter_for_test.rb +123 -3
- data/test/serializers/association_macros_test.rb +36 -0
- data/test/serializers/associations_test.rb +70 -47
- data/test/serializers/attribute_test.rb +28 -4
- data/test/serializers/attributes_test.rb +8 -14
- data/test/serializers/cache_test.rb +58 -31
- data/test/serializers/fieldset_test.rb +3 -4
- data/test/serializers/meta_test.rb +42 -28
- data/test/serializers/root_test.rb +21 -0
- data/test/serializers/serializer_for_test.rb +1 -1
- data/test/support/rails_app.rb +21 -0
- data/test/support/serialization_testing.rb +13 -0
- data/test/support/simplecov.rb +6 -0
- data/test/support/stream_capture.rb +50 -0
- data/test/support/test_case.rb +5 -0
- data/test/test_helper.rb +41 -29
- data/test/utils/include_args_to_hash_test.rb +79 -0
- metadata +123 -17
- data/test/action_controller/json_api_linked_test.rb +0 -179
- data/test/action_controller/rescue_from_test.rb +0 -32
- data/test/serializers/urls_test.rb +0 -26
@@ -24,7 +24,7 @@ module ActiveModel
|
|
24
24
|
@serializer = PostPreviewSerializer.new(@post)
|
25
25
|
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
26
26
|
@serializer,
|
27
|
-
include: [
|
27
|
+
include: [:comments, :author]
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
@@ -58,9 +58,9 @@ module ActiveModel
|
|
58
58
|
},
|
59
59
|
{
|
60
60
|
id: @author.id.to_s,
|
61
|
-
type:
|
61
|
+
type: 'authors',
|
62
62
|
relationships: {
|
63
|
-
posts: { data: [
|
63
|
+
posts: { data: [{ type: 'posts', id: @post.id.to_s }] }
|
64
64
|
}
|
65
65
|
}
|
66
66
|
]
|
@@ -70,7 +70,7 @@ module ActiveModel
|
|
70
70
|
|
71
71
|
def test_includes_author_id
|
72
72
|
expected = {
|
73
|
-
data: { type:
|
73
|
+
data: { type: 'authors', id: @author.id.to_s }
|
74
74
|
}
|
75
75
|
|
76
76
|
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:author])
|
@@ -22,42 +22,45 @@ module ActiveModel
|
|
22
22
|
@second_comment.post = @post
|
23
23
|
@post.author = @author
|
24
24
|
@post_without_comments.author = nil
|
25
|
-
@blog = Blog.new(id: 1, name:
|
25
|
+
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
26
26
|
@blog.writer = @author
|
27
27
|
@blog.articles = [@post]
|
28
28
|
@post.blog = @blog
|
29
29
|
@post_without_comments.blog = nil
|
30
|
-
|
30
|
+
@tag = Tag.new(id: 1, name: '#hash_tag')
|
31
|
+
@post.tags = [@tag]
|
31
32
|
@serializer = PostSerializer.new(@post)
|
32
33
|
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)
|
34
|
+
|
35
|
+
@virtual_value = VirtualValue.new(id: 1)
|
33
36
|
end
|
34
37
|
|
35
38
|
def test_includes_comment_ids
|
36
|
-
expected = { data: [
|
39
|
+
expected = { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] }
|
37
40
|
|
38
41
|
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:comments])
|
39
42
|
end
|
40
43
|
|
41
44
|
def test_includes_linked_comments
|
42
|
-
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include:
|
45
|
+
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:comments])
|
43
46
|
expected = [{
|
44
|
-
id:
|
45
|
-
type:
|
47
|
+
id: '1',
|
48
|
+
type: 'comments',
|
46
49
|
attributes: {
|
47
50
|
body: 'ZOMG A COMMENT'
|
48
51
|
},
|
49
52
|
relationships: {
|
50
|
-
post: { data: { type:
|
53
|
+
post: { data: { type: 'posts', id: '1' } },
|
51
54
|
author: { data: nil }
|
52
55
|
}
|
53
56
|
}, {
|
54
|
-
id:
|
55
|
-
type:
|
57
|
+
id: '2',
|
58
|
+
type: 'comments',
|
56
59
|
attributes: {
|
57
60
|
body: 'ZOMG ANOTHER COMMENT'
|
58
61
|
},
|
59
62
|
relationships: {
|
60
|
-
post: { data: { type:
|
63
|
+
post: { data: { type: 'posts', id: '1' } },
|
61
64
|
author: { data: nil }
|
62
65
|
}
|
63
66
|
}]
|
@@ -65,19 +68,19 @@ module ActiveModel
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def test_limit_fields_of_linked_comments
|
68
|
-
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include:
|
71
|
+
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:comments], fields: { comment: [:id] })
|
69
72
|
expected = [{
|
70
|
-
id:
|
71
|
-
type:
|
73
|
+
id: '1',
|
74
|
+
type: 'comments',
|
72
75
|
relationships: {
|
73
|
-
post: { data: { type:
|
76
|
+
post: { data: { type: 'posts', id: '1' } },
|
74
77
|
author: { data: nil }
|
75
78
|
}
|
76
79
|
}, {
|
77
|
-
id:
|
78
|
-
type:
|
80
|
+
id: '2',
|
81
|
+
type: 'comments',
|
79
82
|
relationships: {
|
80
|
-
post: { data: { type:
|
83
|
+
post: { data: { type: 'posts', id: '1' } },
|
81
84
|
author: { data: nil }
|
82
85
|
}
|
83
86
|
}]
|
@@ -95,14 +98,46 @@ module ActiveModel
|
|
95
98
|
serializer = BlogSerializer.new(@blog)
|
96
99
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
97
100
|
actual = adapter.serializable_hash[:data][:relationships][:articles]
|
101
|
+
|
98
102
|
expected = {
|
99
103
|
data: [{
|
100
|
-
type:
|
101
|
-
id:
|
104
|
+
type: 'posts',
|
105
|
+
id: '1'
|
102
106
|
}]
|
103
107
|
}
|
104
108
|
assert_equal expected, actual
|
105
109
|
end
|
110
|
+
|
111
|
+
def test_has_many_with_no_serializer
|
112
|
+
serializer = PostWithTagsSerializer.new(@post)
|
113
|
+
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
114
|
+
|
115
|
+
assert_equal({
|
116
|
+
data: {
|
117
|
+
id: '1',
|
118
|
+
type: 'posts',
|
119
|
+
relationships: {
|
120
|
+
tags: { data: [@tag.as_json] }
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}, adapter.serializable_hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_has_many_with_virtual_value
|
127
|
+
serializer = VirtualValueSerializer.new(@virtual_value)
|
128
|
+
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
129
|
+
|
130
|
+
assert_equal({
|
131
|
+
data: {
|
132
|
+
id: '1',
|
133
|
+
type: 'virtual_values',
|
134
|
+
relationships: {
|
135
|
+
maker: { data: { id: 1 } },
|
136
|
+
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}, adapter.serializable_hash)
|
140
|
+
end
|
106
141
|
end
|
107
142
|
end
|
108
143
|
end
|
@@ -19,41 +19,61 @@ module ActiveModel
|
|
19
19
|
@comment.author = nil
|
20
20
|
@post.author = @author
|
21
21
|
@anonymous_post.author = nil
|
22
|
-
@blog = Blog.new(id: 1, name:
|
22
|
+
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
23
23
|
@blog.writer = @author
|
24
24
|
@blog.articles = [@post, @anonymous_post]
|
25
25
|
@author.posts = []
|
26
26
|
@author.roles = []
|
27
27
|
|
28
|
+
@virtual_value = VirtualValue.new(id: 1)
|
29
|
+
|
28
30
|
@serializer = AuthorSerializer.new(@author)
|
29
|
-
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include:
|
31
|
+
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:bio, :posts])
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_includes_bio_id
|
33
|
-
expected = { data: { type:
|
35
|
+
expected = { data: { type: 'bios', id: '43' } }
|
34
36
|
|
35
37
|
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:bio])
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_includes_linked_bio
|
39
|
-
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include:
|
41
|
+
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:bio])
|
40
42
|
|
41
43
|
expected = [
|
42
44
|
{
|
43
|
-
id:
|
44
|
-
type:
|
45
|
+
id: '43',
|
46
|
+
type: 'bios',
|
45
47
|
attributes: {
|
46
|
-
content:
|
48
|
+
content: 'AMS Contributor',
|
47
49
|
rating: nil
|
48
50
|
},
|
49
51
|
relationships: {
|
50
|
-
author: { data: { type:
|
52
|
+
author: { data: { type: 'authors', id: '1' } }
|
51
53
|
}
|
52
54
|
}
|
53
55
|
]
|
54
56
|
|
55
57
|
assert_equal(expected, @adapter.serializable_hash[:included])
|
56
58
|
end
|
59
|
+
|
60
|
+
def test_has_one_with_virtual_value
|
61
|
+
serializer = VirtualValueSerializer.new(@virtual_value)
|
62
|
+
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
63
|
+
|
64
|
+
expected = {
|
65
|
+
data: {
|
66
|
+
id: '1',
|
67
|
+
type: 'virtual_values',
|
68
|
+
relationships: {
|
69
|
+
maker: { data: { id: 1 } },
|
70
|
+
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
assert_equal(expected, adapter.serializable_hash)
|
76
|
+
end
|
57
77
|
end
|
58
78
|
end
|
59
79
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class Adapter
|
6
|
+
class JsonApiTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
ActionController::Base.cache_store.clear
|
9
|
+
@author = Author.new(id: 1, name: 'Steve K.')
|
10
|
+
@post = Post.new(id: 1, title: 'New Post', body: 'Body')
|
11
|
+
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
12
|
+
@second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
|
13
|
+
@post.comments = [@first_comment, @second_comment]
|
14
|
+
@first_comment.post = @post
|
15
|
+
@second_comment.post = @post
|
16
|
+
@post.author = @author
|
17
|
+
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
18
|
+
@post.blog = @blog
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_custom_keys
|
22
|
+
serializer = PostWithCustomKeysSerializer.new(@post)
|
23
|
+
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
24
|
+
|
25
|
+
assert_equal({
|
26
|
+
reviews: { data: [
|
27
|
+
{ type: 'comments', id: '1' },
|
28
|
+
{ type: 'comments', id: '2' }
|
29
|
+
] },
|
30
|
+
writer: { data: { type: 'authors', id: '1' } },
|
31
|
+
site: { data: { type: 'blogs', id: '1' } }
|
32
|
+
}, adapter.serializable_hash[:data][:relationships])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -43,104 +43,104 @@ module ActiveModel
|
|
43
43
|
serializer = ArraySerializer.new([@first_post, @second_post])
|
44
44
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
45
45
|
serializer,
|
46
|
-
include: [
|
46
|
+
include: [:comments, author: [:bio]]
|
47
47
|
)
|
48
48
|
alt_adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
49
49
|
serializer,
|
50
|
-
include:
|
50
|
+
include: [:comments, author: [:bio]]
|
51
51
|
)
|
52
52
|
|
53
53
|
expected = {
|
54
54
|
data: [
|
55
55
|
{
|
56
|
-
id:
|
57
|
-
type:
|
56
|
+
id: '10',
|
57
|
+
type: 'posts',
|
58
58
|
attributes: {
|
59
|
-
title:
|
60
|
-
body:
|
59
|
+
title: 'Hello!!',
|
60
|
+
body: 'Hello, world!!'
|
61
61
|
},
|
62
62
|
relationships: {
|
63
|
-
comments: { data: [
|
64
|
-
blog: { data: { type:
|
65
|
-
author: { data: { type:
|
63
|
+
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
64
|
+
blog: { data: { type: 'blogs', id: '999' } },
|
65
|
+
author: { data: { type: 'authors', id: '1' } }
|
66
66
|
}
|
67
67
|
},
|
68
68
|
{
|
69
|
-
id:
|
70
|
-
type:
|
69
|
+
id: '20',
|
70
|
+
type: 'posts',
|
71
71
|
attributes: {
|
72
|
-
title:
|
73
|
-
body:
|
72
|
+
title: 'New Post',
|
73
|
+
body: 'Body'
|
74
74
|
},
|
75
75
|
relationships: {
|
76
76
|
comments: { data: [] },
|
77
|
-
blog: { data: { type:
|
78
|
-
author: { data: { type:
|
77
|
+
blog: { data: { type: 'blogs', id: '999' } },
|
78
|
+
author: { data: { type: 'authors', id: '2' } }
|
79
79
|
}
|
80
80
|
}
|
81
81
|
],
|
82
82
|
included: [
|
83
83
|
{
|
84
|
-
id:
|
85
|
-
type:
|
84
|
+
id: '1',
|
85
|
+
type: 'comments',
|
86
86
|
attributes: {
|
87
|
-
body:
|
87
|
+
body: 'ZOMG A COMMENT'
|
88
88
|
},
|
89
89
|
relationships: {
|
90
|
-
post: { data: { type:
|
90
|
+
post: { data: { type: 'posts', id: '10' } },
|
91
91
|
author: { data: nil }
|
92
92
|
}
|
93
93
|
}, {
|
94
|
-
id:
|
95
|
-
type:
|
94
|
+
id: '2',
|
95
|
+
type: 'comments',
|
96
96
|
attributes: {
|
97
|
-
body:
|
97
|
+
body: 'ZOMG ANOTHER COMMENT',
|
98
98
|
},
|
99
99
|
relationships: {
|
100
|
-
post: { data: { type:
|
100
|
+
post: { data: { type: 'posts', id: '10' } },
|
101
101
|
author: { data: nil }
|
102
102
|
}
|
103
103
|
}, {
|
104
|
-
id:
|
105
|
-
type:
|
104
|
+
id: '1',
|
105
|
+
type: 'authors',
|
106
106
|
attributes: {
|
107
|
-
name:
|
107
|
+
name: 'Steve K.'
|
108
108
|
},
|
109
109
|
relationships: {
|
110
|
-
posts: { data: [
|
110
|
+
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
111
111
|
roles: { data: [] },
|
112
|
-
bio: { data: { type:
|
112
|
+
bio: { data: { type: 'bios', id: '1' } }
|
113
113
|
}
|
114
114
|
}, {
|
115
|
-
id:
|
116
|
-
type:
|
115
|
+
id: '1',
|
116
|
+
type: 'bios',
|
117
117
|
attributes: {
|
118
|
-
content:
|
118
|
+
content: 'AMS Contributor',
|
119
119
|
rating: nil
|
120
120
|
},
|
121
121
|
relationships: {
|
122
|
-
author: { data: { type:
|
122
|
+
author: { data: { type: 'authors', id: '1' } }
|
123
123
|
}
|
124
124
|
}, {
|
125
|
-
id:
|
126
|
-
type:
|
125
|
+
id: '2',
|
126
|
+
type: 'authors',
|
127
127
|
attributes: {
|
128
|
-
name:
|
128
|
+
name: 'Tenderlove'
|
129
129
|
},
|
130
130
|
relationships: {
|
131
|
-
posts: { data: [
|
131
|
+
posts: { data: [{ type: 'posts', id: '20' }] },
|
132
132
|
roles: { data: [] },
|
133
|
-
bio: { data: { type:
|
133
|
+
bio: { data: { type: 'bios', id: '2' } }
|
134
134
|
}
|
135
135
|
}, {
|
136
|
-
id:
|
137
|
-
type:
|
136
|
+
id: '2',
|
137
|
+
type: 'bios',
|
138
138
|
attributes: {
|
139
139
|
rating: nil,
|
140
|
-
content:
|
140
|
+
content: 'Rails Contributor',
|
141
141
|
},
|
142
142
|
relationships: {
|
143
|
-
author: { data: { type:
|
143
|
+
author: { data: { type: 'authors', id: '2' } }
|
144
144
|
}
|
145
145
|
}
|
146
146
|
]
|
@@ -153,48 +153,48 @@ module ActiveModel
|
|
153
153
|
serializer = BioSerializer.new @bio1
|
154
154
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
155
155
|
serializer,
|
156
|
-
include: [
|
156
|
+
include: [author: [:posts]]
|
157
157
|
)
|
158
158
|
alt_adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
159
159
|
serializer,
|
160
|
-
include:
|
160
|
+
include: [author: [:posts]]
|
161
161
|
)
|
162
162
|
|
163
163
|
expected = [
|
164
164
|
{
|
165
|
-
id:
|
166
|
-
type:
|
165
|
+
id: '1',
|
166
|
+
type: 'authors',
|
167
167
|
attributes: {
|
168
|
-
name:
|
168
|
+
name: 'Steve K.'
|
169
169
|
},
|
170
170
|
relationships: {
|
171
|
-
posts: { data: [
|
171
|
+
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
172
172
|
roles: { data: [] },
|
173
|
-
bio: { data: { type:
|
173
|
+
bio: { data: { type: 'bios', id: '1' } }
|
174
174
|
}
|
175
175
|
}, {
|
176
|
-
id:
|
177
|
-
type:
|
176
|
+
id: '10',
|
177
|
+
type: 'posts',
|
178
178
|
attributes: {
|
179
|
-
title:
|
180
|
-
body:
|
179
|
+
title: 'Hello!!',
|
180
|
+
body: 'Hello, world!!'
|
181
181
|
},
|
182
182
|
relationships: {
|
183
|
-
comments: { data: [
|
184
|
-
blog: { data: { type:
|
185
|
-
author: { data: { type:
|
183
|
+
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
184
|
+
blog: { data: { type: 'blogs', id: '999' } },
|
185
|
+
author: { data: { type: 'authors', id: '1' } }
|
186
186
|
}
|
187
187
|
}, {
|
188
|
-
id:
|
189
|
-
type:
|
188
|
+
id: '30',
|
189
|
+
type: 'posts',
|
190
190
|
attributes: {
|
191
|
-
title:
|
192
|
-
body:
|
191
|
+
title: 'Yet Another Post',
|
192
|
+
body: 'Body'
|
193
193
|
},
|
194
194
|
relationships: {
|
195
195
|
comments: { data: [] },
|
196
|
-
blog: { data: { type:
|
197
|
-
author: { data: { type:
|
196
|
+
blog: { data: { type: 'blogs', id: '999' } },
|
197
|
+
author: { data: { type: 'authors', id: '1' } }
|
198
198
|
}
|
199
199
|
}
|
200
200
|
]
|
@@ -224,26 +224,26 @@ module ActiveModel
|
|
224
224
|
serializer = ArraySerializer.new([@first_comment, @second_comment])
|
225
225
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
226
226
|
serializer,
|
227
|
-
include: [
|
227
|
+
include: [:post]
|
228
228
|
)
|
229
229
|
|
230
230
|
expected = [
|
231
231
|
{
|
232
|
-
id:
|
233
|
-
type:
|
232
|
+
id: '10',
|
233
|
+
type: 'posts',
|
234
234
|
attributes: {
|
235
|
-
title:
|
236
|
-
body:
|
235
|
+
title: 'Hello!!',
|
236
|
+
body: 'Hello, world!!'
|
237
237
|
},
|
238
238
|
relationships: {
|
239
239
|
comments: {
|
240
|
-
data: [{type:
|
240
|
+
data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }]
|
241
241
|
},
|
242
242
|
blog: {
|
243
|
-
data: {type:
|
243
|
+
data: { type: 'blogs', id: '999' }
|
244
244
|
},
|
245
245
|
author: {
|
246
|
-
data: {type:
|
246
|
+
data: { type: 'authors', id: '1' }
|
247
247
|
}
|
248
248
|
}
|
249
249
|
}
|
@@ -257,19 +257,19 @@ module ActiveModel
|
|
257
257
|
serializer = PostPreviewSerializer.new(@first_post)
|
258
258
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
259
259
|
serializer,
|
260
|
-
include: [
|
260
|
+
include: [:author]
|
261
261
|
)
|
262
262
|
|
263
263
|
expected = {
|
264
264
|
data: {
|
265
|
-
id:
|
266
|
-
type:
|
265
|
+
id: '10',
|
266
|
+
type: 'posts',
|
267
267
|
attributes: {
|
268
|
-
title:
|
269
|
-
body:
|
268
|
+
title: 'Hello!!',
|
269
|
+
body: 'Hello, world!!'
|
270
270
|
},
|
271
271
|
relationships: {
|
272
|
-
comments: { data: [
|
272
|
+
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
273
273
|
author: { data: nil }
|
274
274
|
}
|
275
275
|
}
|