active_model_serializers 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f42ff2b93cdc399b58c219efd12add5e5757612a
4
- data.tar.gz: 624cba1a3b71a9aa668f7612b1937a889b98d22e
3
+ metadata.gz: 824c53b8e015242b747a646eb8d39e6f5bfb6828
4
+ data.tar.gz: c57b340d57742eda89976c6eff76f79c630615ce
5
5
  SHA512:
6
- metadata.gz: 4abbf3c69e8de7d29b24aab129229e5bfa6c94eb46c73212016d02592ea8fb3d3fbba6eb0effef1f8b0b3a03ca359f71933678fe98da58db21590f76f1c02dd3
7
- data.tar.gz: b5730a2a45db222ee3b331e1ef3a1ba68efc86c17dc7d2c8172c59d4bb4273624031085d331b96078f861d764cb7b8a58d8405ffd9c081af5268b7b319688e94
6
+ metadata.gz: 1d102aafb1713dd3010bde0cfc29e84626f9dd56d02a0d63807fed04a05d519a4d11ee35ee19e6c0a1e15714a460bdc8280e0d491421bc9fc8dc49fe84dce3fc
7
+ data.tar.gz: 3135135c42d6533232266a5d7f8b7efba43c83b2fc9017a2867172afeb2c459fc9b335d1322dd625eb916729891902357898785f51b981590ff5cc20671c1d34
data/CHANGELOG.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.4...0-9-stable)
4
4
 
