active_model_serializers 0.10.0.rc2 → 0.10.0.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +82 -0
  4. data/.rubocop_todo.yml +315 -0
  5. data/.simplecov +99 -0
  6. data/.travis.yml +8 -0
  7. data/CHANGELOG.md +9 -3
  8. data/Gemfile +39 -8
  9. data/README.md +55 -31
  10. data/Rakefile +29 -2
  11. data/active_model_serializers.gemspec +37 -13
  12. data/appveyor.yml +25 -0
  13. data/docs/README.md +29 -0
  14. data/docs/general/adapters.md +110 -0
  15. data/docs/general/configuration_options.md +11 -0
  16. data/docs/general/getting_started.md +73 -0
  17. data/docs/howto/add_pagination_links.md +112 -0
  18. data/docs/howto/add_root_key.md +51 -0
  19. data/docs/howto/outside_controller_use.md +42 -0
  20. data/lib/action_controller/serialization.rb +24 -33
  21. data/lib/active_model/serializable_resource.rb +70 -0
  22. data/lib/active_model/serializer.rb +50 -131
  23. data/lib/active_model/serializer/adapter.rb +84 -21
  24. data/lib/active_model/serializer/adapter/flatten_json.rb +9 -9
  25. data/lib/active_model/serializer/adapter/fragment_cache.rb +10 -13
  26. data/lib/active_model/serializer/adapter/json.rb +25 -28
  27. data/lib/active_model/serializer/adapter/json/fragment_cache.rb +2 -12
  28. data/lib/active_model/serializer/adapter/json_api.rb +100 -98
  29. data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +4 -14
  30. data/lib/active_model/serializer/adapter/json_api/pagination_links.rb +50 -0
  31. data/lib/active_model/serializer/adapter/null.rb +2 -8
  32. data/lib/active_model/serializer/array_serializer.rb +22 -17
  33. data/lib/active_model/serializer/association.rb +20 -0
  34. data/lib/active_model/serializer/associations.rb +97 -0
  35. data/lib/active_model/serializer/belongs_to_reflection.rb +10 -0
  36. data/lib/active_model/serializer/collection_reflection.rb +7 -0
  37. data/lib/active_model/serializer/configuration.rb +1 -0
  38. data/lib/active_model/serializer/fieldset.rb +7 -7
  39. data/lib/active_model/serializer/has_many_reflection.rb +10 -0
  40. data/lib/active_model/serializer/has_one_reflection.rb +10 -0
  41. data/lib/active_model/serializer/lint.rb +129 -0
  42. data/lib/active_model/serializer/railtie.rb +7 -0
  43. data/lib/active_model/serializer/reflection.rb +74 -0
  44. data/lib/active_model/serializer/singular_reflection.rb +7 -0
  45. data/lib/active_model/serializer/utils.rb +35 -0
  46. data/lib/active_model/serializer/version.rb +1 -1
  47. data/lib/active_model_serializers.rb +28 -14
  48. data/lib/generators/serializer/serializer_generator.rb +7 -7
  49. data/lib/generators/serializer/templates/{serializer.rb → serializer.rb.erb} +2 -2
  50. data/lib/tasks/rubocop.rake +0 -0
  51. data/test/action_controller/adapter_selector_test.rb +3 -3
  52. data/test/action_controller/explicit_serializer_test.rb +9 -9
  53. data/test/action_controller/json_api/linked_test.rb +179 -0
  54. data/test/action_controller/json_api/pagination_test.rb +116 -0
  55. data/test/action_controller/serialization_scope_name_test.rb +10 -6
  56. data/test/action_controller/serialization_test.rb +149 -112
  57. data/test/active_record_test.rb +9 -0
  58. data/test/adapter/fragment_cache_test.rb +11 -1
  59. data/test/adapter/json/belongs_to_test.rb +4 -5
  60. data/test/adapter/json/collection_test.rb +30 -21
  61. data/test/adapter/json/has_many_test.rb +20 -9
  62. data/test/adapter/json_api/belongs_to_test.rb +38 -38
  63. data/test/adapter/json_api/collection_test.rb +22 -23
  64. data/test/adapter/json_api/has_many_embed_ids_test.rb +2 -2
  65. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +4 -4
  66. data/test/adapter/json_api/has_many_test.rb +54 -19
  67. data/test/adapter/json_api/has_one_test.rb +28 -8
  68. data/test/adapter/json_api/json_api_test.rb +37 -0
  69. data/test/adapter/json_api/linked_test.rb +75 -75
  70. data/test/adapter/json_api/pagination_links_test.rb +115 -0
  71. data/test/adapter/json_api/resource_type_config_test.rb +59 -0
  72. data/test/adapter/json_test.rb +18 -5
  73. data/test/adapter_test.rb +10 -11
  74. data/test/array_serializer_test.rb +63 -5
  75. data/test/capture_warnings.rb +65 -0
  76. data/test/fixtures/active_record.rb +56 -0
  77. data/test/fixtures/poro.rb +60 -29
  78. data/test/generators/scaffold_controller_generator_test.rb +1 -2
  79. data/test/generators/serializer_generator_test.rb +17 -12
  80. data/test/lint_test.rb +37 -0
  81. data/test/logger_test.rb +18 -0
  82. data/test/poro_test.rb +9 -0
  83. data/test/serializable_resource_test.rb +27 -0
  84. data/test/serializers/adapter_for_test.rb +123 -3
  85. data/test/serializers/association_macros_test.rb +36 -0
  86. data/test/serializers/associations_test.rb +70 -47
  87. data/test/serializers/attribute_test.rb +28 -4
  88. data/test/serializers/attributes_test.rb +8 -14
  89. data/test/serializers/cache_test.rb +58 -31
  90. data/test/serializers/fieldset_test.rb +3 -4
  91. data/test/serializers/meta_test.rb +42 -28
  92. data/test/serializers/root_test.rb +21 -0
  93. data/test/serializers/serializer_for_test.rb +1 -1
  94. data/test/support/rails_app.rb +21 -0
  95. data/test/support/serialization_testing.rb +13 -0
  96. data/test/support/simplecov.rb +6 -0
  97. data/test/support/stream_capture.rb +50 -0
  98. data/test/support/test_case.rb +5 -0
  99. data/test/test_helper.rb +41 -29
  100. data/test/utils/include_args_to_hash_test.rb +79 -0
  101. metadata +123 -17
  102. data/test/action_controller/json_api_linked_test.rb +0 -179
  103. data/test/action_controller/rescue_from_test.rb +0 -32
  104. data/test/serializers/urls_test.rb +0 -26
