cheap_ams 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +315 -0
- data/.simplecov +99 -0
- data/.travis.yml +8 -0
- data/Gemfile +10 -1
- data/README.md +4 -16
- data/Rakefile +29 -2
- data/cheap_ams.gemspec +3 -2
- data/docs/README.md +1 -0
- data/docs/general/configuration_options.md +11 -0
- data/lib/action_controller/serialization.rb +2 -2
- data/lib/active_model/serializable_resource.rb +0 -2
- data/lib/active_model/serializer/adapter/fragment_cache.rb +3 -4
- data/lib/active_model/serializer/adapter/json/fragment_cache.rb +0 -2
- data/lib/active_model/serializer/adapter/json.rb +0 -1
- data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +2 -4
- data/lib/active_model/serializer/adapter/json_api.rb +87 -93
- data/lib/active_model/serializer/adapter.rb +4 -4
- data/lib/active_model/serializer/array_serializer.rb +11 -12
- data/lib/active_model/serializer/association.rb +0 -1
- data/lib/active_model/serializer/fieldset.rb +2 -4
- data/lib/active_model/serializer/lint.rb +2 -4
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +0 -25
- data/lib/active_model_serializers.rb +0 -1
- data/lib/generators/serializer/serializer_generator.rb +7 -7
- data/lib/generators/serializer/templates/{serializer.rb → serializer.rb.erb} +0 -0
- 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 +28 -28
- data/test/action_controller/json_api/pagination_test.rb +24 -24
- data/test/action_controller/serialization_test.rb +73 -79
- data/test/adapter/fragment_cache_test.rb +2 -2
- data/test/adapter/json/belongs_to_test.rb +4 -4
- data/test/adapter/json/collection_test.rb +15 -15
- data/test/adapter/json/has_many_test.rb +5 -5
- data/test/adapter/json_api/belongs_to_test.rb +37 -37
- 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 +25 -25
- data/test/adapter/json_api/has_one_test.rb +10 -10
- data/test/adapter/json_api/json_api_test.rb +6 -7
- data/test/adapter/json_api/linked_test.rb +69 -69
- data/test/adapter/json_api/pagination_links_test.rb +8 -8
- data/test/adapter/json_api/resource_type_config_test.rb +14 -14
- data/test/adapter/json_test.rb +7 -7
- data/test/adapter_test.rb +2 -2
- data/test/array_serializer_test.rb +11 -7
- data/test/capture_warnings.rb +8 -7
- data/test/fixtures/active_record.rb +0 -1
- data/test/fixtures/poro.rb +7 -12
- data/test/generators/scaffold_controller_generator_test.rb +1 -2
- data/test/generators/serializer_generator_test.rb +10 -10
- data/test/lint_test.rb +0 -7
- data/test/serializers/adapter_for_test.rb +0 -1
- data/test/serializers/associations_test.rb +4 -4
- data/test/serializers/attribute_test.rb +7 -7
- data/test/serializers/attributes_test.rb +8 -14
- data/test/serializers/cache_test.rb +8 -7
- data/test/serializers/fieldset_test.rb +3 -4
- data/test/serializers/meta_test.rb +23 -23
- data/test/serializers/root_test.rb +1 -3
- data/test/serializers/serializer_for_test.rb +1 -1
- data/test/support/serialization_testing.rb +13 -0
- data/test/support/simplecov.rb +6 -0
- data/test/support/stream_capture.rb +2 -2
- data/test/test_helper.rb +14 -2
- metadata +13 -6
- data/test/serializers/urls_test.rb +0 -26
@@ -28,10 +28,10 @@ module ActionController
|
|
28
28
|
@first_comment.author = @author2
|
29
29
|
@second_comment.post = @post
|
30
30
|
@second_comment.author = nil
|
31
|
-
@post2 = Post.new(id: 2, title:
|
31
|
+
@post2 = Post.new(id: 2, title: 'Another Post', body: 'Body')
|
32
32
|
@post2.author = @author
|
33
33
|
@post2.comments = []
|
34
|
-
@blog = Blog.new(id: 1, name:
|
34
|
+
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
35
35
|
@post.blog = @blog
|
36
36
|
@post2.blog = @blog
|
37
37
|
end
|
@@ -75,7 +75,7 @@ module ActionController
|
|
75
75
|
|
76
76
|
def render_collection_with_include
|
77
77
|
setup_post
|
78
|
-
render json: [@post], include:
|
78
|
+
render json: [@post], include: %w(author comments), adapter: :json_api
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -100,37 +100,37 @@ module ActionController
|
|
100
100
|
response = JSON.parse(@response.body)
|
101
101
|
expected_linked = [
|
102
102
|
{
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
'id' => '1',
|
104
|
+
'type' => 'authors',
|
105
|
+
'attributes' => {
|
106
|
+
'name' => 'Steve K.'
|
107
107
|
},
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
'relationships' => {
|
109
|
+
'posts' => { 'data' => [] },
|
110
|
+
'roles' => { 'data' => [{ 'type' => 'roles', 'id' => '1' }, { 'type' => 'roles', 'id' => '2' }] },
|
111
|
+
'bio' => { 'data' => nil }
|
112
112
|
}
|
113
113
|
}, {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
'id' => '1',
|
115
|
+
'type' => 'roles',
|
116
|
+
'attributes' => {
|
117
|
+
'name' => 'admin',
|
118
|
+
'description' => nil,
|
119
|
+
'slug' => 'admin-1'
|
120
120
|
},
|
121
|
-
|
122
|
-
|
121
|
+
'relationships' => {
|
122
|
+
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
123
123
|
}
|
124
124
|
}, {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
125
|
+
'id' => '2',
|
126
|
+
'type' => 'roles',
|
127
|
+
'attributes' => {
|
128
|
+
'name' => 'colab',
|
129
|
+
'description' => nil,
|
130
|
+
'slug' => 'colab-2'
|
131
131
|
},
|
132
|
-
|
133
|
-
|
132
|
+
'relationships' => {
|
133
|
+
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
134
134
|
}
|
135
135
|
}
|
136
136
|
]
|
@@ -172,7 +172,7 @@ module ActionController
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def has_type?(collection, value)
|
175
|
-
collection.detect { |i| i['type'] == value}
|
175
|
+
collection.detect { |i| i['type'] == value }
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
@@ -47,11 +47,11 @@ module ActionController
|
|
47
47
|
tests PaginationTestController
|
48
48
|
|
49
49
|
def test_render_pagination_links_with_will_paginate
|
50
|
-
expected_links = {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
51
|
+
'first' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
52
|
+
'prev' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
53
|
+
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
54
|
+
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
55
55
|
|
56
56
|
get :render_pagination_using_will_paginate, page: { number: 2, size: 1 }
|
57
57
|
response = JSON.parse(@response.body)
|
@@ -59,48 +59,48 @@ module ActionController
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_render_only_last_and_next_pagination_links
|
62
|
-
expected_links = {
|
63
|
-
|
64
|
-
|
62
|
+
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
63
|
+
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
64
|
+
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
65
65
|
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }
|
66
66
|
response = JSON.parse(@response.body)
|
67
67
|
assert_equal expected_links, response['links']
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_render_pagination_links_with_kaminari
|
71
|
-
expected_links = {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
72
|
+
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
73
|
+
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
74
|
+
'next' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
75
|
+
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
76
76
|
get :render_pagination_using_kaminari, page: { number: 2, size: 1 }
|
77
77
|
response = JSON.parse(@response.body)
|
78
78
|
assert_equal expected_links, response['links']
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_render_only_prev_and_first_pagination_links
|
82
|
-
expected_links = {
|
83
|
-
|
84
|
-
|
82
|
+
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
83
|
+
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
84
|
+
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1" }
|
85
85
|
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }
|
86
86
|
response = JSON.parse(@response.body)
|
87
87
|
assert_equal expected_links, response['links']
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_render_only_last_and_next_pagination_links_with_additional_params
|
91
|
-
expected_links = {
|
92
|
-
|
93
|
-
|
94
|
-
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }, teste:
|
91
|
+
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
92
|
+
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
93
|
+
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
94
|
+
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }, teste: 'additional'
|
95
95
|
response = JSON.parse(@response.body)
|
96
96
|
assert_equal expected_links, response['links']
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_render_only_prev_and_first_pagination_links_with_additional_params
|
100
|
-
expected_links = {
|
101
|
-
|
102
|
-
|
103
|
-
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }, teste:
|
100
|
+
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
101
|
+
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
102
|
+
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional" }
|
103
|
+
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }, teste: 'additional'
|
104
104
|
response = JSON.parse(@response.body)
|
105
105
|
assert_equal expected_links, response['links']
|
106
106
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
3
|
module ActionController
|
@@ -7,61 +6,48 @@ module ActionController
|
|
7
6
|
include ActiveSupport::Testing::Stream
|
8
7
|
class ImplicitSerializationTestController < ActionController::Base
|
9
8
|
def render_using_implicit_serializer
|
10
|
-
@profile = Profile.new(
|
9
|
+
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
11
10
|
render json: @profile
|
12
11
|
end
|
13
12
|
|
14
13
|
def render_using_default_adapter_root
|
15
|
-
|
16
|
-
|
17
|
-
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
18
|
-
render json: @profile
|
19
|
-
end
|
14
|
+
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
15
|
+
render json: @profile
|
20
16
|
end
|
21
17
|
|
22
18
|
def render_array_using_custom_root
|
23
|
-
|
24
|
-
|
25
|
-
render json: [@profile], root: "custom_root"
|
26
|
-
end
|
19
|
+
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
20
|
+
render json: [@profile], root: 'custom_root'
|
27
21
|
end
|
28
22
|
|
29
23
|
def render_array_that_is_empty_using_custom_root
|
30
|
-
|
31
|
-
render json: [], root: "custom_root"
|
32
|
-
end
|
24
|
+
render json: [], root: 'custom_root'
|
33
25
|
end
|
34
26
|
|
35
27
|
def render_object_using_custom_root
|
36
|
-
|
37
|
-
|
38
|
-
render json: @profile, root: "custom_root"
|
39
|
-
end
|
28
|
+
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
29
|
+
render json: @profile, root: 'custom_root'
|
40
30
|
end
|
41
31
|
|
42
32
|
def render_array_using_implicit_serializer
|
43
33
|
array = [
|
44
|
-
Profile.new(
|
45
|
-
Profile.new(
|
34
|
+
Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
|
35
|
+
Profile.new(name: 'Name 2', description: 'Description 2', comments: 'Comments 2')
|
46
36
|
]
|
47
37
|
render json: array
|
48
38
|
end
|
49
39
|
|
50
40
|
def render_array_using_implicit_serializer_and_meta
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
]
|
56
|
-
|
57
|
-
render json: @profiles, meta: { total: 10 }
|
58
|
-
end
|
41
|
+
@profiles = [
|
42
|
+
Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
43
|
+
]
|
44
|
+
render json: @profiles, meta: { total: 10 }
|
59
45
|
end
|
60
46
|
|
61
47
|
def render_object_with_cache_enabled
|
62
|
-
@comment = Comment.new(
|
48
|
+
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
63
49
|
@author = Author.new(id: 1, name: 'Joao Moura.')
|
64
|
-
@post = Post.new(
|
50
|
+
@post = Post.new(id: 1, title: 'New Post', body: 'Body', comments: [@comment], author: @author)
|
65
51
|
|
66
52
|
generate_cached_serializer(@post)
|
67
53
|
|
@@ -70,11 +56,11 @@ module ActionController
|
|
70
56
|
end
|
71
57
|
|
72
58
|
def render_json_object_without_serializer
|
73
|
-
render json: {error: 'Result is Invalid'}
|
59
|
+
render json: { error: 'Result is Invalid' }
|
74
60
|
end
|
75
61
|
|
76
62
|
def render_json_array_object_without_serializer
|
77
|
-
render json: [{error: 'Result is Invalid'}]
|
63
|
+
render json: [{ error: 'Result is Invalid' }]
|
78
64
|
end
|
79
65
|
|
80
66
|
def update_and_render_object_with_cache_enabled
|
@@ -85,9 +71,9 @@ module ActionController
|
|
85
71
|
end
|
86
72
|
|
87
73
|
def render_object_expired_with_cache_enabled
|
88
|
-
comment = Comment.new(
|
74
|
+
comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
89
75
|
author = Author.new(id: 1, name: 'Joao Moura.')
|
90
|
-
post = Post.new(
|
76
|
+
post = Post.new(id: 1, title: 'New Post', body: 'Body', comments: [comment], author: author)
|
91
77
|
|
92
78
|
generate_cached_serializer(post)
|
93
79
|
|
@@ -97,16 +83,16 @@ module ActionController
|
|
97
83
|
end
|
98
84
|
|
99
85
|
def render_changed_object_with_cache_enabled
|
100
|
-
comment = Comment.new(
|
86
|
+
comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
101
87
|
author = Author.new(id: 1, name: 'Joao Moura.')
|
102
|
-
post = Post.new(
|
88
|
+
post = Post.new(id: 1, title: 'ZOMG a New Post', body: 'Body', comments: [comment], author: author)
|
103
89
|
|
104
90
|
render json: post
|
105
91
|
end
|
106
92
|
|
107
93
|
def render_fragment_changed_object_with_only_cache_enabled
|
108
94
|
author = Author.new(id: 1, name: 'Joao Moura.')
|
109
|
-
role = Role.new(
|
95
|
+
role = Role.new(id: 42, name: 'ZOMG A ROLE', description: 'DESCRIPTION HERE', author: author)
|
110
96
|
|
111
97
|
generate_cached_serializer(role)
|
112
98
|
role.name = 'lol'
|
@@ -117,7 +103,7 @@ module ActionController
|
|
117
103
|
|
118
104
|
def render_fragment_changed_object_with_except_cache_enabled
|
119
105
|
author = Author.new(id: 1, name: 'Joao Moura.')
|
120
|
-
bio = Bio.new(
|
106
|
+
bio = Bio.new(id: 42, content: 'ZOMG A ROLE', rating: 5, author: author)
|
121
107
|
|
122
108
|
generate_cached_serializer(bio)
|
123
109
|
bio.content = 'lol'
|
@@ -127,18 +113,19 @@ module ActionController
|
|
127
113
|
end
|
128
114
|
|
129
115
|
def render_fragment_changed_object_with_relationship
|
130
|
-
comment = Comment.new(
|
131
|
-
comment2 = Comment.new(
|
132
|
-
like = Like.new(
|
116
|
+
comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
117
|
+
comment2 = Comment.new(id: 1, body: 'ZOMG AN UPDATED-BUT-NOT-CACHE-EXPIRED COMMENT')
|
118
|
+
like = Like.new(id: 1, likeable: comment, time: 3.days.ago)
|
133
119
|
|
134
120
|
generate_cached_serializer(like)
|
135
121
|
like.likable = comment2
|
136
|
-
like.time = Time.now.to_s
|
122
|
+
like.time = Time.zone.now.to_s
|
137
123
|
|
138
124
|
render json: like
|
139
125
|
end
|
140
126
|
|
141
127
|
private
|
128
|
+
|
142
129
|
def generate_cached_serializer(obj)
|
143
130
|
ActiveModel::SerializableResource.new(obj).to_json
|
144
131
|
end
|
@@ -160,8 +147,8 @@ module ActionController
|
|
160
147
|
get :render_using_implicit_serializer
|
161
148
|
|
162
149
|
expected = {
|
163
|
-
name:
|
164
|
-
description:
|
150
|
+
name: 'Name 1',
|
151
|
+
description: 'Description 1'
|
165
152
|
}
|
166
153
|
|
167
154
|
assert_equal 'application/json', @response.content_type
|
@@ -169,15 +156,16 @@ module ActionController
|
|
169
156
|
end
|
170
157
|
|
171
158
|
def test_render_using_default_root
|
172
|
-
|
173
|
-
|
159
|
+
with_adapter :json_api do
|
160
|
+
get :render_using_default_adapter_root
|
161
|
+
end
|
174
162
|
expected = {
|
175
163
|
data: {
|
176
164
|
id: assigns(:profile).id.to_s,
|
177
|
-
type:
|
165
|
+
type: 'profiles',
|
178
166
|
attributes: {
|
179
|
-
name:
|
180
|
-
description:
|
167
|
+
name: 'Name 1',
|
168
|
+
description: 'Description 1'
|
181
169
|
}
|
182
170
|
}
|
183
171
|
}
|
@@ -187,25 +175,30 @@ module ActionController
|
|
187
175
|
end
|
188
176
|
|
189
177
|
def test_render_array_using_custom_root
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
with_adapter :json do
|
179
|
+
get :render_array_using_custom_root
|
180
|
+
end
|
181
|
+
expected = { custom_roots: [{ name: 'Name 1', description: 'Description 1' }] }
|
193
182
|
assert_equal 'application/json', @response.content_type
|
194
183
|
assert_equal expected.to_json, @response.body
|
195
184
|
end
|
196
185
|
|
197
186
|
def test_render_array_that_is_empty_using_custom_root
|
198
|
-
|
187
|
+
with_adapter :json do
|
188
|
+
get :render_array_that_is_empty_using_custom_root
|
189
|
+
end
|
199
190
|
|
200
|
-
expected =
|
191
|
+
expected = { custom_roots: [] }
|
201
192
|
assert_equal 'application/json', @response.content_type
|
202
193
|
assert_equal expected.to_json, @response.body
|
203
194
|
end
|
204
195
|
|
205
196
|
def test_render_object_using_custom_root
|
206
|
-
|
197
|
+
with_adapter :json do
|
198
|
+
get :render_object_using_custom_root
|
199
|
+
end
|
207
200
|
|
208
|
-
expected =
|
201
|
+
expected = { custom_root: { name: 'Name 1', description: 'Description 1' } }
|
209
202
|
assert_equal 'application/json', @response.content_type
|
210
203
|
assert_equal expected.to_json, @response.body
|
211
204
|
end
|
@@ -214,7 +207,7 @@ module ActionController
|
|
214
207
|
get :render_json_object_without_serializer
|
215
208
|
|
216
209
|
assert_equal 'application/json', @response.content_type
|
217
|
-
expected_body = {error: 'Result is Invalid'}
|
210
|
+
expected_body = { error: 'Result is Invalid' }
|
218
211
|
assert_equal expected_body.to_json, @response.body
|
219
212
|
end
|
220
213
|
|
@@ -222,7 +215,7 @@ module ActionController
|
|
222
215
|
get :render_json_array_object_without_serializer
|
223
216
|
|
224
217
|
assert_equal 'application/json', @response.content_type
|
225
|
-
expected_body = [{error: 'Result is Invalid'}]
|
218
|
+
expected_body = [{ error: 'Result is Invalid' }]
|
226
219
|
assert_equal expected_body.to_json, @response.body
|
227
220
|
end
|
228
221
|
|
@@ -233,11 +226,11 @@ module ActionController
|
|
233
226
|
expected = [
|
234
227
|
{
|
235
228
|
name: 'Name 1',
|
236
|
-
description: 'Description 1'
|
229
|
+
description: 'Description 1'
|
237
230
|
},
|
238
231
|
{
|
239
232
|
name: 'Name 2',
|
240
|
-
description: 'Description 2'
|
233
|
+
description: 'Description 2'
|
241
234
|
}
|
242
235
|
]
|
243
236
|
|
@@ -245,16 +238,17 @@ module ActionController
|
|
245
238
|
end
|
246
239
|
|
247
240
|
def test_render_array_using_implicit_serializer_and_meta
|
248
|
-
|
249
|
-
|
241
|
+
with_adapter :json_api do
|
242
|
+
get :render_array_using_implicit_serializer_and_meta
|
243
|
+
end
|
250
244
|
expected = {
|
251
245
|
data: [
|
252
246
|
{
|
253
247
|
id: assigns(:profiles).first.id.to_s,
|
254
|
-
type:
|
248
|
+
type: 'profiles',
|
255
249
|
attributes: {
|
256
|
-
name:
|
257
|
-
description:
|
250
|
+
name: 'Name 1',
|
251
|
+
description: 'Description 1'
|
258
252
|
}
|
259
253
|
}
|
260
254
|
],
|
@@ -288,7 +282,7 @@ module ActionController
|
|
288
282
|
}
|
289
283
|
|
290
284
|
ActionController::Base.cache_store.clear
|
291
|
-
Timecop.freeze(Time.now) do
|
285
|
+
Timecop.freeze(Time.zone.now) do
|
292
286
|
get :render_object_with_cache_enabled
|
293
287
|
|
294
288
|
assert_equal 'application/json', @response.content_type
|
@@ -336,8 +330,8 @@ module ActionController
|
|
336
330
|
response = JSON.parse(@response.body)
|
337
331
|
|
338
332
|
assert_equal 'application/json', @response.content_type
|
339
|
-
assert_equal 'ZOMG A ROLE', response[
|
340
|
-
assert_equal 'HUEHUEBRBR', response[
|
333
|
+
assert_equal 'ZOMG A ROLE', response['name']
|
334
|
+
assert_equal 'HUEHUEBRBR', response['description']
|
341
335
|
end
|
342
336
|
|
343
337
|
def test_render_with_fragment_except_cache_enable
|
@@ -346,23 +340,23 @@ module ActionController
|
|
346
340
|
response = JSON.parse(@response.body)
|
347
341
|
|
348
342
|
assert_equal 'application/json', @response.content_type
|
349
|
-
assert_equal 5, response[
|
350
|
-
assert_equal 'lol', response[
|
343
|
+
assert_equal 5, response['rating']
|
344
|
+
assert_equal 'lol', response['content']
|
351
345
|
end
|
352
346
|
|
353
347
|
def test_render_fragment_changed_object_with_relationship
|
354
348
|
ActionController::Base.cache_store.clear
|
355
349
|
|
356
|
-
Timecop.freeze(Time.now) do
|
350
|
+
Timecop.freeze(Time.zone.now) do
|
357
351
|
get :render_fragment_changed_object_with_relationship
|
358
352
|
response = JSON.parse(@response.body)
|
359
353
|
|
360
354
|
expected_return = {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
355
|
+
'id' => 1,
|
356
|
+
'time' => Time.zone.now.to_s,
|
357
|
+
'likeable' => {
|
358
|
+
'id' => 1,
|
359
|
+
'body' => 'ZOMG A COMMENT'
|
366
360
|
}
|
367
361
|
}
|
368
362
|
|
@@ -385,8 +379,8 @@ module ActionController
|
|
385
379
|
body: 'ZOMG A COMMENT' }
|
386
380
|
],
|
387
381
|
blog: {
|
388
|
-
id:999,
|
389
|
-
name:
|
382
|
+
id: 999,
|
383
|
+
name: 'Custom blog'
|
390
384
|
},
|
391
385
|
author: {
|
392
386
|
id: 1,
|
@@ -417,7 +411,7 @@ module ActionController
|
|
417
411
|
true
|
418
412
|
end
|
419
413
|
}.new
|
420
|
-
assert_equal
|
414
|
+
assert_equal '', (capture(:stderr) {
|
421
415
|
controller.get_serializer(Profile.new)
|
422
416
|
})
|
423
417
|
end
|
@@ -4,9 +4,9 @@ module ActiveModel
|
|
4
4
|
class Adapter
|
5
5
|
class FragmentCacheTest < Minitest::Test
|
6
6
|
def setup
|
7
|
-
@spam = Spam::UnrelatedLink.new(id:
|
7
|
+
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
8
8
|
@author = Author.new(name: 'Joao M. D. Moura')
|
9
|
-
@role = Role.new(name: 'Great Author', description:nil)
|
9
|
+
@role = Role.new(name: 'Great Author', description: nil)
|
10
10
|
@role.author = [@author]
|
11
11
|
@role_serializer = RoleSerializer.new(@role)
|
12
12
|
@spam_serializer = Spam::UnrelatedLinkSerializer.new(@spam)
|
@@ -14,7 +14,7 @@ module ActiveModel
|
|
14
14
|
@comment.post = @post
|
15
15
|
@comment.author = nil
|
16
16
|
@anonymous_post.author = nil
|
17
|
-
@blog = Blog.new(id: 1, name:
|
17
|
+
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
18
18
|
@post.blog = @blog
|
19
19
|
@anonymous_post.blog = nil
|
20
20
|
|
@@ -24,21 +24,21 @@ module ActiveModel
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_includes_post
|
27
|
-
assert_equal({id: 42, title: 'New Post', body: 'Body'}, @adapter.serializable_hash[:comment][:post])
|
27
|
+
assert_equal({ id: 42, title: 'New Post', body: 'Body' }, @adapter.serializable_hash[:comment][:post])
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_include_nil_author
|
31
31
|
serializer = PostSerializer.new(@anonymous_post)
|
32
32
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
33
33
|
|
34
|
-
assert_equal({post: {title:
|
34
|
+
assert_equal({ post: { title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], blog: { id: 999, name: 'Custom blog' }, author: nil } }, adapter.serializable_hash)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_include_nil_author_with_specified_serializer
|
38
38
|
serializer = PostPreviewSerializer.new(@anonymous_post)
|
39
39
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
40
40
|
|
41
|
-
assert_equal({post: {title:
|
41
|
+
assert_equal({ post: { title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], author: nil } }, adapter.serializable_hash)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|