jsonapi-serializers 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jsonapi-serializers.gemspec +2 -2
- data/lib/jsonapi-serializers/serializer.rb +6 -1
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +16 -0
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cff13da1ad649652014dfc451176436fcde50ba
|
4
|
+
data.tar.gz: 46c974244da10f13881c8a0de5ea63eec2c2ec04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2746b67e07e94155403e8740932d8f0a6f0df161208e6a3602346be71350cb0cd11b84dfb3d710e8008cf5582650b6f2e25058286aba8984be92acf95be479bd
|
7
|
+
data.tar.gz: dcc38f840609ef7730e7c84f11bc613092935b156b1786cb16b9314caafe8d1d9854b2d40c376badf0a447fcc6f031074a364e0e45625c0cac2338a17c710d99
|
data/jsonapi-serializers.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Mike Fotinakis"]
|
10
10
|
spec.email = ["mike@fotinakis.com"]
|
11
11
|
spec.summary = %q{Pure Ruby readonly serializers for the JSON:API spec.}
|
12
|
-
spec.description = %q{}
|
13
|
-
spec.homepage = ""
|
12
|
+
spec.description = %q{Pure Ruby readonly serializers for the JSON:API spec.}
|
13
|
+
spec.homepage = "https://github.com/fotinakis/jsonapi-serializers"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -359,10 +359,15 @@ module JSONAPI
|
|
359
359
|
|
360
360
|
serializer = serializer_class.new(object, options)
|
361
361
|
data = {
|
362
|
-
'id' => serializer.id.to_s,
|
363
362
|
'type' => serializer.type.to_s,
|
364
363
|
}
|
365
364
|
|
365
|
+
# "The id member is not required when the resource object originates at the client
|
366
|
+
# and represents a new resource to be created on the server."
|
367
|
+
# http://jsonapi.org/format/#document-resource-objects
|
368
|
+
# We'll assume that if the id is blank, it means the resource is to be created.
|
369
|
+
data['id'] = serializer.id.to_s if serializer.id && !serializer.id.empty?
|
370
|
+
|
366
371
|
# Merge in optional top-level members if they are non-nil.
|
367
372
|
# http://jsonapi.org/format/#document-structure-resource-objects
|
368
373
|
# Call the methods once now to avoid calling them twice when evaluating the if's below.
|
data/spec/serializer_spec.rb
CHANGED
@@ -129,6 +129,22 @@ describe JSONAPI::Serializer do
|
|
129
129
|
},
|
130
130
|
})
|
131
131
|
end
|
132
|
+
it 'does not include id when it is nil' do
|
133
|
+
post = create(:post)
|
134
|
+
post.id = nil
|
135
|
+
primary_data = serialize_primary(post, {serializer: MyApp::PostSerializerWithoutLinks})
|
136
|
+
expect(primary_data).to eq({
|
137
|
+
'type' => 'posts',
|
138
|
+
'attributes' => {
|
139
|
+
'title' => 'Title for Post 1',
|
140
|
+
'long-content' => 'Body for Post 1',
|
141
|
+
},
|
142
|
+
'relationships' => {
|
143
|
+
'author' => {},
|
144
|
+
'long-comments' => {},
|
145
|
+
},
|
146
|
+
})
|
147
|
+
end
|
132
148
|
it 'serializes object when multiple attributes are declared once' do
|
133
149
|
post = create(:post)
|
134
150
|
primary_data = serialize_primary(post, {serializer: MyApp::MultipleAttributesSerializer})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Fotinakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4.2'
|
97
|
-
description:
|
97
|
+
description: Pure Ruby readonly serializers for the JSON:API spec.
|
98
98
|
email:
|
99
99
|
- mike@fotinakis.com
|
100
100
|
executables: []
|
@@ -117,7 +117,7 @@ files:
|
|
117
117
|
- spec/spec_helper.rb
|
118
118
|
- spec/support/factory.rb
|
119
119
|
- spec/support/serializers.rb
|
120
|
-
homepage:
|
120
|
+
homepage: https://github.com/fotinakis/jsonapi-serializers
|
121
121
|
licenses:
|
122
122
|
- MIT
|
123
123
|
metadata: {}
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.2.2
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: Pure Ruby readonly serializers for the JSON:API spec.
|
@@ -146,4 +146,3 @@ test_files:
|
|
146
146
|
- spec/spec_helper.rb
|
147
147
|
- spec/support/factory.rb
|
148
148
|
- spec/support/serializers.rb
|
149
|
-
has_rdoc:
|