@@ -27,8 +27,8 @@ module ActiveModel
27
27
  def test_includes_comment_ids
28
28
  expected = {
29
29
  data: [
30
- { type: "posts", id: "1"},
31
- { type: "posts", id: "2"}
30
+ { type: 'posts', id: '1' },
31
+ { type: 'posts', id: '2' }
32
32
  ]
33
33
  }
34
34
 
@@ -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: ['comments', 'author']
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: "authors",
61
+ type: 'authors',
62
62
  relationships: {
63
- posts: { data: [ {type: "posts", id: @post.id.to_s } ] }
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: "authors", id: @author.id.to_s }
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: "My Blog!!")
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: [ { type: "comments", id: "1" }, { type: "comments", id: "2" } ] }
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: 'comments')
45
+ @adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:comments])
43
46
  expected = [{
44
- id: "1",
45
- type: "comments",
47
+ id: '1',
48
+ type: 'comments',
46
49
  attributes: {
47
50
  body: 'ZOMG A COMMENT'
48
51
  },
49
52
  relationships: {
50
- post: { data: { type: "posts", id: "1" } },
53
+ post: { data: { type: 'posts', id: '1' } },
51
54
  author: { data: nil }
52
55
  }
53
56
  }, {
54
- id: "2",
55
- type: "comments",
57
+ id: '2',
58
+ type: 'comments',
56
59
  attributes: {
57
60
  body: 'ZOMG ANOTHER COMMENT'
58
61
  },
59
62
  relationships: {
60
- post: { data: { type: "posts", id: "1" } },
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: 'comments', fields: {comment: [:id]})
71
+ @adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:comments], fields: { comment: [:id] })
69
72
  expected = [{
70
- id: "1",
71
- type: "comments",
73
+ id: '1',
74
+ type: 'comments',
72
75
  relationships: {
73
- post: { data: { type: "posts", id: "1" } },
76
+ post: { data: { type: 'posts', id: '1' } },
74
77
  author: { data: nil }
75
78
  }
76
79
  }, {
77
- id: "2",
78
- type: "comments",
80
+ id: '2',
81
+ type: 'comments',
79
82
  relationships: {
80
- post: { data: { type: "posts", id: "1" } },
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: "posts",
101
- id: "1"
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: "My Blog!!")
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: 'bio,posts')
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: "bios", id: "43" } }
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: 'bio')
41
+ @adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: [:bio])
40
42
 
