active_model_serializers 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +9 -1
  5. data/Rakefile +3 -3
  6. data/active_model_serializers.gemspec +15 -15
  7. data/docs/general/fields.md +31 -0
  8. data/docs/general/rendering.md +7 -2
  9. data/docs/general/serializers.md +32 -0
  10. data/docs/howto/add_pagination_links.md +2 -3
  11. data/docs/integrations/ember-and-json-api.md +25 -10
  12. data/lib/action_controller/serialization.rb +4 -3
  13. data/lib/active_model/serializer.rb +3 -4
  14. data/lib/active_model/serializer/array_serializer.rb +8 -5
  15. data/lib/active_model/serializer/associations.rb +2 -2
  16. data/lib/active_model/serializer/caching.rb +11 -8
  17. data/lib/active_model/serializer/error_serializer.rb +11 -7
  18. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  19. data/lib/active_model/serializer/lint.rb +134 -130
  20. data/lib/active_model/serializer/version.rb +1 -1
  21. data/lib/active_model_serializers/deprecate.rb +1 -1
  22. data/lib/active_model_serializers/model.rb +1 -1
  23. data/lib/active_model_serializers/railtie.rb +1 -1
  24. data/lib/active_model_serializers/register_jsonapi_renderer.rb +37 -35
  25. data/lib/generators/rails/serializer_generator.rb +3 -3
  26. data/lib/grape/active_model_serializers.rb +7 -5
  27. data/test/action_controller/adapter_selector_test.rb +3 -3
  28. data/test/action_controller/json_api/errors_test.rb +5 -6
  29. data/test/action_controller/json_api/linked_test.rb +4 -4
  30. data/test/action_controller/json_api/pagination_test.rb +19 -19
  31. data/test/action_controller/serialization_test.rb +1 -1
  32. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  33. data/test/active_model_serializers/key_transform_test.rb +254 -252
  34. data/test/active_model_serializers/model_test.rb +6 -4
  35. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +2 -2
  36. data/test/adapter/json/transform_test.rb +14 -14
  37. data/test/adapter/json_api/errors_test.rb +9 -9
  38. data/test/adapter/json_api/has_many_test.rb +18 -18
  39. data/test/adapter/json_api/json_api_test.rb +5 -7
  40. data/test/adapter/json_api/linked_test.rb +1 -1
  41. data/test/adapter/json_api/pagination_links_test.rb +6 -6
  42. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  43. data/test/adapter/json_api/transform_test.rb +218 -218
  44. data/test/adapter/json_api/type_test.rb +1 -1
  45. data/test/adapter/json_test.rb +8 -8
  46. data/test/adapter/null_test.rb +1 -2
  47. data/test/adapter/polymorphic_test.rb +5 -5
  48. data/test/adapter_test.rb +1 -1
  49. data/test/benchmark/bm_caching.rb +1 -1
  50. data/test/cache_test.rb +29 -1
  51. data/test/collection_serializer_test.rb +2 -2
  52. data/test/fixtures/poro.rb +2 -2
  53. data/test/grape_test.rb +130 -128
  54. data/test/lint_test.rb +1 -1
  55. data/test/logger_test.rb +13 -11
  56. data/test/serializable_resource_test.rb +12 -16
  57. data/test/serializers/associations_test.rb +10 -10
  58. data/test/serializers/attribute_test.rb +1 -1
  59. data/test/serializers/attributes_test.rb +1 -1
  60. data/test/serializers/fieldset_test.rb +1 -1
  61. data/test/serializers/root_test.rb +1 -1
  62. data/test/serializers/serializer_for_test.rb +3 -1
  63. data/test/support/isolated_unit.rb +4 -2
  64. data/test/support/serialization_testing.rb +7 -5
  65. metadata +3 -3
  66. data/.rubocop_todo.yml +0 -167
@@ -30,7 +30,7 @@ module ActiveModel
30
30
  def errors
31
31
  end
32
32
 
33
- def self.human_attribute_name(attr, options = {})
33
+ def self.human_attribute_name(_, _ = {})
34
34
  end
35
35
 
36
36
  def self.lookup_ancestors
@@ -1,18 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
- class ActiveModelSerializers::LoggerTest < ActiveSupport::TestCase
4
- def test_logger_is_set_to_action_controller_logger_when_initializer_runs
5
- assert_equal $action_controller_logger, ActionController::Base.logger # rubocop:disable Style/GlobalVars
6
- end
3
+ module ActiveModelSerializers
4
+ class LoggerTest < ActiveSupport::TestCase
5
+ def test_logger_is_set_to_action_controller_logger_when_initializer_runs
6
+ assert_equal $action_controller_logger, ActionController::Base.logger # rubocop:disable Style/GlobalVars
7
+ end
7
8
 
8
- def test_logger_can_be_set
9
- original_logger = ActiveModelSerializers.logger
10
- logger = Logger.new(STDOUT)
9
+ def test_logger_can_be_set
10
+ original_logger = ActiveModelSerializers.logger
11
+ logger = Logger.new(STDOUT)
11
12
 
12
- ActiveModelSerializers.logger = logger
13
+ ActiveModelSerializers.logger = logger
13
14
 
14
- assert_equal ActiveModelSerializers.logger, logger
15
- ensure
16
- ActiveModelSerializers.logger = original_logger
15
+ assert_equal ActiveModelSerializers.logger, logger
16
+ ensure
17
+ ActiveModelSerializers.logger = original_logger
18
+ end
17
19
  end
18
20
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  module ActiveModelSerializers
4
4
  class SerializableResourceTest < ActiveSupport::TestCase
5
5
  def setup
6
- @resource = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
6
+ @resource = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
7
7
  @serializer = ProfileSerializer.new(@resource)
8
8
  @adapter = ActiveModelSerializers::Adapter.create(@serializer)
9
9
  @serializable_resource = SerializableResource.new(@resource)
@@ -32,11 +32,11 @@ module ActiveModelSerializers
32
32
  end
33
33
 
34
34
  def test_use_adapter_with_adapter_option
35
- assert SerializableResource.new(@resource, { adapter: 'json' }).use_adapter?
35
+ assert SerializableResource.new(@resource, adapter: 'json').use_adapter?
36
36
  end
37
37
 
38
38
  def test_use_adapter_with_adapter_option_as_false
39
- refute SerializableResource.new(@resource, { adapter: false }).use_adapter?
39
+ refute SerializableResource.new(@resource, adapter: false).use_adapter?
40
40
  end
41
41
 
42
42
  class SerializableResourceErrorsTest < Minitest::Test
@@ -45,14 +45,12 @@ module ActiveModelSerializers
45
45
  resource = ModelWithErrors.new
46
46
  resource.errors.add(:name, 'must be awesome')
47
47
  serializable_resource = ActiveModelSerializers::SerializableResource.new(
48
- resource, {
49
- serializer: ActiveModel::Serializer::ErrorSerializer,
50
- adapter: :json_api
51
- }
48
+ resource, serializer: ActiveModel::Serializer::ErrorSerializer,
49
+ adapter: :json_api
52
50
  )
53
51
  expected_response_document = {
54
- :errors => [
55
- { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
52
+ errors: [
53
+ { source: { pointer: '/data/attributes/name' }, detail: 'must be awesome' }
56
54
  ]
57
55
  }
58
56
  assert_equal serializable_resource.as_json(options), expected_response_document
@@ -65,15 +63,13 @@ module ActiveModelSerializers
65
63
  resource.errors.add(:title, 'must be amazing')
66
64
  resources << ModelWithErrors.new
67
65
  serializable_resource = SerializableResource.new(
68
- resources, {
69
- serializer: ActiveModel::Serializer::ErrorsSerializer,
70
- each_serializer: ActiveModel::Serializer::ErrorSerializer,
71
- adapter: :json_api
72
- }
66
+ resources, serializer: ActiveModel::Serializer::ErrorsSerializer,
67
+ each_serializer: ActiveModel::Serializer::ErrorSerializer,
68
+ adapter: :json_api
73
69
  )
74
70
  expected_response_document = {
75
- :errors => [
76
- { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' }
71
+ errors: [
72
+ { source: { pointer: '/data/attributes/title' }, detail: 'must be amazing' }
77
73
  ]
78
74
  }
79
75
  assert_equal serializable_resource.as_json(options), expected_response_document
@@ -7,10 +7,10 @@ module ActiveModel
7
7
  @author = Author.new(name: 'Steve K.')
8
8
  @author.bio = nil
9
9
  @author.roles = []
10
- @blog = Blog.new({ name: 'AMS Blog' })
11
- @post = Post.new({ title: 'New Post', body: 'Body' })
12
- @tag = Tag.new({ name: '#hashtagged' })
13
- @comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
10
+ @blog = Blog.new(name: 'AMS Blog')
11
+ @post = Post.new(title: 'New Post', body: 'Body')
12
+ @tag = Tag.new(name: '#hashtagged')
13
+ @comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
14
14
  @post.comments = [@comment]
15
15
  @post.tags = [@tag]
16
16
  @post.blog = @blog
@@ -19,7 +19,7 @@ module ActiveModel
19
19
  @post.author = @author
20
20
  @author.posts = [@post]
21
21
 
22
- @post_serializer = PostSerializer.new(@post, { custom_options: true })
22
+ @post_serializer = PostSerializer.new(@post, custom_options: true)
23
23
  @author_serializer = AuthorSerializer.new(@author)
24
24
  @comment_serializer = CommentSerializer.new(@comment)
25
25
  end
@@ -143,12 +143,12 @@ module ActiveModel
143
143
  )
144
144
  actual = serializable(post, adapter: :attributes, serializer: InlineAssociationTestPostSerializer).as_json
145
145
  expected = {
146
- :comments => [
147
- { :id => 1, :contents => 'first comment' },
148
- { :id => 2, :contents => 'last comment' }
146
+ comments: [
147
+ { id: 1, contents: 'first comment' },
148
+ { id: 2, contents: 'last comment' }
149
149
  ],
150
- :last_comments => [
151
- { :id => 2, :contents => 'last comment' }
150
+ last_comments: [
151
+ { id: 2, contents: 'last comment' }
152
152
  ]
153
153
  }
154
154
 
@@ -22,7 +22,7 @@ module ActiveModel
22
22
  inherited_klass = Class.new(AlternateBlogSerializer)
23
23
  blog_serializer = inherited_klass.new(@blog)
24
24
  adapter = ActiveModelSerializers::Adapter::Attributes.new(blog_serializer)
25
- assert_equal({ :id => 1, :title => 'AMS Hints' }, adapter.serializable_hash)
25
+ assert_equal({ id: 1, title: 'AMS Hints' }, adapter.serializable_hash)
26
26
  end
27
27
 
28
28
  def test_multiple_calls_with_the_same_attribute
@@ -4,7 +4,7 @@ module ActiveModel
4
4
  class Serializer
5
5
  class AttributesTest < ActiveSupport::TestCase
6
6
  def setup
7
- @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
7
+ @profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
8
8
  @profile_serializer = ProfileSerializer.new(@profile)
9
9
  @comment = Comment.new(id: 1, body: 'ZOMG!!', date: '2015')
10
10
  @serializer_klass = Class.new(CommentSerializer)
@@ -5,7 +5,7 @@ module ActiveModel
5
5
  class FieldsetTest < ActiveSupport::TestCase
6
6
  def test_fieldset_with_hash
7
7
  fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
8
- expected = { :post => [:id, :title], :comment => [:body] }
8
+ expected = { post: [:id, :title], comment: [:body] }
9
9
 
10
10
  assert_equal(expected, fieldset.fields)
11
11
  end
@@ -8,7 +8,7 @@ module ActiveModel
8
8
  end
9
9
 
10
10
  def test_overwrite_root
11
- serializer = VirtualValueSerializer.new(@virtual_value, { root: 'smth' })
11
+ serializer = VirtualValueSerializer.new(@virtual_value, root: 'smth')
12
12
  assert_equal('smth', serializer.json_key)
13
13
  end
14
14
 
@@ -41,7 +41,9 @@ module ActiveModel
41
41
  end
42
42
 
43
43
  class CustomProfile
44
- def serializer_class; ProfileSerializer; end
44
+ def serializer_class
45
+ ProfileSerializer
46
+ end
45
47
  end
46
48
 
47
49
  Tweet = Class.new(::Model)
@@ -75,6 +75,8 @@ module TestHelpers
75
75
  end
76
76
  end
77
77
 
78
- class ActiveSupport::TestCase
79
- include TestHelpers::Generation
78
+ module ActiveSupport
79
+ class TestCase
80
+ include TestHelpers::Generation
81
+ end
80
82
  end
@@ -44,10 +44,12 @@ module SerializationTesting
44
44
  end
45
45
  end
46
46
 
47
- class Minitest::Test
48
- def before_setup
49
- ActionController::Base.cache_store.clear
50
- end
47
+ module Minitest
48
+ class Test
49
+ def before_setup
50
+ ActionController::Base.cache_store.clear
51
+ end
51
52
 
52
- include SerializationTesting
53
+ include SerializationTesting
54
+ end
53
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -246,7 +246,6 @@ files:
246
246
  - ".github/PULL_REQUEST_TEMPLATE.md"
247
247
  - ".gitignore"
248
248
  - ".rubocop.yml"
249
- - ".rubocop_todo.yml"
250
249
  - ".simplecov"
251
250
  - ".travis.yml"
252
251
  - CHANGELOG.md
@@ -267,6 +266,7 @@ files:
267
266
  - docs/general/caching.md
268
267
  - docs/general/configuration_options.md
269
268
  - docs/general/deserialization.md
269
+ - docs/general/fields.md
270
270
  - docs/general/getting_started.md
271
271
  - docs/general/instrumentation.md
272
272
  - docs/general/key_transforms.md
@@ -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'