restfully 0.7.1.rc2 → 0.7.1.rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,13 +16,15 @@ module Restfully
16
16
  end
17
17
 
18
18
  def find_by_uid(symbol)
19
- find{ |i| reload_if_empty(i).media_type.represents?(symbol) }
19
+ found = find{ |i| i.media_type.represents?(symbol) }
20
+ found.expand unless found.nil?
21
+ found
20
22
  end
21
23
 
22
24
  def find_by_index(index)
23
25
  index = index+length if index < 0
24
26
  each_with_index{|item, i|
25
- return reload_if_empty(item) if i == index
27
+ return item.expand if i == index
26
28
  }
27
29
  nil
28
30
  end
@@ -25,8 +25,7 @@ module Restfully
25
25
  # resource["uid"]
26
26
  # => "rennes"
27
27
  def [](key)
28
- reload_if_empty(self)
29
- media_type.property(key)
28
+ expand.media_type.property(key)
30
29
  end
31
30
 
32
31
  def uri
@@ -93,7 +92,7 @@ module Restfully
93
92
  end
94
93
 
95
94
  def submit(*args)
96
- if allow?(:post)
95
+ if allow?("POST")
97
96
  @request.no_cache!
98
97
  payload, options = extract_payload_from_args(args)
99
98
  session.post(request.uri, payload, options)
@@ -103,7 +102,7 @@ module Restfully
103
102
  end
104
103
 
105
104
  def delete(options = {})
106
- if allow?(:delete)
105
+ if allow?("DELETE")
107
106
  @request.no_cache!
108
107
  session.delete(request.uri)
109
108
  else
@@ -112,7 +111,7 @@ module Restfully
112
111
  end
113
112
 
114
113
  def update(*args)
115
- if allow?(:put)
114
+ if allow?("PUT")
116
115
  @request.no_cache!
117
116
  payload, options = extract_payload_from_args(args)
118
117
  session.put(request.uri, payload, options)
@@ -122,6 +121,7 @@ module Restfully
122
121
  end
123
122
 
124
123
  def allow?(method)
124
+ reload
125
125
  response.allow?(method)
126
126
  end
127
127
 
@@ -155,6 +155,7 @@ module Restfully
155
155
  end
156
156
  end
157
157
  else
158
+ expand
158
159
  pp.text "PROPERTIES"
159
160
  pp.nest 2 do
160
161
  properties.each do |key, value|
@@ -191,7 +192,8 @@ module Restfully
191
192
  end
192
193
 
193
194
  def expand
194
- reload_if_empty(self)
195
+ reload unless complete?
196
+ self
195
197
  end
196
198
 
197
199
  protected
@@ -212,9 +214,5 @@ module Restfully
212
214
  [payload, options]
213
215
  end
214
216
 
215
- def reload_if_empty(resource)
216
- resource.reload if resource && !resource.complete?
217
- resource
218
- end
219
217
  end
220
218
  end
@@ -1,3 +1,3 @@
1
1
  module Restfully
2
- VERSION = "0.7.1.rc2"
2
+ VERSION = "0.7.1.rc3"
3
3
  end
@@ -44,14 +44,23 @@ describe Restfully::Resource do
44
44
  association.should_receive(:load)
45
45
  @resource.clusters
46
46
  end
47
-
47
+ {:update => "PUT", :submit => "POST", :delete => "DELETE"}.each do |method, http_method|
48
+ it "should reload the resource first, to get the Allowed HTTP methods when calling #{method.to_sym}" do
49
+ @resource.should_receive(:reload).once.and_return(@resource)
50
+ @response.should_receive(:allow?).with(http_method).and_return(true)
51
+ @session.should_receive(http_method.downcase.to_sym).
52
+ and_return(mock(Restfully::HTTP::Response))
53
+ @resource.send(method.to_sym)
54
+ end
55
+ end
48
56
  it "should not allow to submit if POST not allowed on the resource" do
57
+ @resource.should_receive(:reload).and_return(@resource)
49
58
  lambda{
50
59
  @resource.submit
51
60
  }.should raise_error(Restfully::MethodNotAllowed)
52
61
  end
53
62
  it "should send a POST request if POST is allowed [payload argument]" do
54
- @resource.should_receive(:allow?).with(:post).and_return(true)
63
+ @resource.should_receive(:allow?).with("POST").and_return(true)
55
64
  @session.should_receive(:post).with(
56
65
  @resource.uri,
57
66
  'some payload',
@@ -66,7 +75,7 @@ describe Restfully::Resource do
66
75
  )
67
76
  end
68
77
  it "should send a POST request if POST is allowed [payload as hash]" do
69
- @resource.should_receive(:allow?).with(:post).and_return(true)
78
+ @resource.should_receive(:allow?).with("POST").and_return(true)
70
79
  @session.should_receive(:post).with(
71
80
  @resource.uri,
72
81
  {:key => 'value'},
@@ -93,7 +102,7 @@ describe Restfully::Resource do
93
102
  }, fixture('bonfire-network-existing.xml')
94
103
  )
95
104
  @resource = Restfully::Resource.new(@session, @response, @request).load
96
- @resource.should_receive(:allow?).with(:put).and_return(true)
105
+ @resource.should_receive(:allow?).with("PUT").and_return(true)
97
106
  @session.should_receive(:put).with(
98
107
  @resource.uri,
99
108
  {:key => 'value'},
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfully
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424105
4
+ hash: 15424107
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 1
10
10
  - rc
11
- - 2
12
- version: 0.7.1.rc2
11
+ - 3
12
+ version: 0.7.1.rc3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Cyril Rohr
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-05-13 00:00:00 +02:00
20
+ date: 2011-05-16 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency