restfully 0.7.1.pre → 0.7.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,12 @@ module Restfully
68
68
  total == 0
69
69
  end
70
70
 
71
+ # Expand the items that
72
+ def expand
73
+ each {|i| i.expand}
74
+ self
75
+ end
76
+
71
77
  def inspect
72
78
  map{|item| item}.inspect
73
79
  end
@@ -50,11 +50,7 @@ module Restfully
50
50
  end
51
51
 
52
52
  def inspect
53
- [
54
- "#{method.to_s.upcase} #{uri.to_s}",
55
- head.map{|(k,v)| "#{k}: #{v}"}.join("\n"),
56
- body
57
- ].compact.join("\n")
53
+ "#{method.to_s.upcase} #{uri.to_s}, head=#{head.inspect}, body=#{body.inspect}"
58
54
  end
59
55
 
60
56
  def no_cache?
@@ -36,6 +36,10 @@ module Restfully
36
36
  def media_type
37
37
  response.media_type
38
38
  end
39
+
40
+ def complete?
41
+ media_type.complete?
42
+ end
39
43
 
40
44
  def collection?
41
45
  media_type.collection?
@@ -185,6 +189,10 @@ module Restfully
185
189
  # end
186
190
  self
187
191
  end
192
+
193
+ def expand
194
+ reload_if_empty(self)
195
+ end
188
196
 
189
197
  protected
190
198
  def extract_payload_from_args(args)
@@ -205,7 +213,7 @@ module Restfully
205
213
  end
206
214
 
207
215
  def reload_if_empty(resource)
208
- resource.reload if resource && !resource.media_type.complete?
216
+ resource.reload if resource && !resource.complete?
209
217
  resource
210
218
  end
211
219
  end
@@ -1,3 +1,3 @@
1
1
  module Restfully
2
- VERSION = "0.7.1.pre"
2
+ VERSION = "0.7.1.rc1"
3
3
  end
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <collection xmlns="http://api.bonfire-project.eu/doc/schemas/occi" href="/locations">
3
+ <items offset="0" total="5">
4
+ <location href="/locations/be-ibbt">
5
+ <name>be-ibbt</name>
6
+ <url>https://bonfire.test.atlantis.ugent.be</url>
7
+ <link rel="parent" href="/" type="application/vnd.bonfire+xml"/>
8
+ <link rel="computes" href="/locations/be-ibbt/computes" type="application/vnd.bonfire+xml"/>
9
+ <link rel="networks" href="/locations/be-ibbt/networks" type="application/vnd.bonfire+xml"/>
10
+ <link rel="storages" href="/locations/be-ibbt/storages" type="application/vnd.bonfire+xml"/>
11
+ </location>
12
+ <location href="/locations/de-hlrs">
13
+ <name>de-hlrs</name>
14
+ <url>https://nebulosus.hlrs.de:8443</url>
15
+ <link rel="parent" href="/" type="application/vnd.bonfire+xml"/>
16
+ <link rel="computes" href="/locations/de-hlrs/computes" type="application/vnd.bonfire+xml"/>
17
+ <link rel="networks" href="/locations/de-hlrs/networks" type="application/vnd.bonfire+xml"/>
18
+ <link rel="storages" href="/locations/de-hlrs/storages" type="application/vnd.bonfire+xml"/>
19
+ </location>
20
+ <location href="/locations/fr-inria">
21
+ <name>fr-inria</name>
22
+ <url>https://bonfire.grid5000.fr:443</url>
23
+ <link rel="parent" href="/" type="application/vnd.bonfire+xml"/>
24
+ <link rel="computes" href="/locations/fr-inria/computes" type="application/vnd.bonfire+xml"/>
25
+ <link rel="networks" href="/locations/fr-inria/networks" type="application/vnd.bonfire+xml"/>
26
+ <link rel="storages" href="/locations/fr-inria/storages" type="application/vnd.bonfire+xml"/>
27
+ </location>
28
+ <location href="/locations/uk-epcc">
29
+ <name>uk-epcc</name>
30
+ <url>https://crockett.epcc.ed.ac.uk:8443</url>
31
+ <link rel="parent" href="/" type="application/vnd.bonfire+xml"/>
32
+ <link rel="computes" href="/locations/uk-epcc/computes" type="application/vnd.bonfire+xml"/>
33
+ <link rel="networks" href="/locations/uk-epcc/networks" type="application/vnd.bonfire+xml"/>
34
+ <link rel="storages" href="/locations/uk-epcc/storages" type="application/vnd.bonfire+xml"/>
35
+ </location>
36
+ <location href="/locations/uk-hplabs">
37
+ <name>uk-hplabs</name>
38
+ <url>https://occisvr-vif0.occi.ext8.bonfire.hpl.hp.com:8443</url>
39
+ <link rel="parent" href="/" type="application/vnd.bonfire+xml"/>
40
+ <link rel="computes" href="/locations/uk-hplabs/computes" type="application/vnd.bonfire+xml"/>
41
+ <link rel="networks" href="/locations/uk-hplabs/networks" type="application/vnd.bonfire+xml"/>
42
+ <link rel="storages" href="/locations/uk-hplabs/storages" type="application/vnd.bonfire+xml"/>
43
+ </location>
44
+ </items>
45
+ <link href="/" rel="parent" type="application/vnd.bonfire+xml"/>
46
+ </collection>
@@ -43,6 +43,21 @@ describe Restfully::Collection do
43
43
  items[0]['uid'].should == 376505
