harpy 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,6 +80,19 @@ module Harpy
80
80
  result
81
81
  end
82
82
 
83
+ def delete_from_url(url)
84
+ delete_from_url_handler Harpy.client.delete url
85
+ end
86
+
87
+ def delete_from_urn(urn)
88
+ url = Harpy.entry_point.urn urn
89
+ url ? delete_from_url(url) : false
90
+ end
91
+
92
+ def delete_from_id(id)
93
+ delete_from_urn urn id
94
+ end
95
+
83
96
  private
84
97
 
85
98
  def url
@@ -96,6 +109,17 @@ module Harpy
96
109
  Harpy.client.invalid_code response
97
110
  end
98
111
  end
112
+
113
+ def delete_from_url_handler(response)
114
+ case response.code
115
+ when 204
116
+ true
117
+ when 404
118
+ false
119
+ else
120
+ Harpy.client.invalid_code response
121
+ end
122
+ end
99
123
  end
100
124
 
101
125
  module InstanceMethods
data/lib/harpy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Harpy
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -191,6 +191,103 @@ describe "class including Harpy::Resource" do
191
191
  Harpy::Spec::Company.from_id(1).should be_nil
192
192
  end
193
193
  end
194
+ end
195
+ describe ".delete_from_url(url)" do
196
+ context "called with only one url" do
197
+ let(:url){ "http://localhost/company/1" }
198
+ it "is true on success" do
199
+ response = Typhoeus::Response.new :code => 204
200
+ Harpy.client.should_receive(:delete).with(url).and_return response
201
+ result = Harpy::Spec::Company.delete_from_url url
202
+ result.should be_true
203
+ end
204
+ it "is false when not found" do
205
+ response = Typhoeus::Response.new :code => 404
206
+ Harpy.client.should_receive(:delete).with(url).and_return response
207
+ Harpy::Spec::Company.delete_from_url(url).should be_false
208
+ end
209
+ it "delegates response code != 204 or 404 to client" do
210
+ response = Typhoeus::Response.new :code => 500
211
+ Harpy.client.should_receive(:delete).with(url).and_return response
212
+ Harpy.client.should_receive(:invalid_code).with response
213
+ Harpy::Spec::Company.delete_from_url url
214
+ end
215
+ end
216
+ end
217
+ describe ".delete_from_urn(urn)" do
218
+ context "when entry point is not set" do
219
+ it "raises Harpy::EntryPointRequired" do
220
+ lambda{
221
+ Harpy::Spec::Company.delete_from_urn("urn:harpy:company:1")
222
+ }.should raise_error Harpy::EntryPointRequired
223
+ end
224
+ end
225
+ context "when entry point is set" do
226
+ let(:urn) { "urn:harpy:company:1" }
227
+ let(:url) { "http://localhost/company/1" }
228
+ it "asks Harpy.entry_point to convert urn to url then call .from_url" do
229
+ # urn:harpy:company:1 -> http://localhost/company/1
230
+ Harpy.entry_point = mock
231
+ Harpy.entry_point.should_receive(:urn).with(urn).and_return url
232
+
233
+ # http://localhost/company/1 -> Harpy::Spec::Company instance
234
+ Harpy::Spec::Company.should_receive(:delete_from_url).with(url).and_return(expected = mock)
235
+ Harpy::Spec::Company.delete_from_urn(urn).should be expected
236
+ end
237
+ it "is nil if urn is not found" do
238
+ # urn:harpy:company:1 -> nil
239
+ Harpy.entry_point = mock
240
+ Harpy.entry_point.should_receive(:urn).with(urn)
241
+
242
+ Harpy::Spec::Company.delete_from_urn(urn).should be_false
243
+ end
244
+ end
245
+ end
246
+ describe ".delete_from_id(id)" do
247
+ context "when urn has not been overriden" do
248
+ it "raises NotImplementedError" do
249
+ lambda{
250
+ Harpy::Spec::Company.delete_from_id(1)
251
+ }.should raise_error NotImplementedError
252
+ end
253
+ end
254
+ context "when urn has been overriden but entry point is not set" do
255
+ let(:urn) { "urn:harpy:company:1" }
256
+ it "raises Harpy::EntryPointRequired" do
257
+ # 1 -> urn:harpy:company:1
258
+ Harpy::Spec::Company.should_receive(:urn).with(1).and_return urn
259
+
260
+ lambda{
261
+ Harpy::Spec::Company.delete_from_id(1)
262
+ }.should raise_error Harpy::EntryPointRequired
263
+ end
264
+ end
265
+ context "when entry point is set and urn has been overriden" do
266
+ let(:urn) { "urn:harpy:company:1" }
267
+ let(:url) { "http://localhost/company/1" }
268
+ it "asks Harpy.entry_point to convert urn to url then call .from_url" do
269
+ # 1 -> urn:harpy:company:1
270
+ Harpy::Spec::Company.should_receive(:urn).with(1).and_return urn
271
+
272
+ # urn:harpy:company:1 -> http://localhost/company/1
273
+ Harpy.entry_point = mock
274
+ Harpy.entry_point.should_receive(:urn).with(urn).and_return url
275
+
276
+ # http://localhost/company/1 -> Harpy::Spec::Company instance
277
+ Harpy::Spec::Company.should_receive(:delete_from_url).with(url).and_return(expected = mock)
278
+ Harpy::Spec::Company.delete_from_id(1).should be expected
279
+ end
280
+ it "is nil if urn is not found" do
281
+ # 1 -> urn:harpy:company:1
282
+ Harpy::Spec::Company.should_receive(:urn).with(1).and_return urn
283
+
284
+ # urn:harpy:company:1 -> nil
285
+ Harpy.entry_point = mock
286
+ Harpy.entry_point.should_receive(:urn).with(urn)
287
+
288
+ Harpy::Spec::Company.delete_from_id(1).should be_false
289
+ end
290
+ end
194
291
  end
