active_model_serializers 0.10.0 → 0.10.13

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 (215) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +239 -2
  3. data/README.md +171 -34
  4. data/lib/action_controller/serialization.rb +23 -3
  5. data/lib/active_model/serializable_resource.rb +2 -0
  6. data/lib/active_model/serializer/adapter/attributes.rb +2 -0
  7. data/lib/active_model/serializer/adapter/base.rb +4 -0
  8. data/lib/active_model/serializer/adapter/json.rb +2 -0
  9. data/lib/active_model/serializer/adapter/json_api.rb +2 -0
  10. data/lib/active_model/serializer/adapter/null.rb +2 -0
  11. data/lib/active_model/serializer/adapter.rb +2 -0
  12. data/lib/active_model/serializer/array_serializer.rb +10 -5
  13. data/lib/active_model/serializer/association.rb +64 -10
  14. data/lib/active_model/serializer/attribute.rb +2 -0
  15. data/lib/active_model/serializer/belongs_to_reflection.rb +6 -3
  16. data/lib/active_model/serializer/collection_serializer.rb +48 -13
  17. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +89 -117
  18. data/lib/active_model/serializer/error_serializer.rb +13 -7
  19. data/lib/active_model/serializer/errors_serializer.rb +27 -20
  20. data/lib/active_model/serializer/field.rb +2 -0
  21. data/lib/active_model/serializer/fieldset.rb +3 -1
  22. data/lib/active_model/serializer/has_many_reflection.rb +5 -3
  23. data/lib/active_model/serializer/has_one_reflection.rb +3 -4
  24. data/lib/active_model/serializer/lazy_association.rb +99 -0
  25. data/lib/active_model/serializer/link.rb +23 -0
  26. data/lib/active_model/serializer/lint.rb +136 -130
  27. data/lib/active_model/serializer/null.rb +2 -0
  28. data/lib/active_model/serializer/reflection.rb +130 -65
  29. data/lib/active_model/serializer/version.rb +3 -1
  30. data/lib/active_model/serializer.rb +321 -86
  31. data/lib/active_model_serializers/adapter/attributes.rb +17 -57
  32. data/lib/active_model_serializers/adapter/base.rb +41 -39
  33. data/lib/active_model_serializers/adapter/json.rb +2 -0
  34. data/lib/active_model_serializers/adapter/json_api/deserialization.rb +4 -2
  35. data/lib/active_model_serializers/adapter/json_api/error.rb +2 -0
  36. data/lib/active_model_serializers/adapter/json_api/jsonapi.rb +2 -0
  37. data/lib/active_model_serializers/adapter/json_api/link.rb +3 -1
  38. data/lib/active_model_serializers/adapter/json_api/meta.rb +2 -0
  39. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +52 -20
  40. data/lib/active_model_serializers/adapter/json_api/relationship.rb +77 -23
  41. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +41 -10
  42. data/lib/active_model_serializers/adapter/json_api.rb +84 -65
  43. data/lib/active_model_serializers/adapter/null.rb +2 -0
  44. data/lib/active_model_serializers/adapter.rb +9 -1
  45. data/lib/active_model_serializers/callbacks.rb +2 -0
  46. data/lib/active_model_serializers/deprecate.rb +3 -2
  47. data/lib/active_model_serializers/deserialization.rb +4 -0
  48. data/lib/active_model_serializers/json_pointer.rb +2 -0
  49. data/lib/active_model_serializers/logging.rb +2 -0
  50. data/lib/active_model_serializers/lookup_chain.rb +82 -0
  51. data/lib/active_model_serializers/model/caching.rb +26 -0
  52. data/lib/active_model_serializers/model.rb +111 -28
  53. data/lib/active_model_serializers/railtie.rb +7 -1
  54. data/lib/active_model_serializers/register_jsonapi_renderer.rb +46 -31
  55. data/lib/active_model_serializers/serializable_resource.rb +10 -7
  56. data/lib/active_model_serializers/serialization_context.rb +12 -3
  57. data/lib/active_model_serializers/test/schema.rb +4 -2
  58. data/lib/active_model_serializers/test/serializer.rb +2 -0
  59. data/lib/active_model_serializers/test.rb +2 -0
  60. data/lib/active_model_serializers.rb +35 -10
  61. data/lib/generators/rails/resource_override.rb +3 -1
  62. data/lib/generators/rails/serializer_generator.rb +6 -4
  63. data/lib/grape/active_model_serializers.rb +9 -5
  64. data/lib/grape/formatters/active_model_serializers.rb +21 -2
  65. data/lib/grape/helpers/active_model_serializers.rb +3 -0
  66. data/lib/tasks/rubocop.rake +55 -0
  67. metadata +104 -296
  68. data/.github/ISSUE_TEMPLATE.md +0 -29
  69. data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
  70. data/.gitignore +0 -35
  71. data/.rubocop.yml +0 -104
  72. data/.rubocop_todo.yml +0 -167
  73. data/.simplecov +0 -110
  74. data/.travis.yml +0 -43
  75. data/CONTRIBUTING.md +0 -105
  76. data/Gemfile +0 -53
  77. data/Rakefile +0 -103
  78. data/active_model_serializers.gemspec +0 -66
  79. data/appveyor.yml +0 -24
  80. data/bin/bench +0 -171
  81. data/bin/bench_regression +0 -316
  82. data/bin/serve_benchmark +0 -39
  83. data/docs/ARCHITECTURE.md +0 -126
  84. data/docs/README.md +0 -40
  85. data/docs/STYLE.md +0 -58
  86. data/docs/general/adapters.md +0 -245
  87. data/docs/general/caching.md +0 -52
  88. data/docs/general/configuration_options.md +0 -100
  89. data/docs/general/deserialization.md +0 -100
  90. data/docs/general/getting_started.md +0 -133
  91. data/docs/general/instrumentation.md +0 -40
  92. data/docs/general/key_transforms.md +0 -40
  93. data/docs/general/logging.md +0 -14
  94. data/docs/general/rendering.md +0 -255
  95. data/docs/general/serializers.md +0 -372
  96. data/docs/how-open-source-maintained.jpg +0 -0
  97. data/docs/howto/add_pagination_links.md +0 -139
  98. data/docs/howto/add_root_key.md +0 -51
  99. data/docs/howto/outside_controller_use.md +0 -58
  100. data/docs/howto/passing_arbitrary_options.md +0 -27
  101. data/docs/howto/serialize_poro.md +0 -32
  102. data/docs/howto/test.md +0 -152
  103. data/docs/integrations/ember-and-json-api.md +0 -112
  104. data/docs/integrations/grape.md +0 -19
  105. data/docs/jsonapi/errors.md +0 -56
  106. data/docs/jsonapi/schema/schema.json +0 -366
  107. data/docs/jsonapi/schema.md +0 -151
  108. data/docs/rfcs/0000-namespace.md +0 -106
  109. data/docs/rfcs/template.md +0 -15
  110. data/lib/active_model/serializer/associations.rb +0 -100
  111. data/lib/active_model/serializer/attributes.rb +0 -82
  112. data/lib/active_model/serializer/collection_reflection.rb +0 -7
  113. data/lib/active_model/serializer/configuration.rb +0 -35
  114. data/lib/active_model/serializer/include_tree.rb +0 -111
  115. data/lib/active_model/serializer/links.rb +0 -35
  116. data/lib/active_model/serializer/meta.rb +0 -29
  117. data/lib/active_model/serializer/singular_reflection.rb +0 -7
  118. data/lib/active_model/serializer/type.rb +0 -25
  119. data/lib/active_model_serializers/key_transform.rb +0 -70
  120. data/test/action_controller/adapter_selector_test.rb +0 -53
  121. data/test/action_controller/explicit_serializer_test.rb +0 -134
  122. data/test/action_controller/json/include_test.rb +0 -167
  123. data/test/action_controller/json_api/deserialization_test.rb +0 -112
  124. data/test/action_controller/json_api/errors_test.rb +0 -41
  125. data/test/action_controller/json_api/linked_test.rb +0 -197
  126. data/test/action_controller/json_api/pagination_test.rb +0 -116
  127. data/test/action_controller/json_api/transform_test.rb +0 -181
  128. data/test/action_controller/serialization_scope_name_test.rb +0 -229
  129. data/test/action_controller/serialization_test.rb +0 -469
  130. data/test/active_model_serializers/adapter_for_test.rb +0 -208
  131. data/test/active_model_serializers/json_pointer_test.rb +0 -20
  132. data/test/active_model_serializers/key_transform_test.rb +0 -263
  133. data/test/active_model_serializers/logging_test.rb +0 -77
  134. data/test/active_model_serializers/model_test.rb +0 -9
  135. data/test/active_model_serializers/railtie_test_isolated.rb +0 -63
  136. data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -58
  137. data/test/active_model_serializers/test/schema_test.rb +0 -130
  138. data/test/active_model_serializers/test/serializer_test.rb +0 -62
  139. data/test/active_record_test.rb +0 -9
  140. data/test/adapter/deprecation_test.rb +0 -100
  141. data/test/adapter/json/belongs_to_test.rb +0 -45
  142. data/test/adapter/json/collection_test.rb +0 -90
  143. data/test/adapter/json/has_many_test.rb +0 -45
  144. data/test/adapter/json/transform_test.rb +0 -93
  145. data/test/adapter/json_api/belongs_to_test.rb +0 -155
  146. data/test/adapter/json_api/collection_test.rb +0 -95
  147. data/test/adapter/json_api/errors_test.rb +0 -78
  148. data/test/adapter/json_api/fields_test.rb +0 -87
  149. data/test/adapter/json_api/has_many_embed_ids_test.rb +0 -43
  150. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -96
  151. data/test/adapter/json_api/has_many_test.rb +0 -144
  152. data/test/adapter/json_api/has_one_test.rb +0 -80
  153. data/test/adapter/json_api/json_api_test.rb +0 -35
  154. data/test/adapter/json_api/linked_test.rb +0 -392
  155. data/test/adapter/json_api/links_test.rb +0 -93
  156. data/test/adapter/json_api/pagination_links_test.rb +0 -166
  157. data/test/adapter/json_api/parse_test.rb +0 -137
  158. data/test/adapter/json_api/relationship_test.rb +0 -161
  159. data/test/adapter/json_api/relationships_test.rb +0 -199
  160. data/test/adapter/json_api/resource_identifier_test.rb +0 -85
  161. data/test/adapter/json_api/resource_meta_test.rb +0 -100
  162. data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -82
  163. data/test/adapter/json_api/transform_test.rb +0 -502
  164. data/test/adapter/json_api/type_test.rb +0 -61
  165. data/test/adapter/json_test.rb +0 -45
  166. data/test/adapter/null_test.rb +0 -23
  167. data/test/adapter/polymorphic_test.rb +0 -171
  168. data/test/adapter_test.rb +0 -67
  169. data/test/array_serializer_test.rb +0 -22
  170. data/test/benchmark/app.rb +0 -65
  171. data/test/benchmark/benchmarking_support.rb +0 -67
  172. data/test/benchmark/bm_caching.rb +0 -119
  173. data/test/benchmark/bm_transform.rb +0 -34
  174. data/test/benchmark/config.ru +0 -3
  175. data/test/benchmark/controllers.rb +0 -84
  176. data/test/benchmark/fixtures.rb +0 -219
  177. data/test/cache_test.rb +0 -485
  178. data/test/collection_serializer_test.rb +0 -110
  179. data/test/fixtures/active_record.rb +0 -78
  180. data/test/fixtures/poro.rb +0 -282
  181. data/test/generators/scaffold_controller_generator_test.rb +0 -24
  182. data/test/generators/serializer_generator_test.rb +0 -57
  183. data/test/grape_test.rb +0 -82
  184. data/test/include_tree/from_include_args_test.rb +0 -26
  185. data/test/include_tree/from_string_test.rb +0 -94
  186. data/test/include_tree/include_args_to_hash_test.rb +0 -64
  187. data/test/lint_test.rb +0 -49
  188. data/test/logger_test.rb +0 -18
  189. data/test/poro_test.rb +0 -9
  190. data/test/serializable_resource_test.rb +0 -83
  191. data/test/serializers/association_macros_test.rb +0 -36
  192. data/test/serializers/associations_test.rb +0 -295
  193. data/test/serializers/attribute_test.rb +0 -151
  194. data/test/serializers/attributes_test.rb +0 -52
  195. data/test/serializers/caching_configuration_test_isolated.rb +0 -170
  196. data/test/serializers/configuration_test.rb +0 -32
  197. data/test/serializers/fieldset_test.rb +0 -14
  198. data/test/serializers/meta_test.rb +0 -196
  199. data/test/serializers/options_test.rb +0 -21
  200. data/test/serializers/read_attribute_for_serialization_test.rb +0 -79
  201. data/test/serializers/root_test.rb +0 -21
  202. data/test/serializers/serialization_test.rb +0 -55
  203. data/test/serializers/serializer_for_test.rb +0 -134
  204. data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  205. data/test/support/isolated_unit.rb +0 -79
  206. data/test/support/rails5_shims.rb +0 -47
  207. data/test/support/rails_app.rb +0 -45
  208. data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  209. data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
  210. data/test/support/schemas/custom/show.json +0 -7
  211. data/test/support/schemas/hyper_schema.json +0 -93
  212. data/test/support/schemas/render_using_json_api.json +0 -43
  213. data/test/support/schemas/simple_json_pointers.json +0 -10
  214. data/test/support/serialization_testing.rb +0 -53
  215. data/test/test_helper.rb +0 -57
data/.rubocop.yml DELETED
@@ -1,104 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- AllCops:
4
- TargetRubyVersion: 2.2
5
- Exclude:
6
- - config/initializers/forbidden_yaml.rb
7
- - !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
8
- DisplayCopNames: true
9
- DisplayStyleGuide: true
10
-
11
- Rails:
12
- Enabled: true
13
-
14
- Lint/NestedMethodDefinition:
15
- Enabled: false
16
- Exclude:
17
- - test/action_controller/serialization_test.rb
18
-
19
- Style/Alias:
20
- EnforcedStyle: prefer_alias
21
-
22
- Style/StringLiterals:
23
- EnforcedStyle: single_quotes
24
-
25
- Metrics/AbcSize:
26
- Max: 35 # TODO: Lower to 15
27
-
28
- Metrics/ClassLength:
29
- Max: 261 # TODO: Lower to 100
30
- Exclude:
31
- - test/**/*.rb
32
-
33
- Metrics/CyclomaticComplexity:
34
- Max: 7 # TODO: Lower to 6
35
-
36
- Metrics/LineLength:
37
- Max: 251 # TODO: Lower to 80
38
-
39
- Metrics/MethodLength:
40
- Max: 106 # TODO: Lower to 10
41
-
42
- Metrics/PerceivedComplexity:
43
- Max: 9 # TODO: Lower to 7
44
-
45
- Style/AlignParameters:
46
- EnforcedStyle: with_fixed_indentation
47
-
48
- Style/ClassAndModuleChildren:
49
- EnforcedStyle: compact
50
-
51
- Style/Documentation:
52
- Enabled: false
53
-
54
- Style/MissingElse:
55
- Enabled: true
56
- EnforcedStyle: case
57
-
58
- Style/EmptyElse:
59
- EnforcedStyle: empty
60
-
61
- Style/MultilineOperationIndentation:
62
- EnforcedStyle: indented
63
-
64
- Style/BlockDelimiters:
65
- Enabled: true
66
- EnforcedStyle: line_count_based
67
-
68
- Style/SignalException:
69
- EnforcedStyle: semantic
70
-
71
- Style/TrailingCommaInLiteral:
72
- EnforcedStyleForMultiline: no_comma
73
-
74
- Style/ConditionalAssignment:
75
- Enabled: false
76
-
77
- Style/DotPosition:
78
- EnforcedStyle: leading
79
-
80
- ########## test_helper.rb sanity
81
- Style/EndBlock:
82
- Exclude:
83
- - test/test_helper.rb
84
-
85
- Style/SpecialGlobalVars:
86
- Exclude:
87
- - test/test_helper.rb
88
-
89
- Style/GlobalVars:
90
- Exclude:
91
- - test/test_helper.rb
92
-
93
- Style/AndOr:
94
- Exclude:
95
- - test/test_helper.rb
96
- - 'lib/active_model/serializer/lint.rb'
97
-
98
- Style/Not:
99
- Exclude:
100
- - test/test_helper.rb
101
-
102
- Style/ClassCheck:
103
- Exclude:
104
- - test/test_helper.rb
data/.rubocop_todo.yml DELETED
@@ -1,167 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2016-03-08 22:29:52 +0100 using RuboCop version 0.37.2.
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
- # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
17
- Lint/UnusedMethodArgument:
18
- Exclude:
19
- - 'test/lint_test.rb'
20
-
21
- # Offense count: 4
22
- # Configuration parameters: EnforcedStyle, SupportedStyles.
23
- # SupportedStyles: strict, flexible
24
- Rails/TimeZone:
25
- Exclude:
26
- - 'test/action_controller/serialization_test.rb'
27
- - 'test/serializers/cache_test.rb'
28
-
29
- # Offense count: 16
30
- # Cop supports --auto-correct.
31
- # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
32
- # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
33
- Style/AlignHash:
34
- Exclude:
35
- - 'test/action_controller/json_api/pagination_test.rb'
36
-
37
- # Offense count: 27
38
- # Cop supports --auto-correct.
39
- # Configuration parameters: EnforcedStyle, SupportedStyles.
40
- # SupportedStyles: braces, no_braces, context_dependent
41
- Style/BracesAroundHashParameters:
42
- Exclude:
43
- - 'test/action_controller/adapter_selector_test.rb'
44
- - 'test/action_controller/json_api/pagination_test.rb'
45
- - 'test/adapter/json_api/linked_test.rb'
46
- - 'test/adapter/json_api/pagination_links_test.rb'
47
- - 'test/adapter/null_test.rb'
48
- - 'test/adapter_test.rb'
49
- - 'test/collection_serializer_test.rb'
50
- - 'test/serializable_resource_test.rb'
51
- - 'test/serializers/associations_test.rb'
52
- - 'test/serializers/attributes_test.rb'
53
- - 'test/serializers/root_test.rb'
54
-
55
- # Offense count: 271
56
- # Configuration parameters: EnforcedStyle, SupportedStyles.
57
- # SupportedStyles: nested, compact
58
- Style/ClassAndModuleChildren:
59
- Enabled: false
60
-
61
- # Offense count: 6
62
- # Cop supports --auto-correct.
63
- Style/CommentIndentation:
64
- Exclude:
65
- - 'active_model_serializers.gemspec'
66
-
67
- # Offense count: 1
68
- Style/DoubleNegation:
69
- Exclude:
70
- - 'lib/active_model/serializable_resource.rb'
71
-
72
- # Offense count: 1
73
- # Configuration parameters: MinBodyLength.
74
- Style/GuardClause:
75
- Exclude:
76
- - 'lib/active_model/serializer.rb'
77
-
78
- # Offense count: 58
79
- # Cop supports --auto-correct.
80
- # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
81
- # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
82
- Style/HashSyntax:
83
- Enabled: false
84
-
85
- # Offense count: 4
86
- # Cop supports --auto-correct.
87
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
88
- # SupportedStyles: special_inside_parentheses, consistent, align_brackets
89
- Style/IndentArray:
90
- Enabled: false
91
-
92
- # Offense count: 10
93
- # Cop supports --auto-correct.
94
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
95
- # SupportedStyles: special_inside_parentheses, consistent, align_braces
96
- Style/IndentHash:
97
- Enabled: false
98
-
99
- # Offense count: 1
100
- # Cop supports --auto-correct.
101
- Style/Lambda:
102
- Exclude:
103
- - 'lib/active_model/serializer.rb'
104
-
105
- # Offense count: 1
106
- # Cop supports --auto-correct.
107
- # Configuration parameters: EnforcedStyle, SupportedStyles.
108
- # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
109
- Style/MethodDefParentheses:
110
- Enabled: false
111
-
112
- # Offense count: 1
113
- # Cop supports --auto-correct.
114
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
115
- # SupportedStyles: aligned, indented
116
- Style/MultilineOperationIndentation:
117
- Enabled: false
118
-
119
- # Offense count: 1
120
- # Cop supports --auto-correct.
121
- Style/NegatedIf:
122
- Exclude:
123
- - 'lib/action_controller/serialization.rb'
124
-
125
- # Offense count: 1
126
- # Cop supports --auto-correct.
127
- Style/PerlBackrefs:
128
- Exclude:
129
- - 'test/fixtures/poro.rb'
130
-
131
- # Offense count: 3
132
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
133
- # NamePrefix: is_, has_, have_
134
- # NamePrefixBlacklist: is_, has_, have_
135
- # NameWhitelist: is_a?
136
- Style/PredicateName:
137
- Exclude:
138
- - 'lib/active_model/serializer/associations.rb'
139
- - 'test/action_controller/json_api/linked_test.rb'
140
-
141
- # Offense count: 1
142
- # Cop supports --auto-correct.
143
- Style/RedundantSelf:
144
- Exclude:
145
- - 'test/fixtures/poro.rb'
146
-
147
- # Offense count: 1
148
- # Cop supports --auto-correct.
149
- # Configuration parameters: AllowIfMethodIsEmpty.
150
- Style/SingleLineMethods:
151
- Exclude:
152
- - 'test/serializers/serializer_for_test.rb'
153
-
154
- # Offense count: 4
155
- # Cop supports --auto-correct.
156
- # Configuration parameters: EnforcedStyle, SupportedStyles.
157
- # SupportedStyles: single_quotes, double_quotes
158
- Style/StringLiteralsInInterpolation:
159
- Enabled: false
160
-
161
- # Offense count: 1
162
- # Cop supports --auto-correct.
163
- # Configuration parameters: EnforcedStyle, SupportedStyles.
164
- # SupportedStyles: final_newline, final_blank_line
165
- Style/TrailingBlankLines:
166
- Exclude:
167
- - 'test/adapter/null_test.rb'
data/.simplecov DELETED
@@ -1,110 +0,0 @@
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
-
23
- SimpleCov.profiles.define 'app' do
24
- coverage_dir 'coverage'
25
- load_profile 'test_frameworks'
26
-
27
- add_group 'Libraries', 'lib'
28
-
29
- add_group 'Long files' do |src_file|
30
- src_file.lines.count > 100
31
- end
32
- class MaxLinesFilter < SimpleCov::Filter
33
- def matches?(source_file)
34
- source_file.lines.count < filter_argument
35
- end
36
- end
37
- add_group 'Short files', MaxLinesFilter.new(5)
38
-
39
- # Exclude these paths from analysis
40
- add_filter '/config/'
41
- add_filter '/db/'
42
- add_filter 'tasks'
43
- add_filter '/.bundle/'
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
- next if $! and not ($!.kind_of? SystemExit and $!.success?)
53
-
54
- header = "#{'*' * 20} SimpleCov Results #{'*' * 20}"
55
- results = SimpleCov.result.format!.join("\n")
56
- exit_message = <<-EOF
57
-
58
- #{header}
59
- {{RESULTS}}
60
- {{FAILURE_MESSAGE}}
61
-
62
- #{'*' * header.size}
63
- EOF
64
- percent = Float(SimpleCov.result.covered_percent)
65
- if percent < @minimum_coverage
66
- failure_message = <<-EOF
67
- Spec coverage was not high enough: #{percent.round(2)}% is < #{@minimum_coverage}%
68
- EOF
69
- exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', failure_message)
70
- @output.puts exit_message
71
- abort(failure_message) if @generate_report
72
- elsif @running_ci
73
- exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', <<-EOF)
74
- Nice job! Spec coverage (#{percent.round(2)}%) is still at or above #{@minimum_coverage}%
75
- EOF
76
- @output.puts exit_message
77
- end
78
- end
79
-
80
- ## CAPTURE CONFIG IN CLOSURE 'AppCoverage.start'
81
- ## to defer running until test/test_helper.rb is loaded.
82
- # rubocop:disable Style/MultilineBlockChain
83
- AppCoverage = Class.new do
84
- def initialize(&block)
85
- @block = block
86
- end
87
-
88
- def start
89
- @block.call
90
- end
91
- end.new do
92
- SimpleCov.start 'app'
93
- if @generate_report
94
- if @running_ci
95
- require 'codeclimate-test-reporter'
96
- @output.puts '[COVERAGE] Running with SimpleCov Simple Formatter and CodeClimate Test Reporter'
97
- formatters = [
98
- SimpleCov::Formatter::SimpleFormatter,
99
- CodeClimate::TestReporter::Formatter
100
- ]
101
- else
102
- @output.puts '[COVERAGE] Running with SimpleCov HTML Formatter'
103
- formatters = [SimpleCov::Formatter::HTMLFormatter]
104
- end
105
- else
106
- formatters = []
107
- end
108
- SimpleCov.formatters = formatters
109
- end
110
- # rubocop:enable Style/MultilineBlockChain
data/.travis.yml DELETED
@@ -1,43 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- rvm:
6
- - 2.1
7
- - 2.2.3
8
- - 2.3.0
9
- - ruby-head
10
- - jruby-9.0.4.0
11
- - jruby-head
12
-
13
- jdk:
14
- - oraclejdk8
15
-
16
- install: bundle install --path=vendor/bundle --retry=3 --jobs=3
17
- cache:
18
- directories:
19
- - vendor/bundle
20
-
21
- script:
22
- - bundle exec rake ci
23
-
24
- env:
25
- global:
26
- - "JRUBY_OPTS='--dev -J-Xmx1024M --debug'"
27
- matrix:
28
- - "RAILS_VERSION=4.1"
29
- - "RAILS_VERSION=4.2"
30
- - "RAILS_VERSION=master"
31
-
32
- matrix:
33
- exclude:
34
- - rvm: 2.1
35
- env: RAILS_VERSION=master
36
- - rvm: jruby-9.0.4.0
37
- env: RAILS_VERSION=master
38
- - rvm: jruby-head
39
- env: RAILS_VERSION=master
40
- allow_failures:
41
- - rvm: ruby-head
42
- - rvm: jruby-head
43
- fast_finish: true
data/CONTRIBUTING.md DELETED
@@ -1,105 +0,0 @@
1
- ## Have an issue?
2
-
3
- Before opening an issue, try the following:
4
-
5
- ##### Consult the documentation
6
-
7
- See if your issue can be resolved by information in the documentation.
8
-
9
- - [0.10 (master) Documentation](https://github.com/rails-api/active_model_serializers/tree/master/docs)
10
- - [![API Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/rails-api/active_model_serializers/v0.10.0)
11
- - [Guides](docs)
12
- - [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
13
- - [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
14
-
15
- ##### Check for an existing issue
16
-
17
- Take a look at the issues to see if a similar one has already been created. If
18
- one exists, please add any additional information that might expedite
19
- resolution.
20
-
21
- #### Open an issue
22
-
23
- If the documentation wasn't able to help resolve the issue and no issue already
24
- exists, please open a new issue with the following in mind:
25
-
26
- - Please make sure only to include one issue per report. If you encounter
27
- multiple, unrelated issues, please report them as such.
28
- - Be detailed. Provide backtraces and example code when possible. Provide
29
- information about your environment. e.g., Ruby version, rails version, etc.
30
- - Own your issue. Actively participate in the discussion and help drive the
31
- issue to closure.
32
- - If you resolve your own issue, please share the details on the issue and close
33
- it out. Others might have the same issue and sharing solutions is helpful.
34
-
35
- ## Contributing
36
-
37
- Contributing can be done in many ways and is not exclusive to code. If you have
38
- thoughts on a particular issue or feature, we encourage you to open new issues
39
- for discussion or add your comments to existing ones.
40
-
41
- #### Pull requests
42
-
43
- We also gladly welcome pull requests. When preparing to work on pull request,
44
- please adhere to these standards:
45
-
46
- - Base work on the master branch unless fixing an issue with
47
- [0.9-stable](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
48
- or
49
- [0.8-stable](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
50
- - Squash your commits and regularly rebase off master.
51
- - Provide a description of the changes contained in the pull request.
52
- - Note any specific areas that should be reviewed.
53
- - Include tests.
54
- - The test suite must pass on [supported Ruby versions](.travis.yml)
55
- - Include updates to the [documentation](https://github.com/rails-api/active_model_serializers/tree/master/docs)
56
- where applicable.
57
- - Update the
58
- [CHANGELOG](https://github.com/rails-api/active_model_serializers/blob/master/CHANGELOG.md)
59
- to the appropriate sections with a brief description of the changes.
60
- - Do not change the VERSION file.
61
-
62
- #### Running tests
63
-
64
- Run all tests
65
-
66
- `$ rake test`
67
-
68
- Run a single test suite
69
-
70
- `$ rake test TEST=path/to/test.rb`
71
-
72
- Run a single test
73
-
74
- `$ rake test TEST=path/to/test.rb TESTOPTS="--name=test_something"`
75
-
76
- Run tests against different Rails versions by setting the RAILS_VERSION variable
77
- and bundling gems. (save this script somewhere executable and run from top of AMS repository)
78
-
79
- ```bash
80
- #!/usr/bin/env bash
81
-
82
- rcommand='puts YAML.load_file("./.travis.yml")["env"]["matrix"].join(" ").gsub("RAILS_VERSION=", "")'
83
- versions=$(ruby -ryaml -e "$rcommand")
84
-
85
- for version in ${versions[@]}; do
86
- export RAILS_VERSION="$version"
87
- rm -f Gemfile.lock
88
- bundle check || bundle --local || bundle
89
- bundle exec rake test
90
- if [ "$?" -eq 0 ]; then
91
- # green in ANSI
92
- echo -e "\033[32m **** Tests passed against Rails ${RAILS_VERSION} **** \033[0m"
93
- else
94
- # red in ANSI
95
- echo -e "\033[31m **** Tests failed against Rails ${RAILS_VERSION} **** \033[0m"
96
- read -p '[Enter] any key to continue, [q] to quit...' prompt
97
- if [ "$prompt" = 'q' ]; then
98
- unset RAILS_VERSION
99
- exit 1
100
- fi
101
- fi
102
- unset RAILS_VERSION
103
- done
104
- ```
105
-
data/Gemfile DELETED
@@ -1,53 +0,0 @@
1
- source 'https://rubygems.org'
2
- #
3
- # Add a Gemfile.local to locally bundle gems outside of version control
4
- local_gemfile = File.join(File.expand_path('..', __FILE__), 'Gemfile.local')
5
- eval_gemfile local_gemfile if File.readable?(local_gemfile)
6
-
7
- # Specify your gem's dependencies in active_model_serializers.gemspec
8
- gemspec
9
-
10
- version = ENV['RAILS_VERSION'] || '4.2'
11
-
12
- if version == 'master'
13
- gem 'rack', github: 'rack/rack'
14
- gem 'arel', github: 'rails/arel'
15
- git 'https://github.com/rails/rails.git' do
16
- gem 'railties'
17
- gem 'activesupport'
18
- gem 'activemodel'
19
- gem 'actionpack'
20
- gem 'activerecord', group: :test
21
- # Rails 5
22
- gem 'actionview'
23
- end
24
- else
25
- gem_version = "~> #{version}.0"
26
- gem 'railties', gem_version
27
- gem 'activesupport', gem_version
28
- gem 'activemodel', gem_version
29
- gem 'actionpack', gem_version
30
- gem 'activerecord', gem_version, group: :test
31
- end
32
-
33
- # https://github.com/bundler/bundler/blob/89a8778c19269561926cea172acdcda241d26d23/lib/bundler/dependency.rb#L30-L54
34
- @windows_platforms = [:mswin, :mingw, :x64_mingw]
35
-
36
- # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
37
- gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
38
-
39
- group :bench do
40
- # https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76
41
- gem 'benchmark-ips', require: false, group: :development
42
- end
43
-
44
- group :test do
45
- gem 'sqlite3', platform: (@windows_platforms + [:ruby])
46
- gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
47
- gem 'codeclimate-test-reporter', require: false
48
- end
49
-
50
- group :development, :test do
51
- gem 'rubocop', '~> 0.39.0', require: false
52
- gem 'yard', require: false
53
- end
data/Rakefile DELETED
@@ -1,103 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
- begin
7
- require 'simplecov'
8
- rescue LoadError
9
- end
10
-
11
- Bundler::GemHelper.install_tasks
12
-
13
- require 'yard'
14
-
15
- namespace :yard do
16
- YARD::Rake::YardocTask.new(:doc) do |t|
17
- t.stats_options = ['--list-undoc']
18
- end
19
-
20
- desc 'start a gem server'
21
- task :server do
22
- sh 'bundle exec yard server --gems'
23
- end
24
-
25
- desc 'use Graphviz to generate dot graph'
26
- task :graph do
27
- output_file = 'doc/erd.dot'
28
- sh "bundle exec yard graph --protected --full --dependencies > #{output_file}"
29
- puts 'open doc/erd.dot if you have graphviz installed'
30
- end
31
- end
32
-
33
- begin
34
- require 'rubocop'
35
- require 'rubocop/rake_task'
36
- rescue LoadError
37
- else
38
- Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
39
- require 'rbconfig'
40
- # https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
41
- windows_platforms = /(msdos|mswin|djgpp|mingw)/
42
- if RbConfig::CONFIG['host_os'] =~ windows_platforms
43
- desc 'No-op rubocop on Windows-- unsupported platform'
44
- task :rubocop do
45
- puts 'Skipping rubocop on Windows'
46
- end
47
- elsif defined?(::Rubinius)
48
- desc 'No-op rubocop to avoid rbx segfault'
49
- task :rubocop do
50
- puts 'Skipping rubocop on rbx due to segfault'
51
- puts 'https://github.com/rubinius/rubinius/issues/3499'
52
- end
53
- else
54
- Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
55
- desc 'Execute rubocop'
56
- RuboCop::RakeTask.new(:rubocop) do |task|
57
- task.options = ['--rails', '--display-cop-names', '--display-style-guide']
58
- task.fail_on_error = true
59
- end
60
- end
61
- end
62
-
63
- require 'rake/testtask'
64
-
65
- Rake::TestTask.new(:test) do |t|
66
- t.libs << 'lib'
67
- t.libs << 'test'
68
- t.pattern = 'test/**/*_test.rb'
69
- t.ruby_opts = ['-r./test/test_helper.rb']
70
- t.ruby_opts << ' -w' unless ENV['NO_WARN'] == 'true'
71
- t.verbose = true
72
- end
73
-
74
- desc 'Run isolated tests'
75
- task isolated: ['test:isolated']
76
- namespace :test do
77
- task :isolated do
78
- desc 'Run isolated tests for Railtie'
79
- require 'shellwords'
80
- dir = File.dirname(__FILE__)
81
- dir = Shellwords.shellescape(dir)
82
- isolated_test_files = FileList['test/**/*_test_isolated.rb']
83
- # https://github.com/rails/rails/blob/3d590add45/railties/lib/rails/generators/app_base.rb#L345-L363
84
- _bundle_command = Gem.bin_path('bundler', 'bundle')
85
- require 'bundler'
86
- Bundler.with_clean_env do
87
- isolated_test_files.all? do |test_file|
88
- command = "-w -I#{dir}/lib -I#{dir}/test #{Shellwords.shellescape(test_file)}"
89
- full_command = %("#{Gem.ruby}" #{command})
90
- system(full_command)
91
- end or fail 'Failures' # rubocop:disable Style/AndOr
92
- end
93
- end
94
- end
95
-
96
- if ENV['RAILS_VERSION'].to_s > '4.0' && RUBY_ENGINE == 'ruby'
97
- task default: [:isolated, :test, :rubocop]
98
- else
99
- task default: [:test, :rubocop]
100
- end
101
-
102
- desc 'CI test task'
103
- task :ci => [:default]