json_api_ruby 0.4.5 → 0.5.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d44fb07a8492daca10263befdbc625650a3c2eea
|
4
|
+
data.tar.gz: bb712bed6fa7af0c0bd54af3b7a8d9cee881d32c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c0e735cf0650b19682845590bc206988c277af76ee99f9f8aef2f3dbd057e42441363a8f3ad51d68b062746d6e29f5e1b1cc3546ddfa7f68c21fa0b6cbfc64
|
7
|
+
data.tar.gz: 1e727eaab3ccc5b1b651caa5674b4072b2fb7da29487db244c784c42bf0eee0ac9acf3500873a055278af843cd2cde70ef124327fbe708e17fd51413030d1806
|
@@ -3,6 +3,7 @@ module JsonApi
|
|
3
3
|
module DSL
|
4
4
|
attr :_id_field
|
5
5
|
attr :_use_links
|
6
|
+
attr :_type
|
6
7
|
attr :fields
|
7
8
|
attr :relationships
|
8
9
|
|
@@ -30,6 +31,15 @@ module JsonApi
|
|
30
31
|
@_id_field = key
|
31
32
|
end
|
32
33
|
|
34
|
+
def type(type)
|
35
|
+
# allow falling back to default if we reallly want to
|
36
|
+
if type.blank?
|
37
|
+
@_type = nil
|
38
|
+
else
|
39
|
+
@_type = type.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
33
43
|
def use_links(yesno)
|
34
44
|
@_use_links = yesno
|
35
45
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe JsonApi::Resource do
|
4
|
-
|
5
|
-
|
6
|
-
PersonResource.new(person).to_hash
|
7
|
-
end
|
4
|
+
let(:person) { Person.new('Brad J. Armbruster', 'ace@airforce.mil') }
|
5
|
+
subject(:serialized_person) { PersonResource.new(person).to_hash }
|
8
6
|
|
9
7
|
it 'is follows the JSON API spec' do
|
10
8
|
expect(serialized_person).to be_valid_json_api
|
@@ -26,6 +24,15 @@ RSpec.describe JsonApi::Resource do
|
|
26
24
|
expect(serialized_person).to have_attribute(:updated_at)
|
27
25
|
end
|
28
26
|
|
27
|
+
describe 'overridding type' do
|
28
|
+
before { PersonResource.type(:persons) }
|
29
|
+
after { PersonResource.type(nil) }
|
30
|
+
|
31
|
+
it 'has "persons" as its type' do
|
32
|
+
expect(serialized_person['type']).to eq 'persons'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
describe 'relationships' do
|
30
37
|
subject(:serialized_article) do
|
31
38
|
article = Person.new('Anatoly Fyodorovich Krimov', 'red_star@kremlin.mil').articles.first
|
@@ -70,6 +70,7 @@ class Person
|
|
70
70
|
end
|
71
71
|
|
72
72
|
class PersonResource < JsonApi::Resource
|
73
|
+
type :people
|
73
74
|
attribute :name
|
74
75
|
attribute :email_address
|
75
76
|
attribute :created_at
|
@@ -101,6 +102,7 @@ end
|
|
101
102
|
|
102
103
|
class ArticleResource < JsonApi::Resource
|
103
104
|
id_field :uuid
|
105
|
+
type :articles
|
104
106
|
attributes :publish_date, :title, :short_description, :created_at, :updated_at
|
105
107
|
|
106
108
|
has_one :author
|
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.
|
4
|
+
version: 0.5.0
|
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-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|