active_model_serializers 0.8.3 → 0.10.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +86 -0
  4. data/.rubocop_todo.yml +240 -0
  5. data/.simplecov +111 -0
  6. data/.travis.yml +33 -22
  7. data/CHANGELOG.md +358 -6
  8. data/CONTRIBUTING.md +220 -0
  9. data/Gemfile +46 -1
  10. data/{MIT-LICENSE.txt → LICENSE.txt} +3 -2
  11. data/README.md +81 -591
  12. data/Rakefile +68 -11
  13. data/active_model_serializers.gemspec +57 -23
  14. data/appveyor.yml +27 -0
  15. data/docs/ARCHITECTURE.md +120 -0
  16. data/docs/DESIGN.textile +8 -0
  17. data/docs/README.md +35 -0
  18. data/docs/general/adapters.md +162 -0
  19. data/docs/general/caching.md +52 -0
  20. data/docs/general/configuration_options.md +27 -0
  21. data/docs/general/getting_started.md +98 -0
  22. data/docs/general/instrumentation.md +40 -0
  23. data/docs/general/logging.md +14 -0
  24. data/docs/general/rendering.md +153 -0
  25. data/docs/general/serializers.md +207 -0
  26. data/docs/how-open-source-maintained.jpg +0 -0
  27. data/docs/howto/add_pagination_links.md +121 -0
  28. data/docs/howto/add_root_key.md +51 -0
  29. data/docs/howto/outside_controller_use.md +58 -0
  30. data/docs/howto/test.md +152 -0
  31. data/docs/integrations/ember-and-json-api.md +112 -0
  32. data/docs/integrations/grape.md +19 -0
  33. data/docs/jsonapi/schema/schema.json +366 -0
  34. data/docs/jsonapi/schema.md +140 -0
  35. data/lib/action_controller/serialization.rb +41 -37
  36. data/lib/active_model/serializable_resource.rb +72 -0
  37. data/lib/active_model/serializer/adapter/attributes.rb +66 -0
  38. data/lib/active_model/serializer/adapter/base.rb +58 -0
  39. data/lib/active_model/serializer/adapter/cached_serializer.rb +45 -0
  40. data/lib/active_model/serializer/adapter/fragment_cache.rb +111 -0
  41. data/lib/active_model/serializer/adapter/json/fragment_cache.rb +13 -0
  42. data/lib/active_model/serializer/adapter/json.rb +21 -0
  43. data/lib/active_model/serializer/adapter/json_api/deserialization.rb +207 -0
  44. data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +21 -0
  45. data/lib/active_model/serializer/adapter/json_api/link.rb +44 -0
  46. data/lib/active_model/serializer/adapter/json_api/pagination_links.rb +58 -0
  47. data/lib/active_model/serializer/adapter/json_api.rb +223 -0
  48. data/lib/active_model/serializer/adapter/null.rb +11 -0
  49. data/lib/active_model/serializer/adapter.rb +91 -0
  50. data/lib/active_model/serializer/array_serializer.rb +9 -0
  51. data/lib/active_model/serializer/association.rb +20 -0
  52. data/lib/active_model/serializer/associations.rb +87 -220
  53. data/lib/active_model/serializer/attribute.rb +25 -0
  54. data/lib/active_model/serializer/attributes.rb +82 -0
  55. data/lib/active_model/serializer/belongs_to_reflection.rb +10 -0
  56. data/lib/active_model/serializer/caching.rb +100 -0
  57. data/lib/active_model/serializer/collection_reflection.rb +7 -0
  58. data/lib/active_model/serializer/collection_serializer.rb +47 -0
  59. data/lib/active_model/serializer/configuration.rb +28 -0
  60. data/lib/active_model/serializer/field.rb +56 -0
  61. data/lib/active_model/serializer/fieldset.rb +31 -0
  62. data/lib/active_model/serializer/has_many_reflection.rb +10 -0
  63. data/lib/active_model/serializer/has_one_reflection.rb +10 -0
  64. data/lib/active_model/serializer/include_tree.rb +111 -0
  65. data/lib/active_model/serializer/links.rb +33 -0
  66. data/lib/active_model/serializer/lint.rb +142 -0
  67. data/lib/active_model/serializer/reflection.rb +91 -0
  68. data/lib/active_model/serializer/singular_reflection.rb +7 -0
  69. data/lib/active_model/serializer/type.rb +25 -0
  70. data/lib/active_model/{serializers → serializer}/version.rb +1 -1
  71. data/lib/active_model/serializer.rb +99 -479
  72. data/lib/active_model_serializers/callbacks.rb +55 -0
  73. data/lib/active_model_serializers/deserialization.rb +13 -0
  74. data/lib/active_model_serializers/logging.rb +119 -0
  75. data/lib/active_model_serializers/model.rb +39 -0
  76. data/lib/active_model_serializers/railtie.rb +38 -0
  77. data/lib/active_model_serializers/serialization_context.rb +10 -0
  78. data/lib/active_model_serializers/test/schema.rb +103 -0
  79. data/lib/active_model_serializers/test/serializer.rb +125 -0
  80. data/lib/active_model_serializers/test.rb +7 -0
  81. data/lib/active_model_serializers.rb +20 -92
  82. data/lib/generators/rails/USAGE +6 -0
  83. data/lib/generators/rails/resource_override.rb +10 -0
  84. data/lib/generators/rails/serializer_generator.rb +36 -0
  85. data/lib/generators/rails/templates/serializer.rb.erb +8 -0
  86. data/lib/grape/active_model_serializers.rb +14 -0
  87. data/lib/grape/formatters/active_model_serializers.rb +15 -0
  88. data/lib/grape/helpers/active_model_serializers.rb +16 -0
  89. data/test/action_controller/adapter_selector_test.rb +53 -0
  90. data/test/action_controller/explicit_serializer_test.rb +134 -0
  91. data/test/action_controller/json/include_test.rb +167 -0
  92. data/test/action_controller/json_api/deserialization_test.rb +59 -0
  93. data/test/action_controller/json_api/linked_test.rb +196 -0
  94. data/test/action_controller/json_api/pagination_test.rb +116 -0
  95. data/test/{serialization_scope_name_test.rb → action_controller/serialization_scope_name_test.rb} +11 -15
  96. data/test/action_controller/serialization_test.rb +435 -0
  97. data/test/active_model_serializers/logging_test.rb +77 -0
  98. data/test/active_model_serializers/model_test.rb +9 -0
  99. data/test/active_model_serializers/railtie_test_isolated.rb +57 -0
  100. data/test/active_model_serializers/serialization_context_test.rb +18 -0
  101. data/test/active_model_serializers/test/schema_test.rb +128 -0
  102. data/test/active_model_serializers/test/serializer_test.rb +63 -0
  103. data/test/active_record_test.rb +9 -0
  104. data/test/adapter/fragment_cache_test.rb +38 -0
  105. data/test/adapter/json/belongs_to_test.rb +47 -0
  106. data/test/adapter/json/collection_test.rb +92 -0
  107. data/test/adapter/json/has_many_test.rb +47 -0
  108. data/test/adapter/json_api/belongs_to_test.rb +157 -0
  109. data/test/adapter/json_api/collection_test.rb +97 -0
  110. data/test/adapter/json_api/fields_test.rb +89 -0
  111. data/test/adapter/json_api/has_many_embed_ids_test.rb +45 -0
  112. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +98 -0
  113. data/test/adapter/json_api/has_many_test.rb +145 -0
  114. data/test/adapter/json_api/has_one_test.rb +81 -0
  115. data/test/adapter/json_api/json_api_test.rb +37 -0
  116. data/test/adapter/json_api/linked_test.rb +394 -0
  117. data/test/adapter/json_api/links_test.rb +68 -0
  118. data/test/adapter/json_api/pagination_links_test.rb +115 -0
  119. data/test/adapter/json_api/parse_test.rb +139 -0
  120. data/test/adapter/json_api/resource_type_config_test.rb +71 -0
  121. data/test/adapter/json_api/toplevel_jsonapi_test.rb +84 -0
  122. data/test/adapter/json_test.rb +47 -0
  123. data/test/adapter/null_test.rb +25 -0
  124. data/test/adapter_test.rb +42 -0
  125. data/test/array_serializer_test.rb +36 -73
  126. data/test/collection_serializer_test.rb +100 -0
  127. data/test/fixtures/active_record.rb +56 -0
  128. data/test/fixtures/poro.rb +229 -0
  129. data/test/generators/scaffold_controller_generator_test.rb +24 -0
  130. data/test/generators/serializer_generator_test.rb +57 -0
  131. data/test/grape_test.rb +82 -0
  132. data/test/include_tree/from_include_args_test.rb +26 -0
  133. data/test/include_tree/from_string_test.rb +94 -0
  134. data/test/include_tree/include_args_to_hash_test.rb +64 -0
  135. data/test/lint_test.rb +40 -0
  136. data/test/logger_test.rb +18 -0
  137. data/test/poro_test.rb +9 -0
  138. data/test/serializable_resource_test.rb +27 -0
  139. data/test/serializers/adapter_for_test.rb +166 -0
  140. data/test/serializers/association_macros_test.rb +36 -0
  141. data/test/serializers/associations_test.rb +267 -0
  142. data/test/serializers/attribute_test.rb +123 -0
  143. data/test/serializers/attributes_test.rb +52 -0
  144. data/test/serializers/cache_test.rb +209 -0
  145. data/test/serializers/configuration_test.rb +32 -0
  146. data/test/serializers/fieldset_test.rb +14 -0
  147. data/test/serializers/meta_test.rb +130 -0
  148. data/test/serializers/options_test.rb +21 -0
  149. data/test/serializers/root_test.rb +21 -0
  150. data/test/serializers/serializer_for_test.rb +134 -0
  151. data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +6 -0
  152. data/test/support/isolated_unit.rb +77 -0
  153. data/test/support/rails5_shims.rb +29 -0
  154. data/test/support/rails_app.rb +25 -0
  155. data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +6 -0
  156. data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +6 -0
  157. data/test/support/schemas/custom/show.json +7 -0
  158. data/test/support/schemas/hyper_schema.json +93 -0
  159. data/test/support/schemas/render_using_json_api.json +43 -0
  160. data/test/support/schemas/simple_json_pointers.json +10 -0
  161. data/test/support/serialization_testing.rb +53 -0
  162. data/test/support/simplecov.rb +6 -0
  163. data/test/support/stream_capture.rb +50 -0
  164. data/test/support/test_case.rb +19 -0
  165. data/test/test_helper.rb +55 -24
  166. metadata +358 -42
  167. data/DESIGN.textile +0 -586
  168. data/Gemfile.edge +0 -9
  169. data/bench/perf.rb +0 -43
  170. data/cruft.md +0 -19
  171. data/lib/active_model/array_serializer.rb +0 -104
  172. data/lib/active_record/serializer_override.rb +0 -16
  173. data/lib/generators/resource_override.rb +0 -13
  174. data/lib/generators/serializer/USAGE +0 -9
  175. data/lib/generators/serializer/serializer_generator.rb +0 -42
  176. data/lib/generators/serializer/templates/serializer.rb +0 -19
  177. data/test/association_test.rb +0 -592
  178. data/test/caching_test.rb +0 -96
  179. data/test/generators_test.rb +0 -85
  180. data/test/no_serialization_scope_test.rb +0 -34
  181. data/test/serialization_test.rb +0 -392
  182. data/test/serializer_support_test.rb +0 -51
  183. data/test/serializer_test.rb +0 -1465
  184. data/test/test_fakes.rb +0 -217
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94274a9d3a573ae8f656719aef33825cabb68673
4
- data.tar.gz: b1d614a90149ec109b67e963464c232d0b5ed3f1
3
+ metadata.gz: 3a84e967d6d485d49bae001e8937b44c77ea0100
4
+ data.tar.gz: 707f685e66fdd3e54ee76944d7594e272eaf2920
5
5
  SHA512:
