json_api_ruby 0.2.0 → 0.2.1
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 +3 -0
- data/lib/json_api_ruby/resources/base.rb +12 -1
- data/lib/json_api_ruby/version.rb +1 -1
- data/spec/json_api_ruby/resource_spec.rb +11 -1
- data/spec/support/resource_objects.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db1df895288feca5b137412ef221f3412c505d22
|
4
|
+
data.tar.gz: b03003fbd272458938040658c346f46ffe46cef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fbb35ae835ca899ccdf4e5da426b9678d359b8fae67b1f33ae80636c232adb2496f4abe41001e79aeb3a26cf3d587cba4a6ffd457ce3a90df4b2e0d1262fb33
|
7
|
+
data.tar.gz: 43d0066a894fa951042e3eb0af367ac38b19c1ab7e24f10d889fe12fe1bb3bb09ef43c208712f68943e1514db7919c0e4281109e0ae5d71703136745b4945079
|
data/CHANGELOG.md
CHANGED
@@ -25,7 +25,7 @@ module JsonApi
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def identifier_hash
|
28
|
-
{ 'id' =>
|
28
|
+
{ 'id' => _model.send(id_field), 'type' => self.type }
|
29
29
|
end
|
30
30
|
|
31
31
|
def links_hash
|
@@ -78,6 +78,17 @@ module JsonApi
|
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
|
+
# Traverses superclasses for the first `_id_field` not set to `:id` and
|
82
|
+
# return its value. Stops when the superclass is Resource.
|
83
|
+
def id_field(klass = self.class)
|
84
|
+
return klass._id_field unless klass._id_field == :id
|
85
|
+
if klass.superclass == Resource
|
86
|
+
klass._id_field
|
87
|
+
else
|
88
|
+
id_field(klass.superclass)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
81
92
|
# Adds elements of the `concat_list` to the `target_list` if they are
|
82
93
|
# not already present.
|
83
94
|
def concat_list(target_list, concat_list)
|
@@ -99,6 +99,10 @@ RSpec.describe JsonApi::Resource do
|
|
99
99
|
SubclassedPersonResource.new(person).to_hash
|
100
100
|
end
|
101
101
|
|
102
|
+
it 'can override the id field of its super-class' do
|
103
|
+
expect(subclass_serialization['id']).to eq('Philip J. Fry')
|
104
|
+
end
|
105
|
+
|
102
106
|
it "does not affect its super-class's list of attributes" do
|
103
107
|
expect(PersonResource.fields).to_not eq(SubclassedPersonResource.fields)
|
104
108
|
end
|
@@ -109,7 +113,9 @@ RSpec.describe JsonApi::Resource do
|
|
109
113
|
end
|
110
114
|
|
111
115
|
it 'returns the same relationships as its super-class' do
|
112
|
-
|
116
|
+
actual_relationship_names = subclass_serialization['relationships'].keys
|
117
|
+
expected_relationship_names = super_class_serialization['relationships'].keys
|
118
|
+
expect(actual_relationship_names).to eq(expected_relationship_names)
|
113
119
|
end
|
114
120
|
|
115
121
|
context 'with overridden attributes' do
|
@@ -128,6 +134,10 @@ RSpec.describe JsonApi::Resource do
|
|
128
134
|
DeeplySubclassedPersonResource.new(person).to_hash
|
129
135
|
end
|
130
136
|
|
137
|
+
it 'can fall back to the id of its super-class' do
|
138
|
+
expect(deep_subclass_serialization['id']).to eq('Philip J. Fry')
|
139
|
+
end
|
140
|
+
|
131
141
|
it 'concatinates its attributes with the list of attributes from its super-classes' do
|
132
142
|
expected_attributes = super_class_serialization['attributes'].merge('website' => 'www.thefuture.com', 'twitter' => '@philipjfry')
|
133
143
|
expect(deep_subclass_serialization['attributes']).to eq(expected_attributes)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tracey Eubanks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|