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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47b346a9a30d6c7e246505a4b48e3c8dd593c2a6
4
- data.tar.gz: 74a94269fb1ffd10b1e30b65cd99e43ca3a62b30
3
+ metadata.gz: f97fe4e6870c3e3338fb3415b762d451f07f2b9d
4
+ data.tar.gz: a911ae55792f5fa60ddd9f198b21f3d9960d3647
5
5
  SHA512:
6
- metadata.gz: 61c621fc667fc3e1e168e50c4af8f267f4b7e3e82ce634d2555e814b2dde4a4514a9033cfa6f917b225bcc01b1f86fee36625a74e4a5d3dbeffc4209ff17aa70
7
- data.tar.gz: a365c42818a1d413d10d78abce01954160879249b6b4e6119db93178d54aa4b608c026c730b2da2f00af7c77537a1260a506ed8fbf8cecf73341f90d437b5f89
6
+ metadata.gz: 639b8b33bd971772668ead59b6e38b7f0e2aa5f36c4c680876a9241aeaa51b77e70efdfc5d8af84f9bd3bf9b5646848a8b1ad30c3e0927a98ca14fe9106410f7
7
+ data.tar.gz: 9b61116bd804ea07f9294792e73d8736b3f06b5919739c304689bf0cf9d9ef7974467eb1fef4929a5ceb6ca9629d95067761428a6f8fa86cebb870bb4d1b3d05
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ Gemfile.local
7
8
  InstalledFiles
8
9
  _yardoc
9
10
  coverage
@@ -19,3 +20,4 @@ test/version_tmp
19
20
  tmp
20
21
  *.swp
21
22
  .ruby-version
