active_model_serializers 0.10.0 → 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +6 -5
  3. data/.travis.yml +30 -21
  4. data/CHANGELOG.md +172 -2
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +23 -4
  7. data/README.md +166 -28
  8. data/Rakefile +3 -32
  9. data/active_model_serializers.gemspec +22 -25
  10. data/appveyor.yml +10 -6
  11. data/bin/rubocop +38 -0
  12. data/docs/README.md +2 -1
  13. data/docs/general/adapters.md +35 -11
  14. data/docs/general/caching.md +7 -1
  15. data/docs/general/configuration_options.md +86 -1
  16. data/docs/general/deserialization.md +1 -1
  17. data/docs/general/fields.md +31 -0
  18. data/docs/general/getting_started.md +1 -1
  19. data/docs/general/logging.md +7 -0
  20. data/docs/general/rendering.md +63 -25
  21. data/docs/general/serializers.md +125 -14
  22. data/docs/howto/add_pagination_links.md +16 -17
  23. data/docs/howto/add_relationship_links.md +140 -0
  24. data/docs/howto/add_root_key.md +11 -0
  25. data/docs/howto/grape_integration.md +42 -0
  26. data/docs/howto/outside_controller_use.md +12 -4
  27. data/docs/howto/passing_arbitrary_options.md +2 -2
  28. data/docs/howto/serialize_poro.md +46 -5
  29. data/docs/howto/test.md +2 -0
  30. data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
  31. data/docs/integrations/ember-and-json-api.md +67 -32
  32. data/docs/jsonapi/schema.md +1 -1
  33. data/lib/action_controller/serialization.rb +13 -3
  34. data/lib/active_model/serializer/adapter/base.rb +2 -0
  35. data/lib/active_model/serializer/array_serializer.rb +8 -5
  36. data/lib/active_model/serializer/association.rb +62 -10
  37. data/lib/active_model/serializer/belongs_to_reflection.rb +4 -3
  38. data/lib/active_model/serializer/collection_serializer.rb +39 -13
  39. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +82 -115
  40. data/lib/active_model/serializer/error_serializer.rb +11 -7
  41. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  42. data/lib/active_model/serializer/has_many_reflection.rb +3 -3
  43. data/lib/active_model/serializer/has_one_reflection.rb +1 -4
  44. data/lib/active_model/serializer/lazy_association.rb +95 -0
  45. data/lib/active_model/serializer/lint.rb +134 -130
  46. data/lib/active_model/serializer/reflection.rb +127 -67
  47. data/lib/active_model/serializer/version.rb +1 -1
  48. data/lib/active_model/serializer.rb +297 -79
  49. data/lib/active_model_serializers/adapter/attributes.rb +3 -66
  50. data/lib/active_model_serializers/adapter/base.rb +39 -39
  51. data/lib/active_model_serializers/adapter/json_api/deserialization.rb +2 -2
  52. data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
  53. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +47 -21
  54. data/lib/active_model_serializers/adapter/json_api/relationship.rb +75 -23
  55. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +39 -10
  56. data/lib/active_model_serializers/adapter/json_api.rb +71 -57
  57. data/lib/active_model_serializers/adapter.rb +6 -0
  58. data/lib/active_model_serializers/deprecate.rb +1 -2
  59. data/lib/active_model_serializers/deserialization.rb +2 -0
  60. data/lib/active_model_serializers/lookup_chain.rb +80 -0
  61. data/lib/active_model_serializers/model.rb +109 -28
  62. data/lib/active_model_serializers/railtie.rb +3 -1
  63. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  64. data/lib/active_model_serializers/serializable_resource.rb +6 -5
  65. data/lib/active_model_serializers/serialization_context.rb +10 -3
  66. data/lib/active_model_serializers/test/schema.rb +2 -2
  67. data/lib/active_model_serializers.rb +16 -1
  68. data/lib/generators/rails/resource_override.rb +1 -1
  69. data/lib/generators/rails/serializer_generator.rb +4 -4
  70. data/lib/grape/active_model_serializers.rb +7 -5
  71. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  72. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  73. data/lib/tasks/rubocop.rake +53 -0
  74. data/test/action_controller/adapter_selector_test.rb +14 -5
  75. data/test/action_controller/explicit_serializer_test.rb +5 -4
  76. data/test/action_controller/json/include_test.rb +106 -27
  77. data/test/action_controller/json_api/deserialization_test.rb +1 -1
  78. data/test/action_controller/json_api/errors_test.rb +8 -9
  79. data/test/action_controller/json_api/fields_test.rb +66 -0
  80. data/test/action_controller/json_api/linked_test.rb +29 -24
  81. data/test/action_controller/json_api/pagination_test.rb +31 -23
  82. data/test/action_controller/json_api/transform_test.rb +11 -3
  83. data/test/action_controller/lookup_proc_test.rb +49 -0
  84. data/test/action_controller/namespace_lookup_test.rb +232 -0
  85. data/test/action_controller/serialization_scope_name_test.rb +12 -6
  86. data/test/action_controller/serialization_test.rb +12 -9
  87. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  88. data/test/active_model_serializers/model_test.rb +137 -4
  89. data/test/active_model_serializers/railtie_test_isolated.rb +12 -7
  90. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +161 -0
  91. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  92. data/test/active_model_serializers/test/schema_test.rb +3 -2
  93. data/test/adapter/attributes_test.rb +40 -0
  94. data/test/adapter/json/collection_test.rb +14 -0
  95. data/test/adapter/json/has_many_test.rb +10 -2
  96. data/test/adapter/json/transform_test.rb +15 -15
  97. data/test/adapter/json_api/collection_test.rb +4 -3
  98. data/test/adapter/json_api/errors_test.rb +17 -19
  99. data/test/adapter/json_api/fields_test.rb +12 -3
  100. data/test/adapter/json_api/has_many_test.rb +49 -20
  101. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +213 -0
  102. data/test/adapter/json_api/json_api_test.rb +5 -7
  103. data/test/adapter/json_api/linked_test.rb +33 -12
  104. data/test/adapter/json_api/links_test.rb +4 -2
  105. data/test/adapter/json_api/pagination_links_test.rb +53 -13
  106. data/test/adapter/json_api/parse_test.rb +1 -1
  107. data/test/adapter/json_api/relationship_test.rb +309 -73
  108. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  109. data/test/adapter/json_api/transform_test.rb +263 -253
  110. data/test/adapter/json_api/type_test.rb +168 -36
  111. data/test/adapter/json_test.rb +8 -7
  112. data/test/adapter/null_test.rb +1 -2
  113. data/test/adapter/polymorphic_test.rb +52 -5
  114. data/test/adapter_test.rb +1 -1
  115. data/test/benchmark/app.rb +1 -1
  116. data/test/benchmark/benchmarking_support.rb +1 -1
  117. data/test/benchmark/bm_active_record.rb +81 -0
  118. data/test/benchmark/bm_adapter.rb +38 -0
  119. data/test/benchmark/bm_caching.rb +16 -16
  120. data/test/benchmark/bm_lookup_chain.rb +83 -0
  121. data/test/benchmark/bm_transform.rb +21 -10
  122. data/test/benchmark/controllers.rb +16 -17
  123. data/test/benchmark/fixtures.rb +72 -72
  124. data/test/cache_test.rb +235 -69
  125. data/test/collection_serializer_test.rb +31 -14
  126. data/test/fixtures/active_record.rb +45 -10
  127. data/test/fixtures/poro.rb +124 -181
  128. data/test/generators/serializer_generator_test.rb +23 -5
  129. data/test/grape_test.rb +170 -56
  130. data/test/lint_test.rb +1 -1
  131. data/test/logger_test.rb +13 -11
  132. data/test/serializable_resource_test.rb +18 -22
  133. data/test/serializers/association_macros_test.rb +3 -2
  134. data/test/serializers/associations_test.rb +222 -49
  135. data/test/serializers/attribute_test.rb +5 -3
  136. data/test/serializers/attributes_test.rb +1 -1
  137. data/test/serializers/caching_configuration_test_isolated.rb +6 -6
  138. data/test/serializers/fieldset_test.rb +1 -1
  139. data/test/serializers/meta_test.rb +12 -6
  140. data/test/serializers/options_test.rb +17 -6
  141. data/test/serializers/read_attribute_for_serialization_test.rb +3 -3
  142. data/test/serializers/reflection_test.rb +427 -0
  143. data/test/serializers/root_test.rb +1 -1
  144. data/test/serializers/serialization_test.rb +2 -2
  145. data/test/serializers/serializer_for_test.rb +12 -10
  146. data/test/serializers/serializer_for_with_namespace_test.rb +88 -0
  147. data/test/support/isolated_unit.rb +9 -4
  148. data/test/support/rails5_shims.rb +8 -2
  149. data/test/support/rails_app.rb +2 -9
  150. data/test/support/serialization_testing.rb +31 -5
  151. data/test/test_helper.rb +13 -0
  152. metadata +130 -71
  153. data/.rubocop_todo.yml +0 -167
  154. data/docs/ARCHITECTURE.md +0 -126
  155. data/lib/active_model/serializer/associations.rb +0 -100
  156. data/lib/active_model/serializer/attributes.rb +0 -82
  157. data/lib/active_model/serializer/collection_reflection.rb +0 -7
  158. data/lib/active_model/serializer/configuration.rb +0 -35
  159. data/lib/active_model/serializer/include_tree.rb +0 -111
  160. data/lib/active_model/serializer/links.rb +0 -35
  161. data/lib/active_model/serializer/meta.rb +0 -29
  162. data/lib/active_model/serializer/singular_reflection.rb +0 -7
  163. data/lib/active_model/serializer/type.rb +0 -25
  164. data/lib/active_model_serializers/key_transform.rb +0 -70
  165. data/test/active_model_serializers/key_transform_test.rb +0 -263
  166. data/test/adapter/json_api/has_many_embed_ids_test.rb +0 -43
  167. data/test/adapter/json_api/relationships_test.rb +0 -199
  168. data/test/adapter/json_api/resource_identifier_test.rb +0 -85
  169. data/test/include_tree/from_include_args_test.rb +0 -26
  170. data/test/include_tree/from_string_test.rb +0 -94
  171. data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ActiveModel
