cheap_ams 0.10.5 → 0.10.6

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +49 -0
  3. data/.rubocop_todo.yml +315 -0
  4. data/.simplecov +99 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +10 -1
  7. data/README.md +4 -16
  8. data/Rakefile +29 -2
  9. data/cheap_ams.gemspec +3 -2
  10. data/docs/README.md +1 -0
  11. data/docs/general/configuration_options.md +11 -0
  12. data/lib/action_controller/serialization.rb +2 -2
  13. data/lib/active_model/serializable_resource.rb +0 -2
  14. data/lib/active_model/serializer/adapter/fragment_cache.rb +3 -4
  15. data/lib/active_model/serializer/adapter/json/fragment_cache.rb +0 -2
  16. data/lib/active_model/serializer/adapter/json.rb +0 -1
  17. data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +2 -4
  18. data/lib/active_model/serializer/adapter/json_api.rb +87 -93
  19. data/lib/active_model/serializer/adapter.rb +4 -4
  20. data/lib/active_model/serializer/array_serializer.rb +11 -12
  21. data/lib/active_model/serializer/association.rb +0 -1
  22. data/lib/active_model/serializer/fieldset.rb +2 -4
  23. data/lib/active_model/serializer/lint.rb +2 -4
  24. data/lib/active_model/serializer/version.rb +1 -1
  25. data/lib/active_model/serializer.rb +0 -25
  26. data/lib/active_model_serializers.rb +0 -1
  27. data/lib/generators/serializer/serializer_generator.rb +7 -7
  28. data/lib/generators/serializer/templates/{serializer.rb → serializer.rb.erb} +0 -0
  29. data/lib/tasks/rubocop.rake +0 -0
  30. data/test/action_controller/adapter_selector_test.rb +3 -3
  31. data/test/action_controller/explicit_serializer_test.rb +9 -9
  32. data/test/action_controller/json_api/linked_test.rb +28 -28
  33. data/test/action_controller/json_api/pagination_test.rb +24 -24
  34. data/test/action_controller/serialization_test.rb +73 -79
  35. data/test/adapter/fragment_cache_test.rb +2 -2
  36. data/test/adapter/json/belongs_to_test.rb +4 -4
  37. data/test/adapter/json/collection_test.rb +15 -15
  38. data/test/adapter/json/has_many_test.rb +5 -5
  39. data/test/adapter/json_api/belongs_to_test.rb +37 -37
  40. data/test/adapter/json_api/collection_test.rb +22 -23
  41. data/test/adapter/json_api/has_many_embed_ids_test.rb +2 -2
  42. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +4 -4
  43. data/test/adapter/json_api/has_many_test.rb +25 -25
  44. data/test/adapter/json_api/has_one_test.rb +10 -10
  45. data/test/adapter/json_api/json_api_test.rb +6 -7
  46. data/test/adapter/json_api/linked_test.rb +69 -69
  47. data/test/adapter/json_api/pagination_links_test.rb +8 -8
  48. data/test/adapter/json_api/resource_type_config_test.rb +14 -14
  49. data/test/adapter/json_test.rb +7 -7
  50. data/test/adapter_test.rb +2 -2
  51. data/test/array_serializer_test.rb +11 -7
  52. data/test/capture_warnings.rb +8 -7
  53. data/test/fixtures/active_record.rb +0 -1
  54. data/test/fixtures/poro.rb +7 -12
  55. data/test/generators/scaffold_controller_generator_test.rb +1 -2
  56. data/test/generators/serializer_generator_test.rb +10 -10
  57. data/test/lint_test.rb +0 -7
  58. data/test/serializers/adapter_for_test.rb +0 -1
  59. data/test/serializers/associations_test.rb +4 -4
  60. data/test/serializers/attribute_test.rb +7 -7
  61. data/test/serializers/attributes_test.rb +8 -14
  62. data/test/serializers/cache_test.rb +8 -7
  63. data/test/serializers/fieldset_test.rb +3 -4
  64. data/test/serializers/meta_test.rb +23 -23
  65. data/test/serializers/root_test.rb +1 -3
  66. data/test/serializers/serializer_for_test.rb +1 -1
  67. data/test/support/serialization_testing.rb +13 -0
  68. data/test/support/simplecov.rb +6 -0
  69. data/test/support/stream_capture.rb +2 -2
  70. data/test/test_helper.rb +14 -2
  71. metadata +13 -6
  72. 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: "Another Post", body: "Body")
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: "My Blog!!")
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: ['author', 'comments'], adapter: :json_api
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
- "id" => "1",
104
- "type" => "authors",
105
- "attributes" => {
106
- "name" => "Steve K."
103
+ 'id' => '1',
104
+ 'type' => 'authors',
105
+ 'attributes' => {
106
+ 'name' => 'Steve K.'
107
107
  },
108
- "relationships" => {
109
- "posts" => { "data" => [] },
110
- "roles" => { "data" => [{ "type" =>"roles", "id" => "1" }, { "type" =>"roles", "id" => "2" }] },
111
- "bio" => { "data" => nil }
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
- "id" => "1",
115
- "type" => "roles",
116
- "attributes" => {
117
- "name" => "admin",
118
- "description" => nil,
119
- "slug" => "admin-1"
114
+ 'id' => '1',
115
+ 'type' => 'roles',
116
+ 'attributes' => {
117
+ 'name' => 'admin',
118
+ 'description' => nil,
119
+ 'slug' => 'admin-1'
120
120
  },
121
- "relationships" => {
122
- "author" => { "data" => { "type" =>"authors", "id" => "1" } }
121
+ 'relationships' => {
122
+ 'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
123
123
  }
124
124
  }, {
125
- "id" => "2",
126
- "type" => "roles",
127
- "attributes" => {
128
- "name" => "colab",
129
- "description" => nil,
130
- "slug" => "colab-2"
125
+ 'id' => '2',
126
+ 'type' => 'roles',
127
+ 'attributes' => {
128
+ 'name' => 'colab',
129
+ 'description' => nil,
130
+ 'slug' => 'colab-2'
131
131
  },
132
- "relationships" => {
133
- "author" => { "data" => { "type" =>"authors", "id" => "1" } }
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 = { "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"}
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 = { "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"}
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 = { "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"}
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 = { "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"}
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 = { "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"
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 = { "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"
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({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
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
- with_adapter ActiveModel::Serializer::Adapter::JsonApi do
16
- # JSON-API adapter sets root by default
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
- with_adapter ActiveModel::Serializer::Adapter::Json do
24
- @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
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
- with_adapter ActiveModel::Serializer::Adapter::Json do
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
- with_adapter ActiveModel::Serializer::Adapter::Json do
37
- @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
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({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
45
- Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
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
- with_adapter ActiveModel::Serializer::Adapter::JsonApi do
52
-
53
- @profiles = [
54
- Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
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({ id: 1, body: 'ZOMG A COMMENT' })
48
+ @comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
63
49
  @author = Author.new(id: 1, name: 'Joao Moura.')
64
- @post = Post.new({ id: 1, title: 'New Post', body: 'Body', comments: [@comment], author: @author })
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({ id: 1, body: 'ZOMG A COMMENT' })
74
+ comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
89
75
  author = Author.new(id: 1, name: 'Joao Moura.')
90
- post = Post.new({ id: 1, title: 'New Post', body: 'Body', comments: [comment], author: author })
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({ id: 1, body: 'ZOMG A COMMENT' })
86
+ comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
101
87
  author = Author.new(id: 1, name: 'Joao Moura.')
102
- post = Post.new({ id: 1, title: 'ZOMG a New Post', body: 'Body', comments: [comment], author: author })
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({ id: 42, name: 'ZOMG A ROLE', description: 'DESCRIPTION HERE', author: author })
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({ id: 42, content: 'ZOMG A ROLE', rating: 5, author: author })
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({ id: 1, body: 'ZOMG A COMMENT' })
131
- comment2 = Comment.new({ id: 1, body: 'ZOMG AN UPDATED-BUT-NOT-CACHE-EXPIRED COMMENT' })
132
- like = Like.new({ id: 1, likeable: comment, time: 3.days.ago })
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: "Name 1",
164
- description: "Description 1"
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
- get :render_using_default_adapter_root
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: "profiles",
165
+ type: 'profiles',
178
166
  attributes: {
179
- name: "Name 1",
180
- description: "Description 1"
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
- get :render_array_using_custom_root
191
-
192
- expected = {custom_roots: [{name: "Name 1", description: "Description 1"}]}
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
- get :render_array_that_is_empty_using_custom_root
187
+ with_adapter :json do
188
+ get :render_array_that_is_empty_using_custom_root
189
+ end
199
190
 
200
- expected = {custom_roots: []}
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
- get :render_object_using_custom_root
197
+ with_adapter :json do
198
+ get :render_object_using_custom_root
199
+ end
207
200
 
208
- expected = {custom_root: {name: "Name 1", description: "Description 1"}}
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
- get :render_array_using_implicit_serializer_and_meta
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: "profiles",
248
+ type: 'profiles',
255
249
  attributes: {
256
- name: "Name 1",
257
- description: "Description 1"
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["name"]
340
- assert_equal 'HUEHUEBRBR', response["description"]
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["rating"]
350
- assert_equal 'lol', response["content"]
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
- "id"=>1,
362
- "time"=>Time.now.to_s,
363
- "likeable" => {
364
- "id"=>1,
365
- "body"=>"ZOMG A COMMENT"
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: "Custom blog"
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 "", (capture(:stderr) {
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: "spam-id-1")
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: "My Blog!!")
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: "Hello!!", body: "Hello, world!!", id: 43, comments: [], blog: {id: 999, name: "Custom blog"}, author: nil}}, adapter.serializable_hash)
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: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}}, adapter.serializable_hash)
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