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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba5f435a463e08420afbfe01b6e6c00d872c1d6
4
- data.tar.gz: 82bd54e3e35ce66ac027407ddd5edcc71d06a9bf
3
+ metadata.gz: db1df895288feca5b137412ef221f3412c505d22
4
+ data.tar.gz: b03003fbd272458938040658c346f46ffe46cef8
5
5
  SHA512:
6
- metadata.gz: 07593a0a1372734b4adcd11bd263e129cece029dc3f3bf3de9dd8998a7a28f32ebf0d02de4e9ff1c77cbdda4a7f6e976a15d666a803a0d983d57a4da935bea80
7
- data.tar.gz: 3625634704e631f29bcce7f64bbd53c847febf50806b063dffced0b3babe90f88360b2349622dce08a47a2bd4ec77529db629e3540fcd0aa9d95534216b451ad
6
+ metadata.gz: 2fbb35ae835ca899ccdf4e5da426b9678d359b8fae67b1f33ae80636c232adb2496f4abe41001e79aeb3a26cf3d587cba4a6ffd457ce3a90df4b2e0d1262fb33
7
+ data.tar.gz: 43d0066a894fa951042e3eb0af367ac38b19c1ab7e24f10d889fe12fe1bb3bb09ef43c208712f68943e1514db7919c0e4281109e0ae5d71703136745b4945079
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.1
2
+ Fix issues with `_id_field` on subclasses of class whose superclass is Resource
3
+
1
4
  0.2.0
2
5
  Added the ability to subclass from a class whose superclass is Resource
3
6
 
@@ -25,7 +25,7 @@ module JsonApi
25
25
  end
26
26
 
27
27
  def identifier_hash
28
- { 'id' => self.id, 'type' => self.type }
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)
@@ -1,3 +1,3 @@
1
1
  module JsonApi
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -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
- expect(subclass_serialization['relationships']).to eq(super_class_serialization['relationships'])
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)
@@ -79,6 +79,7 @@ class PersonResource < JsonApi::Resource
79
79
  end
80
80
 
81
81
  class SubclassedPersonResource < PersonResource
82
+ id_field :name
82
83
  attribute :website
83
84
  end
84
85
 
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.0
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-09 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport