bookingsync-api 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bookingsync/api/resource.rb +2 -2
- data/lib/bookingsync/api/version.rb +1 -1
- data/spec/bookingsync/api/resource_spec.rb +17 -5
- 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: 92433c7543f03518887efc316656768355772c6e
|
4
|
+
data.tar.gz: caf9b90d93ebd5b323f12d7f2a3e81d124353c0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06dff22dabc99c0e7de5197340db2b0cf6270ec62c18518262f6faa31a597a9a48374baebf4811b9bc1d0af880ec0b0cdd7335b2b5587c95a002c23248f23473
|
7
|
+
data.tar.gz: 640a730f3ee59300645065c3023e3ba4f249e684f35a729acd764f10a348b80f260c134a845853b006ffff3e3dc105e1e781e6fbd4d96022cb9b60c714a34c9d
|
@@ -41,8 +41,8 @@ module BookingSync::API
|
|
41
41
|
def method_missing(method, *args)
|
42
42
|
association_key = :"#{@_resources_key}.#{method}"
|
43
43
|
if self[:links] && self[:links].has_key?(method)
|
44
|
-
ids = self[:links][method]
|
45
|
-
return [] if
|
44
|
+
ids = Array(self[:links][method])
|
45
|
+
return [] if ids.empty?
|
46
46
|
options = {uri: {association_key => ids}}
|
47
47
|
options.merge!(query: args.first) if args.first.is_a?(Hash)
|
48
48
|
@_rels[association_key].get(options).resources
|
@@ -14,7 +14,7 @@ describe BookingSync::API::Resource do
|
|
14
14
|
},
|
15
15
|
{
|
16
16
|
:"foo.photos" => "http://foo.com/photos/{foo.photos}",
|
17
|
-
:"foo.
|
17
|
+
:"foo.category" => "http://foo.com/categories/{foo.category}"
|
18
18
|
},
|
19
19
|
"foo"
|
20
20
|
)
|
@@ -45,10 +45,22 @@ describe BookingSync::API::Resource do
|
|
45
45
|
|
46
46
|
describe "associations" do
|
47
47
|
before { VCR.turn_off! }
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
|
49
|
+
context "has_many (ids given as an array)" do
|
50
|
+
it "fetches an association based on links" do
|
51
|
+
stub_request(:get, "http://foo.com/photos/9,10")
|
52
|
+
.to_return(body: {photos: [{file: 'a.jpg'}]}.to_json)
|
53
|
+
expect(resource.photos).to eql([{:file => "a.jpg"}])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "has_one (id given as a single integer)" do
|
58
|
+
let(:links) { {category: 15} }
|
59
|
+
it "fetches an association based on links" do
|
60
|
+
stub_request(:get, "http://foo.com/categories/15")
|
61
|
+
.to_return(body: {categories: [{name: "Secret one"}]}.to_json)
|
62
|
+
expect(resource.category).to eql([{name: "Secret one"}])
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
66
|
context "when there are not associated ids" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookingsync-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sébastien Grosjean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|