23
+ .ruby-gemset
data/.rubocop.yml ADDED
@@ -0,0 +1,82 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - config/initializers/forbidden_yaml.rb
6
+ - !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
7
+ RunRailsCops: true
8
+ DisplayCopNames: true
9
+ DisplayStyleGuide: true
10
+
11
+ Style/IndentationConsistency:
12
+ Exclude:
13
+ - lib/active_model/serializer/adapter/flatten_json.rb
14
+ - lib/active_model/serializer/adapter/fragment_cache.rb
15
+ - lib/active_model/serializer/adapter/json.rb
16
+ - lib/active_model/serializer/adapter/json/fragment_cache.rb
17
+ - lib/active_model/serializer/adapter/json_api.rb
18
+ - lib/active_model/serializer/adapter/json_api/fragment_cache.rb
19
+ - lib/active_model/serializer/adapter/json_api/pagination_links.rb
20
+ - lib/active_model/serializer/adapter/null.rb
21
+
22
+ Style/IndentationWidth:
23
+ Exclude:
24
+ - lib/active_model/serializer/adapter/flatten_json.rb
25
+ - lib/active_model/serializer/adapter/fragment_cache.rb
26
+ - lib/active_model/serializer/adapter/json.rb
27
+ - lib/active_model/serializer/adapter/json/fragment_cache.rb
28
+ - lib/active_model/serializer/adapter/json_api.rb
29
+ - lib/active_model/serializer/adapter/json_api/fragment_cache.rb
30
+ - lib/active_model/serializer/adapter/json_api/pagination_links.rb
31
+ - lib/active_model/serializer/adapter/null.rb
32
+
33
+ Style/AccessModifierIndentation:
34
+ Exclude:
35
+ - lib/active_model/serializer/adapter/flatten_json.rb
36
+ - lib/active_model/serializer/adapter/fragment_cache.rb
37
+ - lib/active_model/serializer/adapter/json.rb
38
+ - lib/active_model/serializer/adapter/json/fragment_cache.rb
39
+ - lib/active_model/serializer/adapter/json_api.rb
40
+ - lib/active_model/serializer/adapter/json_api/fragment_cache.rb
41
+ - lib/active_model/serializer/adapter/json_api/pagination_links.rb
42
+ - lib/active_model/serializer/adapter/null.rb
43
+
44
+ Lint/NestedMethodDefinition:
45
+ Enabled: false
46
+ Exclude:
47
+ - test/action_controller/serialization_test.rb
48
+
49
+ Style/StringLiterals:
50
+ EnforcedStyle: single_quotes
51
+
52
+ Metrics/AbcSize:
53
+ Max: 35 # TODO: Lower to 15
54
+
55
+ Metrics/ClassLength:
56
+ Max: 261 # TODO: Lower to 100
57
+ Exclude:
58
+ - test/**/*.rb
59
+
60
+ Metrics/CyclomaticComplexity:
61
+ Max: 7 # TODO: Lower to 6
62
+
63
+ Metrics/LineLength:
64
+ Max: 251 # TODO: Lower to 80
65
+
66
+ Metrics/MethodLength:
67
+ Max: 106 # TODO: Lower to 10
68
+
69
+ Metrics/PerceivedComplexity:
70
+ Max: 9 # TODO: Lower to 7
71
+
72
+ Style/AlignParameters:
73
+ EnforcedStyle: with_fixed_indentation
74
+
75
+ Style/ClassAndModuleChildren:
76
+ EnforcedStyle: compact
77
+
78
+ Style/Documentation:
79
+ Enabled: false
80
+
81
+ Style/MultilineOperationIndentation:
82
+ EnforcedStyle: indented
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,315 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-08-31 04:23:33 -0500 using RuboCop version 0.33.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowSafeAssignment.
11
+ Lint/AssignmentInCondition:
12
+ Exclude:
13
+ - 'lib/active_model/serializer/adapter/json_api.rb'
14
+
15
+ # Offense count: 1
16
+ Lint/EmptyEnsure:
17
+ Exclude:
18
+ - 'test/serializers/adapter_for_test.rb'
19
+
20
+ # Offense count: 1
21
+ Lint/HandleExceptions:
22
+ Exclude:
23
+ - 'Rakefile'
24
+
25
+ # Offense count: 2
26
+ # Cop supports --auto-correct.
27
+ Lint/UnusedBlockArgument:
28
+ Exclude:
29
+ - 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
30
+
31
+ # Offense count: 9
32
+ # Cop supports --auto-correct.
33
+ Lint/UnusedMethodArgument:
34
+ Exclude:
35
+ - 'lib/active_model/serializer/adapter.rb'
36
+ - 'lib/active_model/serializer/adapter/null.rb'
37
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
38
+ - 'test/fixtures/poro.rb'
39
+ - 'test/lint_test.rb'
40
+
41
+ # Offense count: 1
42
+ Lint/UselessAccessModifier:
43
+ Exclude:
44
+ - 'lib/active_model/serializable_resource.rb'
45
+
46
+ # Offense count: 3
47
+ Lint/UselessAssignment:
48
+ Exclude:
49
+ - 'bench/perf.rb'
50
+ - 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
51
+ - 'test/test_helper.rb'
52
+
53
+ # Offense count: 1
54
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
55
+ Rails/Date:
56
+ Exclude:
57
+ - 'test/fixtures/poro.rb'
58
+
59
+ # Offense count: 8
60
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
61
+ Rails/TimeZone:
62
+ Exclude:
63
+ - 'test/action_controller/serialization_test.rb'
64
+ - 'test/fixtures/poro.rb'
65
+ - 'test/serializers/cache_test.rb'
66
+
67
+ # Offense count: 16
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
70
+ Style/AlignHash:
71
+ Exclude:
72
+ - 'test/action_controller/json_api/pagination_test.rb'
73
+
74
+ # Offense count: 1
75
+ # Cop supports --auto-correct.
76
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
77
+ Style/AndOr:
78
+ Exclude:
79
+ - 'lib/active_model/serializer/lint.rb'
80
+
81
+ # Offense count: 6
82
+ # Cop supports --auto-correct.
83
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
84
+ Style/BlockDelimiters:
85
+ Enabled: false
86
+
87
+ # Offense count: 46
88
+ # Cop supports --auto-correct.
89
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
90
+ Style/BracesAroundHashParameters:
91
+ Exclude:
92
+ - 'test/action_controller/adapter_selector_test.rb'
93
+ - 'test/action_controller/json_api/pagination_test.rb'
94
+ - 'test/action_controller/serialization_test.rb'
95
+ - 'test/adapter/json_api/linked_test.rb'
96
+ - 'test/adapter/json_api/pagination_links_test.rb'
97
+ - 'test/adapter/null_test.rb'
98
+ - 'test/adapter_test.rb'
99
+ - 'test/array_serializer_test.rb'
100
+ - 'test/serializable_resource_test.rb'
101
+ - 'test/serializers/associations_test.rb'
102
+ - 'test/serializers/attribute_test.rb'
103
+ - 'test/serializers/attributes_test.rb'
104
+ - 'test/serializers/fieldset_test.rb'
105
+ - 'test/serializers/root_test.rb'
106
+ - 'test/serializers/urls_test.rb'
107
+
108
+ # Offense count: 167
109
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
110
+ Style/ClassAndModuleChildren:
111
+ Enabled: false
112
+
113
+ # Offense count: 5
114
+ # Cop supports --auto-correct.
115
+ Style/CommentIndentation:
116
+ Exclude:
117
+ - 'active_model_serializers.gemspec'
118
+
119
+ # Offense count: 1
120
+ Style/DoubleNegation:
121
+ Exclude:
122
+ - 'lib/active_model/serializable_resource.rb'
123
+
124
+ # Offense count: 1
125
+ Style/EachWithObject:
126
+ Exclude:
127
+ - 'lib/active_model/serializer/fieldset.rb'
128
+
129
+ # Offense count: 3
130
+ # Configuration parameters: MinBodyLength.
131
+ Style/GuardClause:
132
+ Exclude:
133
+ - 'lib/active_model/serializer.rb'
134
+ - 'lib/active_model/serializer/adapter/json_api.rb'
135
+ - 'test/capture_warnings.rb'
136
+
137
+ # Offense count: 12
138
+ # Cop supports --auto-correct.
139
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
140
+ Style/HashSyntax:
141
+ Enabled: false
142
+
143
+ # Offense count: 9
144
+ # Cop supports --auto-correct.
145
+ Style/IndentArray:
146
+ Exclude:
147
+ - 'test/adapter/json/has_many_test.rb'
148
+ - 'test/adapter/json_api/json_api_test.rb'
149
+ - 'test/adapter/json_api/pagination_links_test.rb'
150
+ - 'test/adapter/json_test.rb'
151
+
152
+ # Offense count: 8
153
+ # Cop supports --auto-correct.
154
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
155
+ Style/IndentHash:
156
+ Enabled: false
157
+
158
+ # Offense count: 1
159
+ # Cop supports --auto-correct.
160
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
161
+ Style/IndentationConsistency:
162
+ Exclude:
163
+ - 'test/action_controller/serialization_scope_name_test.rb'
164
+
165
+ # Offense count: 2
166
+ # Cop supports --auto-correct.
167
+ # Configuration parameters: Width.
168
+ Style/IndentationWidth:
169
+ Exclude:
170
+ - 'lib/active_model/serializable_resource.rb'
171
+ - 'lib/active_model/serializer/fieldset.rb'
172
+
173
+ # Offense count: 1
174
+ # Cop supports --auto-correct.
175
+ Style/Lambda:
176
+ Exclude:
177
+ - 'lib/active_model/serializer.rb'
178
+
179
+ # Offense count: 2
180
+ # Cop supports --auto-correct.
181
+ Style/MethodCallParentheses:
182
+ Exclude:
183
+ - 'lib/active_model/serializer/adapter/json.rb'
184
+ - 'lib/active_model/serializer/adapter/json_api.rb'
185
+
186
+ # Offense count: 1
187
+ # Cop supports --auto-correct.
188
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
189
+ Style/MethodDefParentheses:
190
+ Enabled: false
191
+
192
+ # Offense count: 3
193
+ # Cop supports --auto-correct.
194
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
195
+ Style/MultilineOperationIndentation:
196
+ Enabled: false
197
+
198
+ # Offense count: 1
199
+ # Cop supports --auto-correct.
200
+ Style/NegatedIf:
201
+ Exclude:
202
+ - 'lib/action_controller/serialization.rb'
203
+
204
+ # Offense count: 1
205
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
206
+ Style/Next:
207
+ Exclude:
208
+ - 'lib/active_model/serializer/adapter/json_api.rb'
209
+
210
+ # Offense count: 1
211
+ # Cop supports --auto-correct.
212
+ Style/NumericLiterals:
213
+ MinDigits: 7
214
+
215
+ # Offense count: 2
216
+ # Cop supports --auto-correct.
217
+ # Configuration parameters: PreferredDelimiters.
218
+ Style/PercentLiteralDelimiters:
219
+ Exclude:
220
+ - 'active_model_serializers.gemspec'
221
+
222
+ # Offense count: 2
223
+ # Cop supports --auto-correct.
224
+ Style/PerlBackrefs:
225
+ Exclude:
226
+ - 'test/fixtures/poro.rb'
227
+ - 'test/serializers/associations_test.rb'
228
+
229
+ # Offense count: 6
230
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist.
231
+ Style/PredicateName:
232
+ Exclude:
233
+ - 'lib/active_model/serializer/adapter.rb'
234
+ - 'lib/active_model/serializer/adapter/json_api.rb'
235
+ - 'lib/active_model/serializer/associations.rb'
236
+ - 'test/action_controller/json_api/linked_test.rb'
237
+
238
+ # Offense count: 7
239
+ # Cop supports --auto-correct.
240
+ Style/RedundantSelf:
241
+ Exclude:
242
+ - 'lib/active_model/serializer.rb'
243
+ - 'lib/active_model/serializer/associations.rb'
244
+ - 'test/fixtures/poro.rb'
245
+
246
+ # Offense count: 1
247
+ # Cop supports --auto-correct.
248
+ # Configuration parameters: AllowAsExpressionSeparator.
249
+ Style/Semicolon:
250
+ Exclude:
251
+ - 'lib/active_model/serializer/fieldset.rb'
252
+
253
+ # Offense count: 6
254
+ # Cop supports --auto-correct.
255
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
256
+ Style/SignalException:
257
+ Exclude:
258
+ - 'lib/active_model/serializer.rb'
259
+ - 'lib/active_model/serializer/adapter.rb'
260
+ - 'lib/active_model/serializer/fieldset.rb'
261
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
262
+
263
+ # Offense count: 1
264
+ # Cop supports --auto-correct.
265
+ # Configuration parameters: AllowIfMethodIsEmpty.
266
+ Style/SingleLineMethods:
267
+ Exclude:
268
+ - 'test/serializers/serializer_for_test.rb'
269
+
270
+ # Offense count: 2
271
+ # Cop supports --auto-correct.
272
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
273
+ Style/StringLiteralsInInterpolation:
274
+ Enabled: false
275
+
276
+ # Offense count: 1
277
+ Style/StructInheritance:
278
+ Exclude:
279
+ - 'bench/perf.rb'
280
+
281
+ # Offense count: 1
282
+ # Cop supports --auto-correct.
283
+ # Configuration parameters: IgnoredMethods.
284
+ Style/SymbolProc:
285
+ Exclude:
286
+ - 'lib/generators/serializer/serializer_generator.rb'
287
+
288
+ # Offense count: 8
289
+ # Cop supports --auto-correct.
290
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
291
+ Style/TrailingBlankLines:
292
+ Exclude:
293
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
294
+ - 'lib/generators/serializer/serializer_generator.rb'
295
+ - 'test/adapter/fragment_cache_test.rb'
296
+ - 'test/adapter/json_api/json_api_test.rb'
297
+ - 'test/adapter/null_test.rb'
298
+ - 'test/serializers/cache_test.rb'
299
+ - 'test/serializers/fieldset_test.rb'
300
+ - 'test/support/stream_capture.rb'
301
+
302
+ # Offense count: 6
303
+ # Cop supports --auto-correct.
304
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
305
+ Style/TrailingComma:
306
+ Exclude:
307
+ - 'test/action_controller/adapter_selector_test.rb'
308
+ - 'test/action_controller/serialization_test.rb'
309
+ - 'test/adapter/json_api/belongs_to_test.rb'
310
+ - 'test/adapter/json_api/linked_test.rb'
311
+
312
+ # Offense count: 1
313
+ Style/UnlessElse:
314
+ Exclude:
315
+ - 'lib/active_model/serializer.rb'
data/.simplecov ADDED
@@ -0,0 +1,99 @@
1
+ # https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config
2
+ # see https://github.com/colszowka/simplecov/blob/master/lib/simplecov/defaults.rb
3
+ # vim: set ft=ruby
4
+
5
+ ## DEFINE VARIABLES
6
+ @minimum_coverage = ENV.fetch('COVERAGE_MINIMUM') {
7
+ case (defined?(RUBY_ENGINE) && RUBY_ENGINE) || "ruby"
8
+ when 'jruby', 'rbx'
9
+ 96.0
10
+ else
11
+ 98.1
12
+ end
13
+ }.to_f.round(2)
14
+ # rubocop:disable Style/DoubleNegation
15
+ ENV['FULL_BUILD'] ||= ENV['CI']
16
+ @running_ci = !!(ENV['FULL_BUILD'] =~ /\Atrue\z/i)
17
+ @generate_report = @running_ci || !!(ENV['COVERAGE'] =~ /\Atrue\z/i)
18
+ @output = STDOUT
19
+ # rubocop:enable Style/DoubleNegation
20
+
21
+ ## CONFIGURE SIMPLECOV
22
+ SimpleCov.pid = $$ # In case there's any forking
23
+
24
+ SimpleCov.profiles.define 'app' do
25
+ coverage_dir 'coverage'
26
+ load_profile 'test_frameworks'
27
+
28
+ add_group 'Libraries', 'lib'
29
+
30
+ add_group 'Long files' do |src_file|
31
+ src_file.lines.count > 100
32
+ end
33
+ class MaxLinesFilter < SimpleCov::Filter
34
+ def matches?(source_file)
35
+ source_file.lines.count < filter_argument
36
+ end
37
+ end
38
+ add_group 'Short files', MaxLinesFilter.new(5)
39
+
40
+ # Exclude these paths from analysis
41
+ add_filter '/config/'
42
+ add_filter '/db/'
43
+ add_filter 'tasks'
44
+ end
45
+
46
+ ## START TRACKING COVERAGE (before activating SimpleCov)
47
+ require 'coverage'
48
+ Coverage.start
49
+
50
+ ## ADD SOME CUSTOM REPORTING AT EXIT
51
+ SimpleCov.at_exit do
52
+ header = "#{'*' * 20} SimpleCov Results #{'*' * 20}"
53
+ @output.puts
54
+ @output.puts header
55
+ @output.puts SimpleCov.result.format!
56
+ percent = Float(SimpleCov.result.covered_percent)
57
+ if percent < @minimum_coverage
58
+ @output.puts "Spec coverage was not high enough: "\
59
+ "#{percent.round(2)} is < #{@minimum_coverage}%\n"
60
+ exit 1 if @generate_report
61
+ else
62
+ @output.puts "Nice job! Spec coverage (#{percent.round(2)}) "\
63
+ "is still at or above #{@minimum_coverage}%\n"
64
+ end
65
+ @output.puts
66
+ @output.puts '*' * header.size
67
+ end
68
+
69
+ ## CAPTURE CONFIG IN CLOSURE 'AppCoverage.start'
70
+ ## to defer running until test/test_helper.rb is loaded.
71
+ # rubocop:disable Style/MultilineBlockChain
72
+ AppCoverage = Class.new do
73
+ def initialize(&block)
74
+ @block = block
75
+ end
76
+
77
+ def start
78
+ @block.call
79
+ end
80
+ end.new do
81
+ SimpleCov.start 'app'
82
+ if @generate_report
83
+ if @running_ci
84
+ require 'codeclimate-test-reporter'
85
+ @output.puts '[COVERAGE] Running with SimpleCov Simple Formatter and CodeClimate Test Reporter'
86
+ formatters = [
87
+ SimpleCov::Formatter::SimpleFormatter,
88
+ CodeClimate::TestReporter::Formatter
89
+ ]
90
+ else
91
+ @output.puts '[COVERAGE] Running with SimpleCov HTML Formatter'
92
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
93
+ end
94
+ else
95
+ formatters = []
96
+ end
97
+ SimpleCov.formatters = formatters
98
+ end
99
+ # rubocop:enable Style/MultilineBlockChain