44
44
  end
45
45
 
46
+ it "should expand the items" do
47
+ @response = Restfully::HTTP::Response.new(
48
+ @session, 200, {
49
+ 'Content-Type' => 'application/vnd.bonfire+xml; charset=utf-8'
50
+ }, fixture('bonfire-collection-with-fragments.xml')
51
+ )
52
+ @resource = Restfully::Resource.new(@session, @response, @request).load
53
+ @resource.all?{|i| i.complete?}.should be_false
54
+ stub_request(:get, "https://api.grid5000.fr/locations/de-hlrs/networks/29").
55
+ with(:headers => {'Accept'=>'application/vnd.bonfire+xml', 'Accept-Encoding'=>'gzip, deflate', 'Cache-Control'=>'no-cache'}).
56
+ to_return(:status => 200, :body => fixture("bonfire-network-existing.xml"), :headers => {'Content-Type' => 'application/vnd.bonfire+xml'})
57
+ @resource.expand
58
+ @resource.all?{|i| i.complete?}.should be_true
59
+ end
60
+
46
61
  it "should be empty if no item" do
47
62
  @response = Restfully::HTTP::Response.new(
48
63
  @session, 200, {
@@ -17,7 +17,7 @@ describe Restfully::Resource do
17
17
  )
18
18
  Restfully::MediaType.register Restfully::MediaType::Grid5000
19
19
  end
20
-
20
+
21
21
  it "should correctly initialize a resource" do
22
22
  resource = Restfully::Resource.new(@session, @response, @request)
23
23
  resource.uri.to_s.should == "https://api.grid5000.fr/grid5000/sites/rennes"
@@ -29,13 +29,13 @@ describe Restfully::Resource do
29
29
  resource.should respond_to(rel.to_sym)
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "loaded" do
34
34
  before do
35
35
  @resource = Restfully::Resource.new(@session, @response, @request)
36
36
  @resource.load
37
37
  end
38
-
38
+
39
39
  it "should load the requested association" do
40
40
  @session.should_receive(:get).once.with(
41
41
  URI.parse("/grid5000/sites/rennes/clusters"),
@@ -44,7 +44,7 @@ describe Restfully::Resource do
44
44
  association.should_receive(:load)
45
45
  @resource.clusters
46
46
  end
47
-
47
+
48
48
  it "should not allow to submit if POST not allowed on the resource" do
49
49
  lambda{
50
50
  @resource.submit
@@ -60,7 +60,7 @@ describe Restfully::Resource do
60
60
  :serialization => {}
61
61
  )
62
62
  @resource.submit(
63
- 'some payload',
63
+ 'some payload',
64
64
  :headers => {'Content-Type' => 'text/plain'},
65
65
  :query => {:k1 => 'v1'}
66
66
  )
@@ -75,7 +75,7 @@ describe Restfully::Resource do
75
75
  :serialization => {}
76
76
  )
77
77
  @resource.submit(
78
- :key => 'value',
78
+ :key => 'value',
79
79
  :headers => {'Content-Type' => 'text/plain'},
80
80
  :query => {:k1 => 'v1'}
81
81
  )
@@ -102,26 +102,26 @@ describe Restfully::Resource do
102
102
  :serialization => {"__type__"=>"network"}
103
103
  )
104
104
  @resource.update(
105
- :key => 'value',
105
+ :key => 'value',
106
106
  :headers => {'Content-Type' => 'text/plain'},
107
107
  :query => {:k1 => 'v1'}
108
108
  )
109
109
  end
110
-
110
+
111
111
  it "should reload the resource" do
112
112
  @request.should_receive(:no_cache!)
113
113
  @resource.should_receive(:load).
114
114
  and_return(@resource)
115
115
  @resource.reload.should == @resource
116
116
  end
117
-
117
+
118
118
  it "should reload the resource even after having reloaded it once before" do
119
119
  @session.should_receive(:execute).twice.with(@request).
120
120
  and_return(@response)
121
121
  @resource.reload
122
122
  @resource.reload
123
123
  end
124
-
124
+
125
125
  it "should raise an error if it cannot reload the resource" do
126
126
  @session.should_receive(:execute).with(@request).
127
127
  and_return(res=mock(Restfully::HTTP::Response))
@@ -132,7 +132,38 @@ describe Restfully::Resource do
132
132
  }.should raise_error(Restfully::Error, "Cannot reload the resource")
133
133
  end
134
134
  end
135
-
136
-
137
-
135
+
136
+ describe "integration tests" do
137
+
138
+ it "should not interfere with another previously loaded resource" do
139
+ Restfully::MediaType.register Restfully::MediaType::ApplicationVndBonfireXml
140
+ @session = Restfully::Session.new(
141
+ :uri => "http://localhost:8000"
142
+ )
143
+ @request = Restfully::HTTP::Request.new(
144
+ @session, :get, "/locations",
145
+ :head => {'Accept' => 'application/vnd.bonfire+xml'}
146
+ )
147
+ @response = Restfully::HTTP::Response.new(
148
+ @session, 200, {
149
+ 'Content-Type' => 'application/vnd.bonfire+xml; charset=utf-8',
150
+ 'Allow' => 'GET'
151
+ }, fixture('bonfire-location-collection.xml')
152
+ )
153
+
154
+ resource = Restfully::Resource.new(@session, @response, @request).load
155
+ resource1 = resource[:'uk-epcc']
156
+ resource2 = resource[:'fr-inria']
157
+ stub_request(:get, "http://localhost:8000/locations/uk-epcc/networks").
158
+ with(:headers => {'Accept'=>'application/vnd.bonfire+xml', 'Accept-Encoding'=>'gzip, deflate'}).
159
+ to_return(:status => 200, :body => fixture("bonfire-network-collection.xml"), :headers => {'Content-Type' => 'application/vnd.bonfire+xml'})
160
+ stub_request(:get, "http://localhost:8000/locations/fr-inria/networks").
161
+ with(:headers => {'Accept'=>'application/vnd.bonfire+xml', 'Accept-Encoding'=>'gzip, deflate'}).
162
+ to_return(:status => 200, :body => fixture("bonfire-network-collection.xml"), :headers => {'Content-Type' => 'application/vnd.bonfire+xml'})
163
+ resource1.networks
164
+ resource2.networks
165
+ end
166
+
167
+ end # describe "integration tests"
168
+
138
169
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfully
3
3
  version: !ruby/object:Gem::Version
4
- hash: 961916024
4
+ hash: 15424111
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 1
10
- - pre
11
- version: 0.7.1.pre
10
+ - rc
11
+ - 1
12
+ version: 0.7.1.rc1
12
13
  platform: ruby
13
14
  authors:
14
15
  - Cyril Rohr
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-04-28 00:00:00 +02:00
20
+ date: 2011-05-09 00:00:00 +02:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -214,6 +215,7 @@ files:
214
215
  - spec/fixtures/bonfire-empty-collection.xml
215
216
  - spec/fixtures/bonfire-experiment-collection.xml
216
217
  - spec/fixtures/bonfire-experiment.xml
218
+ - spec/fixtures/bonfire-location-collection.xml
217
219
  - spec/fixtures/bonfire-network-collection.xml
218
220
  - spec/fixtures/bonfire-network-existing.xml
219
221
  - spec/fixtures/bonfire-root.xml
@@ -274,6 +276,7 @@ test_files:
274
276
  - spec/fixtures/bonfire-empty-collection.xml
275
277
  - spec/fixtures/bonfire-experiment-collection.xml
276
278
  - spec/fixtures/bonfire-experiment.xml
279
+ - spec/fixtures/bonfire-location-collection.xml
277
280
  - spec/fixtures/bonfire-network-collection.xml
278
281
  - spec/fixtures/bonfire-network-existing.xml
279
282
  - spec/fixtures/bonfire-root.xml