active_model_serializers 0.9.4 → 0.9.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/active_model/serializer.rb +5 -1
- data/lib/active_model/serializer/version.rb +1 -1
- data/test/fixtures/poro.rb +37 -1
- data/test/tmp/app/serializers/account_serializer.rb +3 -0
- data/test/unit/active_model/serializer/associations_test.rb +30 -0
- metadata +4 -4
- data/lib/active_model_serializers/mime_types.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 824c53b8e015242b747a646eb8d39e6f5bfb6828
|
4
|
+
data.tar.gz: c57b340d57742eda89976c6eff76f79c630615ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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?
|
data/test/fixtures/poro.rb
CHANGED
@@ -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
|
|
@@ -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
|
+
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-
|
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
|