jsonapi-consumer 0.1.0.pre.2 → 0.1.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/jsonapi/consumer/parser.rb +1 -1
- data/lib/jsonapi/consumer/version.rb +1 -1
- data/spec/fixtures/resources.rb +5 -1
- data/spec/fixtures/responses.rb +16 -3
- data/spec/jsonapi/consumer/parser_spec.rb +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c1023158bad9c3f878f6c70c43de0030f33548f
|
4
|
+
data.tar.gz: e00a070c00e6dc4f013b7acb976fa38a3dab2b4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 576270b931a52c0b2813bd09a86a0352cd4b1ca9961ec4ed1cd923fc8f6a09076d03acd6879758c9c7c56f71851fba863cf53effd68b22c9a160adceafad2302
|
7
|
+
data.tar.gz: b8f8db8bb78d3dfd10c7b56206cf2419962a36a3c15c7f0f9ff0f9bb246bab4ecc8f9961a0c308de4ebb23f89669409c1c0b363999a8a0c04f063470b6bd9fbf
|
data/CHANGELOG.md
CHANGED
@@ -40,7 +40,7 @@ module JSONAPI::Consumer
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def find_linked(assoc_name, id)
|
43
|
-
if found = linked.fetch(assoc_name, []).detect {|h| h.fetch(:id) == id }
|
43
|
+
if found = linked.fetch(assoc_name.pluralize, []).detect {|h| h.fetch(:id) == id }
|
44
44
|
klass._association_class_name(assoc_name).new(found)
|
45
45
|
else
|
46
46
|
fetch_linked(assoc_name, id)
|
data/spec/fixtures/resources.rb
CHANGED
@@ -21,10 +21,14 @@ module Blog
|
|
21
21
|
end
|
22
22
|
|
23
23
|
class Post < Base
|
24
|
-
has_one :
|
24
|
+
has_one :user, class_name: 'Blog::User'
|
25
25
|
has_many :comments, class_name: 'Blog::Comment'
|
26
26
|
end
|
27
27
|
|
28
|
+
class User < Base
|
29
|
+
|
30
|
+
end
|
31
|
+
|
28
32
|
class Comment < Base
|
29
33
|
# belongs_to :post, class_name: 'Blog::Post'
|
30
34
|
# has_one :author, class_name: 'Blog::Author'
|
data/spec/fixtures/responses.rb
CHANGED
@@ -7,7 +7,8 @@ module Responses
|
|
7
7
|
comments: [
|
8
8
|
"82083863-bba9-480e-a281-f5d34e7dc0ca",
|
9
9
|
"3b402e8a-7c35-4915-8c72-07ea7779ab76"
|
10
|
-
]
|
10
|
+
],
|
11
|
+
user: "6a45992f-cd20-497a-a753-21b2a1a82356"
|
11
12
|
},
|
12
13
|
id: "e6d1b7ac-80d8-40dd-877d-f5bd40feabfb",
|
13
14
|
title: "Friday Post",
|
@@ -19,7 +20,8 @@ module Responses
|
|
19
20
|
comments: [
|
20
21
|
"9c9ba83b-024c-4d4c-9573-9fd41b95fc14",
|
21
22
|
"27fcf6e8-24b0-41db-94b1-812046a10f54"
|
22
|
-
]
|
23
|
+
],
|
24
|
+
user: "d65dda70-73eb-461a-bb34-5484e6e8c194"
|
23
25
|
},
|
24
26
|
id: "ea006f14-6d05-4e87-bfe7-ee8ae3358840",
|
25
27
|
title: "Monday Post",
|
@@ -28,6 +30,16 @@ module Responses
|
|
28
30
|
}
|
29
31
|
],
|
30
32
|
linked: {
|
33
|
+
users: [
|
34
|
+
{
|
35
|
+
id: "6a45992f-cd20-497a-a753-21b2a1a82356",
|
36
|
+
name: "Jane Smith"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
id: "d65dda70-73eb-461a-bb34-5484e6e8c194",
|
40
|
+
name: "Jim Bob"
|
41
|
+
}
|
42
|
+
],
|
31
43
|
comments: [
|
32
44
|
{
|
33
45
|
id: "82083863-bba9-480e-a281-f5d34e7dc0ca",
|
@@ -44,7 +56,8 @@ module Responses
|
|
44
56
|
]
|
45
57
|
},
|
46
58
|
links: {
|
47
|
-
:"posts.comments" => "http://localhost:3000/api/comments/{posts.comments}"
|
59
|
+
:"posts.comments" => "http://localhost:3000/api/comments/{posts.comments}",
|
60
|
+
:"posts.user" => "http://localhost:3000/api/comments/{posts.user}"
|
48
61
|
}
|
49
62
|
}.with_indifferent_access
|
50
63
|
end
|
@@ -25,15 +25,13 @@ RSpec.describe 'Response Parsing' do
|
|
25
25
|
]
|
26
26
|
}.to_json)
|
27
27
|
|
28
|
-
# puts results.inspect
|
29
28
|
expect(results.size).to eql(2)
|
30
29
|
|
31
30
|
result = results.first
|
32
31
|
expect(result.comments.size).to eql(2)
|
32
|
+
expect(result.user).to be_a(Blog::User)
|
33
33
|
|
34
34
|
last = results.last
|
35
|
-
expect(result.comments.size).to eql(2)
|
36
|
-
|
37
35
|
expect(last.comments.first).to be_a(Blog::Comment)
|
38
36
|
expect(last.comments.first.id).to eql("9c9ba83b-024c-4d4c-9573-9fd41b95fc14")
|
39
37
|
expect(last.comments.first.content).to eql("i found this useful.")
|