5
- ### [v0.9.4 (2015-01-05)](https://github.com/rails-api/active_model_serializers/compare/v0.9.3...v0.9.4)
5
+ ### [v0.9.5 (2016-03-30)](https://github.com/rails-api/active_model_serializers/compare/v0.9.4...v0.9.5)
6
+
7
+ - [#1607](https://github.com/rails-api/active_model_serializers/pull/1607) Merge multiple nested associations. (@Hirtenknogger)
8
+
9
+ ### [v0.9.4 (2016-01-05)](https://github.com/rails-api/active_model_serializers/compare/v0.9.3...v0.9.4)
6
10
 
7
11
  - [#752](https://github.com/rails-api/active_model_serializers/pull/752) Tiny improvement of README 0-9-stable (@basiam)
8
12
  - [#749](https://github.com/rails-api/active_model_serializers/pull/749) remove trailing whitespace (@shwoodard)
@@ -205,7 +205,11 @@ end
205
205
  # we must do this always because even if the current association is not
206
206
  # embeded in root, it might have its own associations that are embeded in root
207
207
  hash.merge!(association_serializer.embedded_in_root_associations) do |key, oldval, newval|
208
- oldval.merge(newval) { |_, oldval, newval| [oldval, newval].flatten.uniq }
208
+ if oldval.respond_to?(:to_ary)
209
+ [oldval, newval].flatten.uniq
210
+ else
211
+ oldval.merge(newval) { |_, oldval, newval| [oldval, newval].flatten.uniq }
212
+ end
209
213
  end
210
214
 
211
215
  if association.embed_in_root?
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Serializer
3
- VERSION = '0.9.4'
3
+ VERSION = '0.9.5'
4
4
  end
5
5
  end
@@ -53,6 +53,26 @@ class SpecialPost < Post
53
53
  end
54
54
  end
55
55
 
56
+ class Type < Model
57
+ end
58
+
59
+ class SelfReferencingUser < Model
60
+ def type
61
+ @type ||= Type.new(name: 'N1')
62
+ end
63
+ def parent
64
+ @parent ||= SelfReferencingUserParent.new(name: 'N1')
65
+ end
66
+ end
67
+
68
+ class SelfReferencingUserParent < Model
69
+ def type
70
+ @type ||= Type.new(name: 'N2')
71
+ end
72
+ def parent
73
+ end
74
+ end
75
+
56
76
  class Comment < Model
57
77
  end
58
78
 
@@ -87,6 +107,22 @@ class UserSerializer < ActiveModel::Serializer
87
107
  has_one :profile
88
108
  end
89
109
 
110
+ class TypeSerializer < ActiveModel::Serializer
111
+ attributes :name
112
+ end
113
+
114
+ class SelfReferencingUserParentSerializer < ActiveModel::Serializer
115
+ attributes :name
116
+ has_one :type, serializer: TypeSerializer, embed: :ids, include: true
117
+ end
118
+
119
+ class SelfReferencingUserSerializer < ActiveModel::Serializer
120
+ attributes :name
121
+
122
+ has_one :type, serializer: TypeSerializer, embed: :ids, include: true
123
+ has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, include: true
124
+ end
125
+
90
126
  class UserInfoSerializer < ActiveModel::Serializer
91
127
  has_one :user, serializer: UserSerializer
92
128
  end
@@ -176,7 +212,7 @@ end
176
212
 
177
213
  class NameKeyPostSerializer < ActiveModel::Serializer
178
214
  attributes :title, :body
179
-
215
+
180
216
  has_many :comments
181
217
  end
182
218
 
@@ -0,0 +1,3 @@
1
+ class AccountSerializer < MySerializer
2
+ attributes :id
3
+ end
@@ -14,6 +14,36 @@ module ActiveModel
14
14
  assert_equal([:comments],
15
15
  another_inherited_serializer_klass._associations.keys)
16
16
  end
17
+ def test_multiple_nested_associations
18
+ parent = SelfReferencingUserParent.new(name: "The Parent")
19
+ child = SelfReferencingUser.new(name: "The child", parent: parent)
20
+ self_referencing_user_serializer = SelfReferencingUserSerializer.new(child)
21
+ result = self_referencing_user_serializer.as_json
22
+ expected_result = {
23
+ "self_referencing_user"=>{
24
+ :name=>"The child",
25
+ "type_id"=>child.type.object_id,
26
+ "parent_id"=>child.parent.object_id
27
+
28
+ },
29
+ "types"=>[
30
+ {
31
+ :name=>"N1",
32
+ },
33
+ {
34
+ :name=>"N2",
35
+ }
36
+ ],
37
+ "parents"=>[
38
+ {
39
+ :name=>"N1",
40
+ "type_id"=>child.parent.type.object_id,
41
+ "parent_id"=>nil
42
+ }
43
+ ]
44
+ }
45
+ assert_equal(expected_result, result)
46
+ end
17
47
  end
18
48
  end
19
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-01-05 00:00:00.000000000 Z
13
+ date: 2016-03-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -75,7 +75,6 @@ files:
75
75
  - lib/active_model/serializer/version.rb
76
76
  - lib/active_model/serializer_support.rb
77
77
  - lib/active_model_serializers.rb
78
- - lib/active_model_serializers/mime_types.rb
79
78
  - test/fixtures/active_record.rb
80
79
  - test/fixtures/poro.rb
81
80
  - test/fixtures/template.html.erb
@@ -88,6 +87,7 @@ files:
88
87
  - test/integration/generators/serializer_generator_test.rb
89
88
  - test/test_app.rb
90
89
  - test/test_helper.rb
90
+ - test/tmp/app/serializers/account_serializer.rb
91
91
  - test/unit/active_model/array_serializer/except_test.rb
92
92
  - test/unit/active_model/array_serializer/key_format_test.rb
93
93
  - test/unit/active_model/array_serializer/meta_test.rb
@@ -151,6 +151,7 @@ test_files:
151
151
  - test/integration/generators/serializer_generator_test.rb
152
152
  - test/test_app.rb
153
153
  - test/test_helper.rb
154
+ - test/tmp/app/serializers/account_serializer.rb
154
155
  - test/unit/active_model/array_serializer/except_test.rb
155
156
  - test/unit/active_model/array_serializer/key_format_test.rb
156
157
  - test/unit/active_model/array_serializer/meta_test.rb
@@ -176,4 +177,3 @@ test_files:
176
177
  - test/unit/active_model/serializer/root_test.rb
177
178
  - test/unit/active_model/serializer/scope_test.rb
178
179
  - test/unit/active_model/serializer/url_helpers_test.rb
179
- has_rdoc:
@@ -1,14 +0,0 @@
1
- # module ActiveModelSerializers::JSONAPI
2
- # HEADERS = {
3
- # content_type: { "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE }
4
- # }
5
- # MEDIA_TYPE = 'application/vnd.api+json'
6
- # end
7
- #
8
- # Mime::Type.register ActiveModelSerializers::JSONAPI::MEDIA_TYPE, :api_json
9
- #
10
- # ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup(ActiveModelSerializers::JSONAPI::MEDIA_TYPE)] = lambda do |body|
11
- # data = JSON.parse(body)
12
- # data = {:_json => data} unless data.is_a?(Hash)
13
- # data.with_indifferent_access
14
- # end