41
43
  expected = [
42
44
  {
43
- id: "43",
44
- type: "bios",
45
+ id: '43',
46
+ type: 'bios',
45
47
  attributes: {
46
- content:"AMS Contributor",
48
+ content: 'AMS Contributor',
47
49
  rating: nil
48
50
  },
49
51
  relationships: {
50
- author: { data: { type: "authors", id: "1" } }
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: ['author', 'author.bio', 'comments']
46
+ include: [:comments, author: [:bio]]
47
47
  )
48
48
  alt_adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
49
49
  serializer,
50
- include: 'author,author.bio,comments'
50
+ include: [:comments, author: [:bio]]
51
51
  )
52
52
 
53
53
  expected = {
54
54
  data: [
55
55
  {
56
- id: "10",
57
- type: "posts",
56
+ id: '10',
57
+ type: 'posts',
58
58
  attributes: {
59
- title: "Hello!!",
60
- body: "Hello, world!!"
59
+ title: 'Hello!!',
60
+ body: 'Hello, world!!'
61
61
  },
62
62
  relationships: {
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" } }
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: "20",
70
- type: "posts",
69
+ id: '20',
70
+ type: 'posts',
71
71
  attributes: {
72
- title: "New Post",
73
- body: "Body"
72
+ title: 'New Post',
73
+ body: 'Body'
74
74
  },
75
75
  relationships: {
76
76
  comments: { data: [] },
77
- blog: { data: { type: "blogs", id: "999" } },
78
- author: { data: { type: "authors", id: "2" } }
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: "1",
85
- type: "comments",
84
+ id: '1',
85
+ type: 'comments',
86
86
  attributes: {
87
- body: "ZOMG A COMMENT"
87
+ body: 'ZOMG A COMMENT'
88
88
  },
89
89
  relationships: {
90
- post: { data: { type: "posts", id: "10" } },
90
+ post: { data: { type: 'posts', id: '10' } },
91
91
  author: { data: nil }
92
92
  }
93
93
  }, {
94
- id: "2",
95
- type: "comments",
94
+ id: '2',
95
+ type: 'comments',
96
96
  attributes: {
97
- body: "ZOMG ANOTHER COMMENT",
97
+ body: 'ZOMG ANOTHER COMMENT',
98
98
  },
99
99
  relationships: {
100
- post: { data: { type: "posts", id: "10" } },
100
+ post: { data: { type: 'posts', id: '10' } },
101
101
  author: { data: nil }
102
102
  }
103
103
  }, {
104
- id: "1",
105
- type: "authors",
104
+ id: '1',
105
+ type: 'authors',
106
106
  attributes: {
107
- name: "Steve K."
107
+ name: 'Steve K.'
108
108
  },
109
109
  relationships: {
110
- posts: { data: [ { type: "posts", id: "10" }, { type: "posts", id: "30" } ] },
110
+ posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
111
111
  roles: { data: [] },
112
- bio: { data: { type: "bios", id: "1" } }
112
+ bio: { data: { type: 'bios', id: '1' } }
113
113
  }
114
114
  }, {
115
- id: "1",
116
- type: "bios",
115
+ id: '1',
116
+ type: 'bios',
117
117
  attributes: {
118
- content: "AMS Contributor",
118
+ content: 'AMS Contributor',
119
119
  rating: nil
120
120
  },
121
121
  relationships: {
122
- author: { data: { type: "authors", id: "1" } }
122
+ author: { data: { type: 'authors', id: '1' } }
123
123
  }
124
124
  }, {
125
- id: "2",
126
- type: "authors",
125
+ id: '2',
126
+ type: 'authors',
127
127
  attributes: {
128
- name: "Tenderlove"
128
+ name: 'Tenderlove'
129
129
  },
130
130
  relationships: {
131
- posts: { data: [ { type: "posts", id:"20" } ] },
131
+ posts: { data: [{ type: 'posts', id: '20' }] },
132
132
  roles: { data: [] },
133
- bio: { data: { type: "bios", id: "2" } }
133
+ bio: { data: { type: 'bios', id: '2' } }
134
134
  }
135
135
  }, {
136
- id: "2",
137
- type: "bios",
136
+ id: '2',
137
+ type: 'bios',
138
138
  attributes: {
139
139
  rating: nil,
140
- content: "Rails Contributor",
140
+ content: 'Rails Contributor',
141
141
  },
142
142
  relationships: {
143
- author: { data: { type: "authors", id: "2" } }
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: ['author', 'author.posts']
156
+ include: [author: [:posts]]
157
157
  )
158
158
  alt_adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
159
159
  serializer,
160
- include: 'author,author.posts'
160
+ include: [author: [:posts]]
161
161
  )
162
162
 
163
163
  expected = [
164
164
  {
165
- id: "1",
166
- type: "authors",
165
+ id: '1',
166
+ type: 'authors',
167
167
  attributes: {
168
- name: "Steve K."
168
+ name: 'Steve K.'
169
169
  },
170
170
  relationships: {
171
- posts: { data: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
171
+ posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
172
172
  roles: { data: [] },
173
- bio: { data: { type: "bios", id: "1" }}
173
+ bio: { data: { type: 'bios', id: '1' } }
174
174
  }
175
175
  }, {
176
- id: "10",
177
- type: "posts",
176
+ id: '10',
177
+ type: 'posts',
178
178
  attributes: {
179
- title: "Hello!!",
180
- body: "Hello, world!!"
179
+ title: 'Hello!!',
180
+ body: 'Hello, world!!'
181
181
  },
182
182
  relationships: {
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" } }
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: "30",
189
- type: "posts",
188
+ id: '30',
189
+ type: 'posts',
190
190
  attributes: {
191
- title: "Yet Another Post",
192
- body: "Body"
191
+ title: 'Yet Another Post',
192
+ body: 'Body'
193
193
  },
194
194
  relationships: {
195
195
  comments: { data: [] },
196
- blog: { data: { type: "blogs", id: "999" } },
197
- author: { data: { type: "authors", id: "1" } }
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: ['post']
227
+ include: [:post]
228
228
  )
229
229
 
230
230
  expected = [
231
231
  {
232
- id: "10",
233
- type: "posts",
232
+ id: '10',
233
+ type: 'posts',
234
234
  attributes: {
235
- title: "Hello!!",
236
- body: "Hello, world!!"
235
+ title: 'Hello!!',
236
+ body: 'Hello, world!!'
237
237
  },
238
238
  relationships: {
239
239
  comments: {
240
- data: [{type: "comments", id: "1"}, {type: "comments", id: "2"}]
240
+ data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }]
241
241
  },
242
242
  blog: {
243
- data: {type: "blogs", id: "999"}
243
+ data: { type: 'blogs', id: '999' }
244
244
  },
245
245
  author: {
246
- data: {type: "authors", id: "1"}
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: ['author']
260
+ include: [:author]
261
261
  )
262
262
 
263
263
  expected = {
264
264
  data: {
265
- id: "10",
266
- type: "posts",
265
+ id: '10',
266
+ type: 'posts',
267
267
  attributes: {
268
- title: "Hello!!",
269
- body: "Hello, world!!"
268
+ title: 'Hello!!',
269
+ body: 'Hello, world!!'
270
270
  },
271
271
  relationships: {
272
- comments: { data: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
272
+ comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
273
273
  author: { data: nil }
274
274
  }
275
275
  }