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.
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
@@ -53,94 +53,94 @@ module ActiveModel
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
  ]
@@ -162,39 +162,39 @@ module ActiveModel
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
  ]
@@ -229,21 +229,21 @@ module ActiveModel
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
  }
@@ -262,14 +262,14 @@ module ActiveModel
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
  }
@@ -20,9 +20,9 @@ module ActiveModel
20
20
  ]
21
21
  end
22
22
 
23
- def mock_request(query_parameters={}, original_url=URI)
23
+ def mock_request(query_parameters = {}, original_url = URI)
24
24
  context = Minitest::Mock.new
25
- context.expect(:original_url, original_url )
25
+ context.expect(:original_url, original_url)
26
26
  context.expect(:query_parameters, query_parameters)
27
27
  @options = {}
28
28
  @options[:context] = context
@@ -42,17 +42,17 @@ module ActiveModel
42
42
  end
43
43
 
44
44
  def data
45
- { data:[
46
- { id:"1", type:"profiles", attributes:{name:"Name 1", description:"Description 1" } },
47
- { id:"2", type:"profiles", attributes:{name:"Name 2", description:"Description 2" } },
48
- { id:"3", type:"profiles", attributes:{name:"Name 3", description:"Description 3" } }
45
+ { data: [
46
+ { id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
47
+ { id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
48
+ { id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } }
49
49
  ]
50
50
  }
51
51
  end
52
52
 
53
53
  def links
54
54
  {
55
- links:{
55
+ links: {
56
56
  self: "#{URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
57
57
  first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
58
58
  prev: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
@@ -74,7 +74,7 @@ module ActiveModel
74
74
  end
75
75
 
76
76
  def expected_response_with_pagination_links_and_additional_params
77
- new_links = links[:links].each_with_object({}) {|(key, value), hash| hash[key] = "#{value}&test=test" }
77
+ new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
78
78
  {}.tap do |hash|
79
79
  hash[:data] = [data.values.flatten.second]
80
80
  hash.merge! links: new_links
@@ -21,35 +21,35 @@ module ActiveModel
21
21
  @comment.author = nil
22
22
  @post.author = @author
23
23
  @anonymous_post.author = nil
24
- @blog = Blog.new(id: 1, name: "My Blog!!")
24
+ @blog = Blog.new(id: 1, name: 'My Blog!!')
25
25
  @blog.writer = @author
26
26
  @blog.articles = [@post, @anonymous_post]
27
27
  @author.posts = []
28
28
  end
29
29
 
30
30
  def with_jsonapi_resource_type type
31
- old_type = ActiveModel::Serializer.config[:jsonapi_resource_type]
32
- ActiveModel::Serializer.config[:jsonapi_resource_type] = type
31
+ old_type = ActiveModel::Serializer.config.jsonapi_resource_type
32
+ ActiveModel::Serializer.config.jsonapi_resource_type = type
33
33
  yield
34
34
  ensure
35
- ActiveModel::Serializer.config[:jsonapi_resource_type] = old_type
35
+ ActiveModel::Serializer.config.jsonapi_resource_type = old_type
36
36
  end
37
37
 
38
38
  def test_config_plural
39
- with_jsonapi_resource_type :plural do
40
- serializer = CommentSerializer.new(@comment)
41
- adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
42
- ActionController::Base.cache_store.clear
43
- assert_equal('comments', adapter.serializable_hash[:data][:type])
39
+ with_adapter :json_api do
40
+ with_jsonapi_resource_type :plural do
41
+ hash = ActiveModel::SerializableResource.new(@comment).serializable_hash
42
+ assert_equal('comments', hash[:data][:type])
43
+ end
44
44
  end
45
45
  end
46
46
 
47
47
  def test_config_singular
48
- with_jsonapi_resource_type :singular do
49
- serializer = CommentSerializer.new(@comment)
50
- adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
51
- ActionController::Base.cache_store.clear
52
- assert_equal('comment', adapter.serializable_hash[:data][:type])
48
+ with_adapter :json_api do
49
+ with_jsonapi_resource_type :singular do
50
+ hash = ActiveModel::SerializableResource.new(@comment).serializable_hash
51
+ assert_equal('comment', hash[:data][:type])
52
+ end
53
53
  end
54
54
  end
55
55
  end
@@ -14,7 +14,7 @@ module ActiveModel
14
14
  @first_comment.post = @post
15
15
  @second_comment.post = @post
16
16
  @post.author = @author
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
 
20
20
  @serializer = PostSerializer.new(@post)
@@ -23,8 +23,8 @@ module ActiveModel
23
23
 
24
24
  def test_has_many
25
25
  assert_equal([
26
- {id: 1, body: 'ZOMG A COMMENT'},
27
- {id: 2, body: 'ZOMG ANOTHER COMMENT'}
26
+ { id: 1, body: 'ZOMG A COMMENT' },
27
+ { id: 2, body: 'ZOMG ANOTHER COMMENT' }
28
28
  ], @adapter.serializable_hash[:post][:comments])
29
29
  end
30
30
 
@@ -34,11 +34,11 @@ module ActiveModel
34
34
 
35
35
  assert_equal({
36
36
  id: 1,
37
- reviews: [{id: 1, body: "ZOMG A COMMENT"},
38
- {id: 2, body: "ZOMG ANOTHER COMMENT"}
37
+ reviews: [{ id: 1, body: 'ZOMG A COMMENT' },
38
+ { id: 2, body: 'ZOMG ANOTHER COMMENT' }
39
39
  ],
40
- writer: {id: 1, name: "Steve K."},
41
- site: {id: 1, name: "My Blog!!"}
40
+ writer: { id: 1, name: 'Steve K.' },
41
+ site: { id: 1, name: 'My Blog!!' }
42
42
  }, adapter.serializable_hash[:post])
43
43
  end
44
44
  end
data/test/adapter_test.rb CHANGED
@@ -35,12 +35,12 @@ module ActiveModel
35
35
  end
36
36
 
37
37
  def test_create_adapter_with_override
38
- adapter = ActiveModel::Serializer::Adapter.create(@serializer, { adapter: :json_api})
38
+ adapter = ActiveModel::Serializer::Adapter.create(@serializer, { adapter: :json_api })
39
39
  assert_equal ActiveModel::Serializer::Adapter::JsonApi, adapter.class
40
40
  end
41
41
 
42
42
  def test_inflected_adapter_class_for_known_adapter
43
- ActiveSupport::Inflector.inflections(:en){|inflect| inflect.acronym 'API' }
43
+ ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym 'API' }
44
44
  klass = ActiveModel::Serializer::Adapter.adapter_class(:json_api)
45
45
 
46
46
  ActiveSupport::Inflector.inflections.acronyms.clear
@@ -7,14 +7,18 @@ module ActiveModel
7
7
  @comment = Comment.new
8
8
  @post = Post.new
9
9
  @resource = build_named_collection @comment, @post
10
- @serializer = ArraySerializer.new(@resource, {some: :options})
10
+ @serializer = ArraySerializer.new(@resource, { some: :options })
11
11
  end
12
12
 
13
13
  def build_named_collection(*resource)
14
- resource.define_singleton_method(:name){ 'MeResource' }
14
+ resource.define_singleton_method(:name) { 'MeResource' }
15
15
  resource
16
16
  end
17
17
 
18
+ def test_has_object_reader_serializer_interface
19
+ assert_equal @serializer.object, @resource
20
+ end
21
+
18
22
  def test_respond_to_each
19
23
  assert_respond_to @serializer, :each
20
24
  end
@@ -32,17 +36,17 @@ module ActiveModel
32
36
  end
33
37
 
34
38
  def test_serializer_option_not_passed_to_each_serializer
35
- serializers = ArraySerializer.new([@post], {serializer: PostSerializer}).to_a
39
+ serializers = ArraySerializer.new([@post], { serializer: PostSerializer }).to_a
36
40
 
37
41
  refute serializers.first.custom_options.key?(:serializer)
38
42
  end
39
43
 
40
44
  def test_meta_and_meta_key_attr_readers
41
- meta_content = {meta: "the meta", meta_key: "the meta key"}
45
+ meta_content = { meta: 'the meta', meta_key: 'the meta key' }
42
46
  @serializer = ArraySerializer.new([@comment, @post], meta_content)
43
47
 
44
- assert_equal @serializer.meta, "the meta"
45
- assert_equal @serializer.meta_key, "the meta key"
48
+ assert_equal @serializer.meta, 'the meta'
49
+ assert_equal @serializer.meta_key, 'the meta key'
46
50
  end
47
51
 
48
52
  def test_root_default
@@ -73,7 +77,7 @@ module ActiveModel
73
77
 
74
78
  def test_json_key_with_resource_with_nil_name_and_no_serializers
75
79
  resource = []
76
- resource.define_singleton_method(:name){ nil }
80
+ resource.define_singleton_method(:name) { nil }
77
81
  serializer = ArraySerializer.new(resource)
78
82
  assert_equal serializer.json_key, nil
79
83
  end
@@ -1,15 +1,15 @@
1
1
  # https://raw.githubusercontent.com/metric_fu/metric_fu/master/spec/capture_warnings.rb
2
- require "tempfile"
3
- require "fileutils"
2
+ require 'tempfile'
3
+ require 'fileutils'
4
4
 
5
5
  class CaptureWarnings
6
6
  def initialize(fail_on_warnings = true)
7
7
  @fail_on_warnings = fail_on_warnings
8
- @stderr_file = Tempfile.new("app.stderr")
8
+ @stderr_file = Tempfile.new('app.stderr')
9
9
  @app_root ||= Dir.pwd
10
- @output_dir = File.join(app_root, "tmp")
10
+ @output_dir = File.join(app_root, 'tmp')
11
11
  FileUtils.mkdir_p(output_dir)
12
- @bundle_dir = File.join(app_root, "bundle")
12
+ @bundle_dir = File.join(app_root, 'bundle')
13
13
  end
14
14
 
15
15
  def before_tests
@@ -40,9 +40,9 @@ class CaptureWarnings
40
40
  end
41
41
 
42
42
  if other_warnings.any?
43
- File.write(File.join(output_dir, "warnings.txt"), other_warnings.join("\n") << "\n")
43
+ File.write(File.join(output_dir, 'warnings.txt'), other_warnings.join("\n") << "\n")
44
44
  puts
45
- puts "Non-app warnings written to tmp/warnings.txt"
45
+ puts 'Non-app warnings written to tmp/warnings.txt'
46
46
  puts
47
47
  end
48
48
 
@@ -53,5 +53,6 @@ class CaptureWarnings
53
53
  end
54
54
 
55
55
  private
56
+
56
57
  attr_reader :stderr_file, :app_root, :output_dir, :bundle_dir, :fail_on_warnings
57
58
  end
@@ -40,7 +40,6 @@ module ARModels
40
40
 
41
41
  has_many :comments
42
42
  belongs_to :author
43
- url :comments
44
43
  end
45
44
 
46
45
  class CommentSerializer < ActiveModel::Serializer
@@ -7,7 +7,7 @@ class Model
7
7
  @_model_name ||= ActiveModel::Name.new(self)
8
8
  end
9
9
 
10
- def initialize(hash={})
10
+ def initialize(hash = {})
11
11
  @attributes = hash
12
12
  end
13
13
 
@@ -59,8 +59,6 @@ end
59
59
  class ProfileSerializer < ActiveModel::Serializer
60
60
  attributes :name, :description
61
61
 
62
- urls :posts, :comments
63
-
64
62
  def arguments_passed_in?
65
63
  options[:my_options] == :accessible
66
64
  end
@@ -68,8 +66,6 @@ end
68
66
 
69
67
  class ProfilePreviewSerializer < ActiveModel::Serializer
70
68
  attributes :name
71
-
72
- urls :posts, :comments
73
69
  end
74
70
 
75
71
  Post = Class.new(Model)
@@ -83,7 +79,7 @@ Location = Class.new(Model)
83
79
  Place = Class.new(Model)
84
80
  Tag = Class.new(Model)
85
81
  VirtualValue = Class.new(Model)
86
- Comment = Class.new(Model) do
82
+ Comment = Class.new(Model) do
87
83
  # Uses a custom non-time-based cache key
88
84
  def cache_key
89
85
  "#{self.class.name.downcase}/#{self.id}"
@@ -94,16 +90,15 @@ module Spam; end
94
90
  Spam::UnrelatedLink = Class.new(Model)
95
91
 
96
92
  PostSerializer = Class.new(ActiveModel::Serializer) do
97
- cache key:'post', expires_in: 0.1, skip_digest: true
93
+ cache key: 'post', expires_in: 0.1, skip_digest: true
98
94
  attributes :id, :title, :body
99
95
 
100
96
  has_many :comments
101
97
  belongs_to :blog
102
98
  belongs_to :author
103
- url :comments
104
99
 
105
100
  def blog
106
- Blog.new(id: 999, name: "Custom blog")
101
+ Blog.new(id: 999, name: 'Custom blog')
107
102
  end
108
103
 
109
104
  def custom_options
@@ -133,7 +128,7 @@ CommentSerializer = Class.new(ActiveModel::Serializer) do
133
128
  end
134
129
 
135
130
  AuthorSerializer = Class.new(ActiveModel::Serializer) do
136
- cache key:'writer', skip_digest: true
131
+ cache key: 'writer', skip_digest: true
137
132
  attribute :id
138
133
  attribute :name
139
134
 
@@ -249,8 +244,8 @@ end
249
244
  VirtualValueSerializer = Class.new(ActiveModel::Serializer) do
250
245
  attributes :id
251
246
 
252
- has_many :reviews, virtual_value: [{id: 1}, {id: 2}]
253
- has_one :maker, virtual_value: {id: 1}
247
+ has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
248
+ has_one :maker, virtual_value: { id: 1 }
254
249
 
255
250
  def reviews
256
251
  end
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- # require 'active_model/serializer/railtie'
3
2
 
4
3
  class ResourceGeneratorTest < Rails::Generators::TestCase
5
4
  destination File.expand_path('../../../tmp/generators', __FILE__)
@@ -19,6 +18,6 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
19
18
  def copy_routes
20
19
  config_dir = File.join(destination_root, 'config')
21
20
  FileUtils.mkdir_p(config_dir)
22
- File.write(File.join(config_dir, 'routes.rb'), 'Rails.application.routes.draw { }')
21
+ File.write(File.join(config_dir, 'routes.rb'), 'Rails.application.routes.draw {}')
23
22
  end
24
23
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require 'generators/serializer/serializer_generator'
3
3
 
4
4
  class SerializerGeneratorTest < Rails::Generators::TestCase
5
- destination File.expand_path("../../../tmp/generators", __FILE__)
5
+ destination File.expand_path('../../../tmp/generators', __FILE__)
6
6
  setup :prepare_destination
7
7
 
8
8
  tests Rails::Generators::SerializerGenerator
@@ -10,33 +10,33 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
10
10
 
11
11
  def test_generates_a_serializer
12
12
  run_generator
13
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer/
13
+ assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < ActiveModel::Serializer/
14
14
  end
15
15
 
16
16
  def test_generates_a_namespaced_serializer
17
- run_generator ["admin/account"]
18
- assert_file "app/serializers/admin/account_serializer.rb", /class Admin::AccountSerializer < ActiveModel::Serializer/
17
+ run_generator ['admin/account']
18
+ assert_file 'app/serializers/admin/account_serializer.rb', /class Admin::AccountSerializer < ActiveModel::Serializer/
19
19
  end
20
20
 
21
21
  def test_uses_application_serializer_if_one_exists
22
22
  Object.const_set(:ApplicationSerializer, Class.new)
23
23
  run_generator
24
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ApplicationSerializer/
24
+ assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < ApplicationSerializer/
25
25
  ensure
26
26
  Object.send :remove_const, :ApplicationSerializer
27
27
  end
28
28
 
29
29
  def test_uses_given_parent
30
30
  Object.const_set(:ApplicationSerializer, Class.new)
31
- run_generator ["Account", "--parent=MySerializer"]
32
- assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < MySerializer/
31
+ run_generator ['Account', '--parent=MySerializer']
32
+ assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < MySerializer/
33
33
  ensure
34
34
  Object.send :remove_const, :ApplicationSerializer
35
35
  end
36
36
 
37
37
  def test_generates_attributes_and_associations
38
38
  run_generator
39
- assert_file "app/serializers/account_serializer.rb" do |serializer|
39
+ assert_file 'app/serializers/account_serializer.rb' do |serializer|
40
40
  assert_match(/^ attributes :id, :name, :description$/, serializer)
41
41
  assert_match(/^ has_one :business$/, serializer)
42
42
  assert_match(/^end\n*\z/, serializer)
@@ -44,8 +44,8 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
44
44
  end
45
45
 
46
46
  def test_with_no_attributes_does_not_add_extra_space
47
- run_generator ["account"]
48
- assert_file "app/serializers/account_serializer.rb" do |content|
47
+ run_generator ['account']
48
+ assert_file 'app/serializers/account_serializer.rb' do |content|
49
49
  if RUBY_PLATFORM =~ /mingw/
50
50
  assert_no_match(/\r\n\r\nend/, content)
51
51
  else