4
- class Serializer
5
- class IncludeTree
6
- class FromStringTest < ActiveSupport::TestCase
7
- def test_simple_array
8
- input = [:comments, :author]
9
- actual = ActiveModel::Serializer::IncludeTree.from_include_args(input)
10
- assert(actual.key?(:author))
11
- assert(actual.key?(:comments))
12
- end
13
-
14
- def test_nested_array
15
- input = [:comments, posts: [:author, comments: [:author]]]
16
- actual = ActiveModel::Serializer::IncludeTree.from_include_args(input)
17
- assert(actual.key?(:posts))
18
- assert(actual[:posts].key?(:author))
19
- assert(actual[:posts].key?(:comments))
20
- assert(actual[:posts][:comments].key?(:author))
21
- assert(actual.key?(:comments))
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,94 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ActiveModel
4
- class Serializer
5
- class IncludeTree
6
- class FromStringTest < ActiveSupport::TestCase
7
- def test_single_string
8
- input = 'author'
9
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
10
- assert(actual.key?(:author))
11
- end
12
-
13
- def test_multiple_strings
14
- input = 'author,comments'
15
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
16
- assert(actual.key?(:author))
17
- assert(actual.key?(:comments))
18
- end
19
-
20
- def test_multiple_strings_with_space
21
- input = 'author, comments'
22
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
23
- assert(actual.key?(:author))
24
- assert(actual.key?(:comments))
25
- end
26
-
27
- def test_nested_string
28
- input = 'posts.author'
29
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
30
- assert(actual.key?(:posts))
31
- assert(actual[:posts].key?(:author))
32
- end
33
-
34
- def test_multiple_nested_string
35
- input = 'posts.author,posts.comments.author,comments'
36
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
37
- assert(actual.key?(:posts))
38
- assert(actual[:posts].key?(:author))
39
- assert(actual[:posts].key?(:comments))
40
- assert(actual[:posts][:comments].key?(:author))
41
- assert(actual.key?(:comments))
42
- end
43
-
44
- def test_toplevel_star_string
45
- input = '*'
46
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
47
- assert(actual.key?(:comments))
48
- end
49
-
50
- def test_nested_star_string
51
- input = 'posts.*'
52
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
53
- assert(actual.key?(:posts))
54
- assert(actual[:posts].key?(:comments))
55
- end
56
-
57
- def test_nested_star_middle_string
58
- input = 'posts.*.author'
59
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
60
- assert(actual.key?(:posts))
61
- assert(actual[:posts].key?(:comments))
62
- assert(actual[:posts][:comments].key?(:author))
63
- refute(actual[:posts][:comments].key?(:unspecified))
64
- end
65
-
66
- def test_nested_star_lower_precedence_string
67
- input = 'posts.comments.author,posts.*'
68
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
69
- assert(actual.key?(:posts))
70
- assert(actual[:posts].key?(:comments))
71
- assert(actual[:posts][:comments].key?(:author))
72
- end
73
-
74
- def test_toplevel_double_star_string
75
- input = '**'
76
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
77
- assert(actual.key?(:posts))
78
- assert(actual[:posts].key?(:comments))
79
- assert(actual[:posts][:comments].key?(:posts))
80
- end
81
-
82
- def test_nested_double_star_string
83
- input = 'comments, posts.**'
84
- actual = ActiveModel::Serializer::IncludeTree.from_string(input)
85
- assert(actual.key?(:comments))
86
- refute(actual[:comments].key?(:author))
87
- assert(actual.key?(:posts))
88
- assert(actual[:posts].key?(:comments))
89
- assert(actual[:posts][:comments].key?(:posts))
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,64 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ActiveModel
4
- class Serializer
5
- class IncludeTree
6
- module Parsing
7
- class IncludeArgsToHashTest < MiniTest::Test
8
- def test_include_args_to_hash_from_symbol
9
- expected = { author: {} }
10
- input = :author
11
- actual = Parsing.include_args_to_hash(input)
12
-
13
- assert_equal(expected, actual)
14
- end
15
-
16
- def test_include_args_to_hash_from_array
17
- expected = { author: {}, comments: {} }
18
- input = [:author, :comments]
19
- actual = Parsing.include_args_to_hash(input)
20
-
21
- assert_equal(expected, actual)
22
- end
23
-
24
- def test_include_args_to_hash_from_nested_array
25
- expected = { author: {}, comments: { author: {} } }
26
- input = [:author, comments: [:author]]
27
- actual = Parsing.include_args_to_hash(input)
28
-
29
- assert_equal(expected, actual)
30
- end
31
-
32
- def test_include_args_to_hash_from_array_of_hashes
33
- expected = {
34
- author: {},
35
- blogs: { posts: { contributors: {} } },
36
- comments: { author: { blogs: { posts: {} } } }
37
- }
38
- input = [
39
- :author,
40
- blogs: [posts: :contributors],
41
- comments: { author: { blogs: :posts } }
42
- ]
43
- actual = Parsing.include_args_to_hash(input)
44
-
45
- assert_equal(expected, actual)
46
- end
47
-
48
- def test_array_of_string
49
- expected = {
50
- comments: { author: {}, attachment: {} }
51
- }
52
- input = [
53
- 'comments.author',
54
- 'comments.attachment'
55
- ]
56
- actual = Parsing.include_args_to_hash(input)
57
-
58
- assert_equal(expected, actual)
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end