195
292
  describe ".urn(id)" do
196
293
  it "raises NotImplementedError" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-02 00:00:00.000000000 +02:00
13
+ date: 2011-08-04 00:00:00.000000000 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus
18
- requirement: &2164624240 !ruby/object:Gem::Requirement
18
+ requirement: &2160282920 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 0.2.4
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2164624240
26
+ version_requirements: *2160282920
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
- requirement: &2164623720 !ruby/object:Gem::Requirement
29
+ requirement: &2160282260 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2164623720
37
+ version_requirements: *2160282260
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: activemodel
40
- requirement: &2164623240 !ruby/object:Gem::Requirement
40
+ requirement: &2160281760 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 3.0.0
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *2164623240
48
+ version_requirements: *2160281760
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: hash-deep-merge
51
- requirement: &2156256400 !ruby/object:Gem::Requirement
51
+ requirement: &2160281280 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 0.1.1
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *2156256400
59
+ version_requirements: *2160281280
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: yajl-ruby
62
- requirement: &2156255920 !ruby/object:Gem::Requirement
62
+ requirement: &2160280500 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.8.2
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *2156255920
70
+ version_requirements: *2160280500
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rake
73
- requirement: &2156255440 !ruby/object:Gem::Requirement
73
+ requirement: &2160280000 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: 0.8.7
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2156255440
81
+ version_requirements: *2160280000
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rspec
84
- requirement: &2156254960 !ruby/object:Gem::Requirement
84
+ requirement: &2160279480 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ~>
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: 2.6.0
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *2156254960
92
+ version_requirements: *2160279480
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rocco
95
- requirement: &2156254480 !ruby/object:Gem::Requirement
95
+ requirement: &2160278960 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ~>
@@ -100,7 +100,7 @@ dependencies:
100
100
  version: '0.7'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *2156254480
103
+ version_requirements: *2160278960
104
104
  description: Client for REST API with HATEOAS
105
105
  email:
106
106
  - joseph.halter@thetalentbox.com