6
- metadata.gz: cc3140d1676014d8ce4aa0add253d247c55652a689cb83e7f7f7a71a81ae8d7c601fc5e2d261d415e243857a479a15156d0a84a67beb1c72475ef51c063cdfca
7
- data.tar.gz: cfc92ac9bb7dfca07cebdd32ef4a120aa5784cc7f1a6bfc8a65900b553be736b174b6bbf22fb7ebd55e8295ea1d118373245396e3c0ac883e954ab27e925bca2
6
+ metadata.gz: 090a01fff8f35b0e858f31a271f34c53f0d87bd82f1f5ead1e0515d38ee8447a0ba9d2f38abc0dfcf188efe59fdfc4d2057d28296dfe8a5e4abd6464c7dff635
7
+ data.tar.gz: 34095f697906ad34ca02913a5619a787d82382baf9b1a60cf9ed43fc74e9939aee8f1391c61dc4a16c60fcdcd009b1479bc407ed6b1c304c54f7081f01f67fc2
data/.gitignore CHANGED
@@ -4,15 +4,21 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ Gemfile.local
7
8
  InstalledFiles
8
9
  _yardoc
9
10
  coverage
10
11
  doc/
11
12
  lib/bundler/man
12
13
  pkg
14
+ Vagrantfile
15
+ .vagrant
13
16
  rdoc
14
17
  spec/reports
15
18
  test/tmp
16
19
  test/version_tmp
17
20
  tmp
18
21
  *.swp
22
+ .ruby-version
23
+ .ruby-gemset
24
+ vendor/bundle
data/.rubocop.yml ADDED
@@ -0,0 +1,86 @@
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
+ Lint/NestedMethodDefinition:
12
+ Enabled: false
13
+ Exclude:
14
+ - test/action_controller/serialization_test.rb
15
+
16
+ Style/StringLiterals:
17
+ EnforcedStyle: single_quotes
18
+
19
+ Metrics/AbcSize:
20
+ Max: 35 # TODO: Lower to 15
21
+
22
+ Metrics/ClassLength:
23
+ Max: 261 # TODO: Lower to 100
24
+ Exclude:
25
+ - test/**/*.rb
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 7 # TODO: Lower to 6
29
+
30
+ Metrics/LineLength:
31
+ Max: 251 # TODO: Lower to 80
32
+
33
+ Metrics/MethodLength:
34
+ Max: 106 # TODO: Lower to 10
35
+
36
+ Metrics/PerceivedComplexity:
37
+ Max: 9 # TODO: Lower to 7
38
+
39
+ Style/AlignParameters:
40
+ EnforcedStyle: with_fixed_indentation
41
+
42
+ Style/ClassAndModuleChildren:
43
+ EnforcedStyle: compact
44
+
45
+ Style/Documentation:
46
+ Enabled: false
47
+
48
+ Style/MissingElse:
49
+ Enabled: true
50
+ EnforcedStyle: case
51
+
52
+ Style/EmptyElse:
53
+ EnforcedStyle: empty
54
+
55
+ Style/MultilineOperationIndentation:
56
+ EnforcedStyle: indented
57
+
58
+ Style/BlockDelimiters:
59
+ Enabled: true
60
+ EnforcedStyle: line_count_based
61
+
62
+ ########## test_helper.rb sanity
63
+ Style/EndBlock:
64
+ Exclude:
65
+ - test/test_helper.rb
66
+
67
+ Style/SpecialGlobalVars:
68
+ Exclude:
69
+ - test/test_helper.rb
70
+
71
+ Style/GlobalVars:
72
+ Exclude:
73
+ - test/test_helper.rb
74
+
75
+ Style/AndOr:
76
+ Exclude:
77
+ - test/test_helper.rb
78
+ - 'lib/active_model/serializer/lint.rb'
79
+
80
+ Style/Not:
81
+ Exclude:
82
+ - test/test_helper.rb
83
+
84
+ Style/ClassCheck:
85
+ Exclude:
86
+ - test/test_helper.rb
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,240 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-09-20 17:56:22 -0500 using RuboCop version 0.34.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: 2
10
+ Lint/HandleExceptions:
11
+ Exclude:
12
+ - 'Rakefile'
13
+
14
+ # Offense count: 2
15
+ # Cop supports --auto-correct.
16
+ Lint/UnusedBlockArgument:
17
+ Exclude:
18
+ - 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
19
+
20
+ # Offense count: 7
21
+ # Cop supports --auto-correct.
22
+ Lint/UnusedMethodArgument:
23
+ Exclude:
24
+ - 'lib/active_model/serializer/adapter/null.rb'
25
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
26
+ - 'test/fixtures/poro.rb'
27
+ - 'test/lint_test.rb'
28
+
29
+ # Offense count: 2
30
+ Lint/UselessAssignment:
31
+ Exclude:
32
+ - 'bench/perf.rb'
33
+ - 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
34
+
35
+ # Offense count: 1
36
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
37
+ Rails/Date:
38
+ Exclude:
39
+ - 'test/fixtures/poro.rb'
40
+
41
+ # Offense count: 4
42
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
43
+ Rails/TimeZone:
44
+ Exclude:
45
+ - 'test/action_controller/serialization_test.rb'
46
+ - 'test/fixtures/poro.rb'
47
+ - 'test/serializers/cache_test.rb'
48
+
49
+ # Offense count: 16
50
+ # Cop supports --auto-correct.
51
+ # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
52
+ Style/AlignHash:
53
+ Exclude:
54
+ - 'test/action_controller/json_api/pagination_test.rb'
55
+
56
+ # Offense count: 25
57
+ # Cop supports --auto-correct.
58
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
59
+ Style/BracesAroundHashParameters:
60
+ Exclude:
61
+ - 'test/action_controller/adapter_selector_test.rb'
62
+ - 'test/action_controller/json_api/pagination_test.rb'
63
+ - 'test/adapter/json_api/linked_test.rb'
64
+ - 'test/adapter/json_api/pagination_links_test.rb'
65
+ - 'test/adapter/null_test.rb'
66
+ - 'test/adapter_test.rb'
67
+ - 'test/collection_serializer_test.rb'
68
+ - 'test/serializable_resource_test.rb'
69
+ - 'test/serializers/associations_test.rb'
70
+ - 'test/serializers/attribute_test.rb'
71
+ - 'test/serializers/attributes_test.rb'
72
+ - 'test/serializers/fieldset_test.rb'
73
+ - 'test/serializers/root_test.rb'
74
+
75
+ # Offense count: 174
76
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
77
+ Style/ClassAndModuleChildren:
78
+ Enabled: false
79
+
80
+ # Offense count: 5
81
+ # Cop supports --auto-correct.
82
+ Style/CommentIndentation:
83
+ Exclude:
84
+ - 'active_model_serializers.gemspec'
85
+
86
+ # Offense count: 1
87
+ Style/DoubleNegation:
88
+ Exclude:
89
+ - 'lib/active_model/serializable_resource.rb'
90
+
91
+ # Offense count: 1
92
+ Style/EachWithObject:
93
+ Exclude:
94
+ - 'lib/active_model/serializer/fieldset.rb'
95
+
96
+ # Offense count: 2
97
+ # Configuration parameters: MinBodyLength.
98
+ Style/GuardClause:
99
+ Exclude:
100
+ - 'lib/active_model/serializer.rb'
101
+
102
+ # Offense count: 12
103
+ # Cop supports --auto-correct.
104
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
105
+ Style/HashSyntax:
106
+ Enabled: false
107
+
108
+ # Offense count: 9
109
+ # Cop supports --auto-correct.
110
+ Style/IndentArray:
111
+ Exclude:
112
+ - 'test/adapter/json/has_many_test.rb'
113
+ - 'test/adapter/json_api/json_api_test.rb'
114
+ - 'test/adapter/json_api/pagination_links_test.rb'
115
+ - 'test/adapter/json_test.rb'
116
+
117
+ # Offense count: 8
118
+ # Cop supports --auto-correct.
119
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
120
+ Style/IndentHash:
121
+ Enabled: false
122
+
123
+ # Offense count: 1
124
+ # Cop supports --auto-correct.
125
+ Style/Lambda:
126
+ Exclude:
127
+ - 'lib/active_model/serializer.rb'
128
+
129
+ # Offense count: 1
130
+ # Cop supports --auto-correct.
131
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
132
+ Style/MethodDefParentheses:
133
+ Enabled: false
134
+
135
+ # Offense count: 3
136
+ # Cop supports --auto-correct.
137
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
138
+ Style/MultilineOperationIndentation:
139
+ Enabled: false
140
+
141
+ # Offense count: 1
142
+ # Cop supports --auto-correct.
143
+ Style/NegatedIf:
144
+ Exclude:
145
+ - 'lib/action_controller/serialization.rb'
146
+
147
+ # Offense count: 1
148
+ # Cop supports --auto-correct.
149
+ Style/NumericLiterals:
150
+ MinDigits: 7
151
+
152
+ # Offense count: 2
153
+ # Cop supports --auto-correct.
154
+ Style/PerlBackrefs:
155
+ Exclude:
156
+ - 'test/fixtures/poro.rb'
157
+ - 'test/serializers/associations_test.rb'
158
+
159
+ # Offense count: 3
160
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist.
161
+ Style/PredicateName:
162
+ Exclude:
163
+ - 'lib/active_model/serializer/associations.rb'
164
+ - 'test/action_controller/json_api/linked_test.rb'
165
+
166
+ # Offense count: 5
167
+ # Cop supports --auto-correct.
168
+ Style/RedundantSelf:
169
+ Exclude:
170
+ - 'lib/active_model/serializer/associations.rb'
171
+ - 'test/fixtures/poro.rb'
172
+
173
+ # Offense count: 1
174
+ # Cop supports --auto-correct.
175
+ # Configuration parameters: AllowAsExpressionSeparator.
176
+ Style/Semicolon:
177
+ Exclude:
178
+ - 'lib/active_model/serializer/fieldset.rb'
179
+
180
+ # Offense count: 3
181
+ # Cop supports --auto-correct.
182
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
183
+ Style/SignalException:
184
+ Exclude:
185
+ - 'lib/active_model/serializer/fieldset.rb'
186
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
187
+
188
+ # Offense count: 1
189
+ # Cop supports --auto-correct.
190
+ # Configuration parameters: AllowIfMethodIsEmpty.
191
+ Style/SingleLineMethods:
192
+ Exclude:
193
+ - 'test/serializers/serializer_for_test.rb'
194
+
195
+ # Offense count: 2
196
+ # Cop supports --auto-correct.
197
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
198
+ Style/StringLiteralsInInterpolation:
199
+ Enabled: false
200
+
201
+ # Offense count: 1
202
+ Style/StructInheritance:
203
+ Exclude:
204
+ - 'bench/perf.rb'
205
+
206
+ # Offense count: 1
207
+ # Cop supports --auto-correct.
208
+ # Configuration parameters: IgnoredMethods.
209
+ Style/SymbolProc:
210
+ Exclude:
211
+ - 'lib/generators/serializer/serializer_generator.rb'
212
+
213
+ # Offense count: 8
214
+ # Cop supports --auto-correct.
215
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
216
+ Style/TrailingBlankLines:
217
+ Exclude:
218
+ - 'lib/active_model/serializer/pass_through_serializer.rb'
219
+ - 'lib/generators/serializer/serializer_generator.rb'
220
+ - 'test/adapter/fragment_cache_test.rb'
221
+ - 'test/adapter/json_api/json_api_test.rb'
222
+ - 'test/adapter/null_test.rb'
223
+ - 'test/serializers/cache_test.rb'
224
+ - 'test/serializers/fieldset_test.rb'
225
+ - 'test/support/stream_capture.rb'
226
+
227
+ # Offense count: 5
228
+ # Cop supports --auto-correct.
229
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
230
+ Style/TrailingComma:
231
+ Exclude:
232
+ - 'test/action_controller/adapter_selector_test.rb'
233
+ - 'test/action_controller/serialization_test.rb'
234
+ - 'test/adapter/json_api/belongs_to_test.rb'
235
+ - 'test/adapter/json_api/linked_test.rb'
236
+
237
+ # Offense count: 1
238
+ Style/UnlessElse:
239
+ Exclude:
240
+ - 'lib/active_model/serializer.rb'
data/.simplecov ADDED
@@ -0,0 +1,111 @@
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
+ add_filter '/.bundle/'
45
+ end
46
+
47
+ ## START TRACKING COVERAGE (before activating SimpleCov)
48
+ require 'coverage'
49
+ Coverage.start
50
+
51
+ ## ADD SOME CUSTOM REPORTING AT EXIT
52
+ SimpleCov.at_exit do
53
+ next if $! and not ($!.kind_of? SystemExit and $!.success?)
54
+
55
+ header = "#{'*' * 20} SimpleCov Results #{'*' * 20}"
56
+ results = SimpleCov.result.format!.join("\n")
57
+ exit_message = <<-EOF
58
+
59
+ #{header}
60
+ {{RESULTS}}
61
+ {{FAILURE_MESSAGE}}
62
+
63
+ #{'*' * header.size}
64
+ EOF
65
+ percent = Float(SimpleCov.result.covered_percent)
66
+ if percent < @minimum_coverage
67
+ failure_message = <<-EOF
68
+ Spec coverage was not high enough: #{percent.round(2)}% is < #{@minimum_coverage}%
69
+ EOF
70
+ exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', failure_message)
71
+ @output.puts exit_message
72
+ abort(failure_message) if @generate_report
73
+ elsif @running_ci
74
+ exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', <<-EOF)
75
+ Nice job! Spec coverage (#{percent.round(2)}%) is still at or above #{@minimum_coverage}%
76
+ EOF
77
+ @output.puts exit_message
78
+ end
79
+ end
80
+
81
+ ## CAPTURE CONFIG IN CLOSURE 'AppCoverage.start'
82
+ ## to defer running until test/test_helper.rb is loaded.
83
+ # rubocop:disable Style/MultilineBlockChain
84
+ AppCoverage = Class.new do
85
+ def initialize(&block)
86
+ @block = block
87
+ end
88
+
89
+ def start
90
+ @block.call
91
+ end
92
+ end.new do
93
+ SimpleCov.start 'app'
94
+ if @generate_report
95
+ if @running_ci
96
+ require 'codeclimate-test-reporter'
97
+ @output.puts '[COVERAGE] Running with SimpleCov Simple Formatter and CodeClimate Test Reporter'
98
+ formatters = [
99
+ SimpleCov::Formatter::SimpleFormatter,
100
+ CodeClimate::TestReporter::Formatter
101
+ ]
102
+ else
103
+ @output.puts '[COVERAGE] Running with SimpleCov HTML Formatter'
104
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
105
+ end
106
+ else
107
+ formatters = []
108
+ end
109
+ SimpleCov.formatters = formatters
110
+ end
111
+ # rubocop:enable Style/MultilineBlockChain
data/.travis.yml CHANGED
@@ -1,28 +1,39 @@
1
1
  language: ruby
2
+
3
+ sudo: false
4
+
2
5
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
6
  - 2.0.0
7
- - ree
8
- - jruby-18mode
9
- - jruby-19mode
7
+ - 2.1
8
+ - 2.2.3
9
+ - 2.3.0
10
+ - ruby-head
10
11
  - rbx-2
11
- gemfile:
12
- - Gemfile
13
- - Gemfile.edge
12
+
13
+ install: bundle install --path=vendor/bundle --retry=3 --jobs=3
14
+ cache:
15
+ directories:
16
+ - vendor/bundle
17
+
18
+ script:
19
+ - bundle exec rake ci
20
+
21
+ env:
22
+ - "RAILS_VERSION=4.0"
23
+ - "RAILS_VERSION=4.1"
24
+ - "RAILS_VERSION=4.2"
25
+ - "RAILS_VERSION=master"
26
+
14
27
  matrix:
15
- allow_failures:
16
- - gemfile: Gemfile.edge
17
28
  exclude:
18
- # Edge Rails is only compatible with 1.9.3
19
- - gemfile: Gemfile.edge
20
- rvm: 1.8.7
21
- - gemfile: Gemfile.edge
22
- rvm: 1.9.2
23
- - gemfile: Gemfile.edge
24
- rvm: ree
25
- - gemfile: Gemfile.edge
26
- rvm: jruby-18mode
27
- - gemfile: Gemfile.edge
28
- rvm: rbx-18mode
29
+ - rvm: 2.0.0
30
+ env: RAILS_VERSION=master
31
+ - rvm: 2.1
32
+ env: RAILS_VERSION=master
33
+ include:
34
+ - rvm: jruby-9.0.4.0
35
+ env: JRUBY_OPTS='-Xcompat.version=2.0 --server -Xcompile.invokedynamic=false -Xcli.debug=true --debug'
36
+ allow_failures:
37
+ - rvm: ruby-head
38
+ - rvm: rbx-2
39
+ fast_finish: true