harpy 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/.travis.yml +4 -6
- data/README.md +5 -5
- data/harpy.gemspec +6 -5
- data/lib/harpy.rb +3 -2
- data/lib/harpy/gem_version.rb +14 -0
- data/lib/harpy/resource.rb +109 -93
- data/lib/harpy/version.rb +9 -0
- data/spec/harpy/client_spec.rb +27 -20
- data/spec/harpy/entry_point_spec.rb +14 -14
- data/spec/harpy/resource_spec.rb +224 -224
- data/spec/harpy_spec.rb +20 -20
- metadata +52 -52
- data/Gemfile.lock +0 -56
@@ -5,7 +5,7 @@ describe Harpy::EntryPoint do
|
|
5
5
|
subject { Harpy::EntryPoint.new url}
|
6
6
|
|
7
7
|
it "should store url" do
|
8
|
-
subject.url.
|
8
|
+
expect(subject.url).to eq(url)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#resource_url(resource_type)" do
|
@@ -14,20 +14,20 @@ describe Harpy::EntryPoint do
|
|
14
14
|
let(:success_response) { Typhoeus::Response.new :code => 200, :body => json_response }
|
15
15
|
let(:error_response) { Typhoeus::Response.new :code => 500 }
|
16
16
|
it "gets entry point from url using client" do
|
17
|
-
Harpy.client.
|
17
|
+
expect(Harpy.client).to receive(:get).with(url).and_return success_response
|
18
18
|
subject.resource_url "user"
|
19
19
|
end
|
20
20
|
it "return nil if no link for resource_type" do
|
21
|
-
Harpy.client.
|
22
|
-
subject.resource_url("user").
|
21
|
+
expect(Harpy.client).to receive(:get).with(url).and_return success_response
|
22
|
+
expect(subject.resource_url("user")).to be_nil
|
23
23
|
end
|
24
24
|
it "return url for existing resource_type" do
|
25
|
-
Harpy.client.
|
26
|
-
subject.resource_url("company_url").
|
25
|
+
expect(Harpy.client).to receive(:get).with(url).and_return success_response
|
26
|
+
expect(subject.resource_url("company_url")).to be_nil
|
27
27
|
end
|
28
28
|
it "delegates response code != 200 to client" do
|
29
|
-
Harpy.client.
|
30
|
-
Harpy.client.
|
29
|
+
expect(Harpy.client).to receive(:get).with(url).and_return error_response
|
30
|
+
expect(Harpy.client).to receive(:invalid_code).with error_response
|
31
31
|
subject.resource_url("company_url")
|
32
32
|
end
|
33
33
|
end
|
@@ -39,16 +39,16 @@ describe Harpy::EntryPoint do
|
|
39
39
|
let(:error_response) { Typhoeus::Response.new :code => 500 }
|
40
40
|
let(:not_found_response) { Typhoeus::Response.new :code => 404 }
|
41
41
|
it "query remote for this urn using client" do
|
42
|
-
Harpy.client.
|
43
|
-
subject.urn(urn).
|
42
|
+
expect(Harpy.client).to receive(:get).with("#{url}/#{urn}").and_return success_response
|
43
|
+
expect(subject.urn(urn)).to eq(company_url)
|
44
44
|
end
|
45
45
|
it "return nil if not found" do
|
46
|
-
Harpy.client.
|
47
|
-
subject.urn(urn).
|
46
|
+
expect(Harpy.client).to receive(:get).with("#{url}/#{urn}").and_return not_found_response
|
47
|
+
expect(subject.urn(urn)).to be_nil
|
48
48
|
end
|
49
49
|
it "delegates response code != 301 or 404 to client" do
|
50
|
-
Harpy.client.
|
51
|
-
Harpy.client.
|
50
|
+
expect(Harpy.client).to receive(:get).with("#{url}/#{urn}").and_return error_response
|
51
|
+
expect(Harpy.client).to receive(:invalid_code).with error_response
|
52
52
|
subject.urn(urn)
|
53
53
|
end
|
54
54
|
end
|
data/spec/harpy/resource_spec.rb
CHANGED
@@ -8,9 +8,9 @@ describe Harpy::Resource do
|
|
8
8
|
it "queries multiple resources in parallel and return instances" do
|
9
9
|
Typhoeus.stub(company_url, method: :get){ success_response }
|
10
10
|
responses = Harpy::Resource.from_url({ Harpy::Spec::Company => [company_url] })
|
11
|
-
responses.
|
12
|
-
responses[Harpy::Spec::Company].
|
13
|
-
responses[Harpy::Spec::Company].first.name.
|
11
|
+
expect(responses.size).to eq(1)
|
12
|
+
expect(responses[Harpy::Spec::Company].size).to eq(1)
|
13
|
+
expect(responses[Harpy::Spec::Company].first.name).to eq("Harpy ltd")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -35,7 +35,7 @@ module Harpy
|
|
35
35
|
super
|
36
36
|
end
|
37
37
|
def check_lastname
|
38
|
-
|
38
|
+
throw :abort unless lastname
|
39
39
|
end
|
40
40
|
def callback_before_save
|
41
41
|
@callbacks << :save
|
@@ -67,21 +67,21 @@ describe "class including Harpy::Resource" do
|
|
67
67
|
]
|
68
68
|
}
|
69
69
|
eos
|
70
|
-
Harpy.client.
|
70
|
+
expect(Harpy.client).to receive(:get).with(url).and_return response
|
71
71
|
result = Harpy::Spec::Company.from_url url
|
72
|
-
result.
|
73
|
-
result.name.
|
74
|
-
result.link("self").
|
72
|
+
expect(result).to be_kind_of Harpy::Spec::Company
|
73
|
+
expect(result.name).to eq("Harpy Ltd")
|
74
|
+
expect(result.link("self")).to eq(url)
|
75
75
|
end
|
76
76
|
it "is nil when not found" do
|
77
77
|
response = Typhoeus::Response.new :code => 404
|
78
|
-
Harpy.client.
|
79
|
-
Harpy::Spec::Company.from_url(url).
|
78
|
+
expect(Harpy.client).to receive(:get).with(url).and_return response
|
79
|
+
expect(Harpy::Spec::Company.from_url(url)).to be_nil
|
80
80
|
end
|
81
81
|
it "delegates response code != 200 or 404 to client" do
|
82
82
|
response = Typhoeus::Response.new :code => 500
|
83
|
-
Harpy.client.
|
84
|
-
Harpy.client.
|
83
|
+
expect(Harpy.client).to receive(:get).with(url).and_return response
|
84
|
+
expect(Harpy.client).to receive(:invalid_code).with response
|
85
85
|
Harpy::Spec::Company.from_url(url)
|
86
86
|
end
|
87
87
|
end
|
@@ -108,22 +108,22 @@ describe "class including Harpy::Resource" do
|
|
108
108
|
Typhoeus.stub(url1, method: :get){ response1 }
|
109
109
|
Typhoeus.stub(url2, method: :get){ response2 }
|
110
110
|
results = Harpy::Spec::Company.from_url [url1, url2]
|
111
|
-
results.
|
112
|
-
results[0].
|
113
|
-
results[0].name.
|
114
|
-
results[0].link("self").
|
115
|
-
results[1].
|
116
|
-
results[1].name.
|
117
|
-
results[1].link("self").
|
111
|
+
expect(results.size).to eq(2)
|
112
|
+
expect(results[0]).to be_kind_of Harpy::Spec::Company
|
113
|
+
expect(results[0].name).to eq("Harpy Ltd")
|
114
|
+
expect(results[0].link("self")).to eq(url1)
|
115
|
+
expect(results[1]).to be_kind_of Harpy::Spec::Company
|
116
|
+
expect(results[1].name).to eq("Harpy Inc")
|
117
|
+
expect(results[1].link("self")).to eq(url2)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
describe ".from_urn(urn)" do
|
122
122
|
context "when entry point is not set" do
|
123
123
|
it "raises Harpy::EntryPointRequired" do
|
124
|
-
|
124
|
+
expect{
|
125
125
|
Harpy::Spec::Company.from_urn("urn:harpy:company:1")
|
126
|
-
}.
|
126
|
+
}.to raise_error Harpy::EntryPointRequired
|
127
127
|
end
|
128
128
|
end
|
129
129
|
context "when entry point is set" do
|
@@ -132,38 +132,38 @@ describe "class including Harpy::Resource" do
|
|
132
132
|
it "asks Harpy.entry_point to convert urn to url then call .from_url" do
|
133
133
|
# urn:harpy:company:1 -> http://localhost/company/1
|
134
134
|
Harpy.entry_point = double
|
135
|
-
Harpy.entry_point.
|
135
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn).and_return url
|
136
136
|
|
137
137
|
# http://localhost/company/1 -> Harpy::Spec::Company instance
|
138
|
-
Harpy::Spec::Company.
|
139
|
-
Harpy::Spec::Company.from_urn(urn).
|
138
|
+
expect(Harpy::Spec::Company).to receive(:from_url).with(url).and_return(expected = double)
|
139
|
+
expect(Harpy::Spec::Company.from_urn(urn)).to be expected
|
140
140
|
end
|
141
141
|
it "is nil if urn is not found" do
|
142
142
|
# urn:harpy:company:1 -> nil
|
143
143
|
Harpy.entry_point = double
|
144
|
-
Harpy.entry_point.
|
144
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn)
|
145
145
|
|
146
|
-
Harpy::Spec::Company.from_urn(urn).
|
146
|
+
expect(Harpy::Spec::Company.from_urn(urn)).to be_nil
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
150
150
|
describe ".from_id(id)" do
|
151
151
|
context "when urn has not been overriden" do
|
152
152
|
it "raises NotImplementedError" do
|
153
|
-
|
153
|
+
expect{
|
154
154
|
Harpy::Spec::Company.from_id(1)
|
155
|
-
}.
|
155
|
+
}.to raise_error NotImplementedError
|
156
156
|
end
|
157
157
|
end
|
158
158
|
context "when urn has been overriden but entry point is not set" do
|
159
159
|
let(:urn) { "urn:harpy:company:1" }
|
160
160
|
it "raises Harpy::EntryPointRequired" do
|
161
161
|
# 1 -> urn:harpy:company:1
|
162
|
-
Harpy::Spec::Company.
|
162
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
163
163
|
|
164
|
-
|
164
|
+
expect{
|
165
165
|
Harpy::Spec::Company.from_id(1)
|
166
|
-
}.
|
166
|
+
}.to raise_error Harpy::EntryPointRequired
|
167
167
|
end
|
168
168
|
end
|
169
169
|
context "when entry point is set and urn has been overriden" do
|
@@ -171,25 +171,25 @@ describe "class including Harpy::Resource" do
|
|
171
171
|
let(:url) { "http://localhost/company/1" }
|
172
172
|
it "asks Harpy.entry_point to convert urn to url then call .from_url" do
|
173
173
|
# 1 -> urn:harpy:company:1
|
174
|
-
Harpy::Spec::Company.
|
174
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
175
175
|
|
176
176
|
# urn:harpy:company:1 -> http://localhost/company/1
|
177
177
|
Harpy.entry_point = double
|
178
|
-
Harpy.entry_point.
|
178
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn).and_return url
|
179
179
|
|
180
180
|
# http://localhost/company/1 -> Harpy::Spec::Company instance
|
181
|
-
Harpy::Spec::Company.
|
182
|
-
Harpy::Spec::Company.from_id(1).
|
181
|
+
expect(Harpy::Spec::Company).to receive(:from_url).with(url).and_return(expected = double)
|
182
|
+
expect(Harpy::Spec::Company.from_id(1)).to be expected
|
183
183
|
end
|
184
184
|
it "is nil if urn is not found" do
|
185
185
|
# 1 -> urn:harpy:company:1
|
186
|
-
Harpy::Spec::Company.
|
186
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
187
187
|
|
188
188
|
# urn:harpy:company:1 -> nil
|
189
189
|
Harpy.entry_point = double
|
190
|
-
Harpy.entry_point.
|
190
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn)
|
191
191
|
|
192
|
-
Harpy::Spec::Company.from_id(1).
|
192
|
+
expect(Harpy::Spec::Company.from_id(1)).to be_nil
|
193
193
|
end
|
194
194
|
end
|
195
195
|
end
|
@@ -198,19 +198,19 @@ describe "class including Harpy::Resource" do
|
|
198
198
|
let(:url){ "http://localhost/company/1" }
|
199
199
|
it "is true on success" do
|
200
200
|
response = Typhoeus::Response.new :code => 204
|
201
|
-
Harpy.client.
|
201
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
202
202
|
result = Harpy::Spec::Company.delete_from_url url
|
203
|
-
result.
|
203
|
+
expect(result).to be_truthy
|
204
204
|
end
|
205
205
|
it "is false when not found" do
|
206
206
|
response = Typhoeus::Response.new :code => 404
|
207
|
-
Harpy.client.
|
208
|
-
Harpy::Spec::Company.delete_from_url(url).
|
207
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
208
|
+
expect(Harpy::Spec::Company.delete_from_url(url)).to be_falsey
|
209
209
|
end
|
210
210
|
it "delegates response code != 204 or 404 to client" do
|
211
211
|
response = Typhoeus::Response.new :code => 500
|
212
|
-
Harpy.client.
|
213
|
-
Harpy.client.
|
212
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
213
|
+
expect(Harpy.client).to receive(:invalid_code).with response
|
214
214
|
Harpy::Spec::Company.delete_from_url url
|
215
215
|
end
|
216
216
|
end
|
@@ -218,9 +218,9 @@ describe "class including Harpy::Resource" do
|
|
218
218
|
describe ".delete_from_urn(urn)" do
|
219
219
|
context "when entry point is not set" do
|
220
220
|
it "raises Harpy::EntryPointRequired" do
|
221
|
-
|
221
|
+
expect{
|
222
222
|
Harpy::Spec::Company.delete_from_urn("urn:harpy:company:1")
|
223
|
-
}.
|
223
|
+
}.to raise_error Harpy::EntryPointRequired
|
224
224
|
end
|
225
225
|
end
|
226
226
|
context "when entry point is set" do
|
@@ -229,38 +229,38 @@ describe "class including Harpy::Resource" do
|
|
229
229
|
it "asks Harpy.entry_point to convert urn to url then call .from_url" do
|
230
230
|
# urn:harpy:company:1 -> http://localhost/company/1
|
231
231
|
Harpy.entry_point = double
|
232
|
-
Harpy.entry_point.
|
232
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn).and_return url
|
233
233
|
|
234
234
|
# http://localhost/company/1 -> Harpy::Spec::Company instance
|
235
|
-
Harpy::Spec::Company.
|
236
|
-
Harpy::Spec::Company.delete_from_urn(urn).
|
235
|
+
expect(Harpy::Spec::Company).to receive(:delete_from_url).with(url).and_return(expected = double)
|
236
|
+
expect(Harpy::Spec::Company.delete_from_urn(urn)).to be expected
|
237
237
|
end
|
238
238
|
it "is nil if urn is not found" do
|
239
239
|
# urn:harpy:company:1 -> nil
|
240
240
|
Harpy.entry_point = double
|
241
|
-
Harpy.entry_point.
|
241
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn)
|
242
242
|
|
243
|
-
Harpy::Spec::Company.delete_from_urn(urn).
|
243
|
+
expect(Harpy::Spec::Company.delete_from_urn(urn)).to be_falsey
|
244
244
|
end
|
245
245
|
end
|
246
246
|
end
|
247
247
|
describe ".delete_from_id(id)" do
|
248
248
|
context "when urn has not been overriden" do
|
249
249
|
it "raises NotImplementedError" do
|
250
|
-
|
250
|
+
expect{
|
251
251
|
Harpy::Spec::Company.delete_from_id(1)
|
252
|
-
}.
|
252
|
+
}.to raise_error NotImplementedError
|
253
253
|
end
|
254
254
|
end
|
255
255
|
context "when urn has been overriden but entry point is not set" do
|
256
256
|
let(:urn) { "urn:harpy:company:1" }
|
257
257
|
it "raises Harpy::EntryPointRequired" do
|
258
258
|
# 1 -> urn:harpy:company:1
|
259
|
-
Harpy::Spec::Company.
|
259
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
260
260
|
|
261
|
-
|
261
|
+
expect{
|
262
262
|
Harpy::Spec::Company.delete_from_id(1)
|
263
|
-
}.
|
263
|
+
}.to raise_error Harpy::EntryPointRequired
|
264
264
|
end
|
265
265
|
end
|
266
266
|
context "when entry point is set and urn has been overriden" do
|
@@ -268,45 +268,45 @@ describe "class including Harpy::Resource" do
|
|
268
268
|
let(:url) { "http://localhost/company/1" }
|
269
269
|
it "asks Harpy.entry_point to convert urn to url then call .from_url" do
|
270
270
|
# 1 -> urn:harpy:company:1
|
271
|
-
Harpy::Spec::Company.
|
271
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
272
272
|
|
273
273
|
# urn:harpy:company:1 -> http://localhost/company/1
|
274
274
|
Harpy.entry_point = double
|
275
|
-
Harpy.entry_point.
|
275
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn).and_return url
|
276
276
|
|
277
277
|
# http://localhost/company/1 -> Harpy::Spec::Company instance
|
278
|
-
Harpy::Spec::Company.
|
279
|
-
Harpy::Spec::Company.delete_from_id(1).
|
278
|
+
expect(Harpy::Spec::Company).to receive(:delete_from_url).with(url).and_return(expected = double)
|
279
|
+
expect(Harpy::Spec::Company.delete_from_id(1)).to be expected
|
280
280
|
end
|
281
281
|
it "is nil if urn is not found" do
|
282
282
|
# 1 -> urn:harpy:company:1
|
283
|
-
Harpy::Spec::Company.
|
283
|
+
expect(Harpy::Spec::Company).to receive(:urn).with(1).and_return urn
|
284
284
|
|
285
285
|
# urn:harpy:company:1 -> nil
|
286
286
|
Harpy.entry_point = double
|
287
|
-
Harpy.entry_point.
|
287
|
+
expect(Harpy.entry_point).to receive(:urn).with(urn)
|
288
288
|
|
289
|
-
Harpy::Spec::Company.delete_from_id(1).
|
289
|
+
expect(Harpy::Spec::Company.delete_from_id(1)).to be_falsey
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
293
293
|
describe ".urn(id)" do
|
294
294
|
it "raises NotImplementedError" do
|
295
|
-
|
295
|
+
expect{
|
296
296
|
Harpy::Spec::Company.urn(1)
|
297
|
-
}.
|
297
|
+
}.to raise_error NotImplementedError
|
298
298
|
end
|
299
299
|
end
|
300
300
|
describe ".resource_name" do
|
301
301
|
it "defaults to underscored class name" do
|
302
|
-
Harpy::Spec::Company.resource_name.
|
302
|
+
expect(Harpy::Spec::Company.resource_name).to eq("harpy/spec/company")
|
303
303
|
end
|
304
304
|
end
|
305
305
|
describe ".search(conditions)" do
|
306
306
|
let(:url){ "http://localhost/company" }
|
307
307
|
before do
|
308
308
|
Harpy.entry_point = double
|
309
|
-
Harpy.entry_point.
|
309
|
+
expect(Harpy.entry_point).to receive(:resource_url).with("harpy/spec/company").and_return url
|
310
310
|
end
|
311
311
|
it "return properly filled instances on 200" do
|
312
312
|
response = Typhoeus::Response.new :code => 200, :body => <<-eos
|
@@ -325,31 +325,31 @@ describe "class including Harpy::Resource" do
|
|
325
325
|
]
|
326
326
|
}
|
327
327
|
eos
|
328
|
-
Harpy.client.
|
328
|
+
expect(Harpy.client).to receive(:get).with(url, :params => {"firstname" => "Anthony"}).and_return response
|
329
329
|
companies = Harpy::Spec::Company.search "firstname" => "Anthony"
|
330
|
-
companies.
|
331
|
-
companies.
|
332
|
-
companies.
|
333
|
-
companies.first.
|
334
|
-
companies.first.firstname.
|
335
|
-
companies.first.id.
|
336
|
-
companies.url.
|
337
|
-
companies.each do |company|
|
338
|
-
company.firstname.
|
339
|
-
end.
|
340
|
-
companies.each.
|
341
|
-
companies.to_a.
|
342
|
-
companies.detect{ true }.
|
343
|
-
companies.
|
344
|
-
companies.
|
330
|
+
expect(companies).to be_kind_of Harpy::Collection
|
331
|
+
expect(companies.size).to eq(1)
|
332
|
+
expect(companies.size).to eq(1)
|
333
|
+
expect(companies.first).to be_kind_of Harpy::Spec::Company
|
334
|
+
expect(companies.first.firstname).to eq("Anthony")
|
335
|
+
expect(companies.first.id).to eq("1")
|
336
|
+
expect(companies.url).to eq(url)
|
337
|
+
expect(companies.each do |company|
|
338
|
+
expect(company.firstname).to eq("Anthony")
|
339
|
+
end).to be_kind_of Array
|
340
|
+
expect(companies.each).to be_kind_of(defined?(Enumerator) ? Enumerator : Enumerable::Enumerator)
|
341
|
+
expect(companies.to_a).to eq([companies.first])
|
342
|
+
expect(companies.detect{ true }).to be companies.first
|
343
|
+
expect(companies.present?).to be true
|
344
|
+
expect(companies.blank?).not_to be true
|
345
345
|
companies.replace []
|
346
|
-
companies.
|
347
|
-
companies.
|
346
|
+
expect(companies.present?).not_to be true
|
347
|
+
expect(companies.blank?).to be true
|
348
348
|
end
|
349
349
|
it "delegates other response codes to client" do
|
350
350
|
response = Typhoeus::Response.new :code => 500
|
351
|
-
Harpy.client.
|
352
|
-
Harpy.client.
|
351
|
+
expect(Harpy.client).to receive(:get).with(url, :params => {}).and_return response
|
352
|
+
expect(Harpy.client).to receive(:invalid_code).with response
|
353
353
|
Harpy::Spec::Company.search
|
354
354
|
end
|
355
355
|
end
|
@@ -357,8 +357,8 @@ describe "class including Harpy::Resource" do
|
|
357
357
|
let(:url){ "http://localhost/user/1/company" }
|
358
358
|
it "overrides url used for searches" do
|
359
359
|
response = Typhoeus::Response.new :code => 500
|
360
|
-
Harpy.client.
|
361
|
-
Harpy.client.
|
360
|
+
expect(Harpy.client).to receive(:get).with(url, :params => {}).and_return response
|
361
|
+
expect(Harpy.client).to receive(:invalid_code).with response
|
362
362
|
Harpy::Spec::Company.with_url(url) do
|
363
363
|
Harpy::Spec::Company.search
|
364
364
|
end
|
@@ -366,9 +366,9 @@ describe "class including Harpy::Resource" do
|
|
366
366
|
it "can be nested" do
|
367
367
|
url2 = "http://localhost/user/2/company"
|
368
368
|
response = Typhoeus::Response.new :code => 500
|
369
|
-
Harpy.client.
|
370
|
-
Harpy.client.
|
371
|
-
Harpy.client.
|
369
|
+
expect(Harpy.client).to receive(:get).ordered.with(url2, :params => {}).and_return response
|
370
|
+
expect(Harpy.client).to receive(:get).ordered.with(url, :params => {}).and_return response
|
371
|
+
expect(Harpy.client).to receive(:invalid_code).twice.with response
|
372
372
|
Harpy::Spec::Company.with_url(url) do
|
373
373
|
Harpy::Spec::Company.with_url(url2) do
|
374
374
|
Harpy::Spec::Company.search
|
@@ -380,43 +380,43 @@ describe "class including Harpy::Resource" do
|
|
380
380
|
describe "mass assignment" do
|
381
381
|
it "sets any attribute on initialization" do
|
382
382
|
company = Harpy::Spec::Company.new "name" => "Harpy Ltd"
|
383
|
-
company.name.
|
383
|
+
expect(company.name).to eq("Harpy Ltd")
|
384
384
|
end
|
385
385
|
it "initialization works with string keys only" do
|
386
386
|
company = Harpy::Spec::Company.new :name => "Harpy Ltd"
|
387
|
-
company.name.
|
387
|
+
expect(company.name).to be_nil
|
388
388
|
end
|
389
389
|
it "#attributes=(attrs) merges new attributes with previous ones" do
|
390
390
|
company = Harpy::Spec::Company.new "name" => "Harpy Ltd", "deleted" => false
|
391
391
|
company.attributes = {"name" => "Harpy Inc", "custom" => true}
|
392
|
-
company.name.
|
393
|
-
company.deleted.
|
394
|
-
company.custom.
|
392
|
+
expect(company.name).to eql "Harpy Inc"
|
393
|
+
expect(company.deleted).to be_falsey
|
394
|
+
expect(company.custom).to be_truthy
|
395
395
|
end
|
396
396
|
it "#attributes=(attrs) works with string keys only" do
|
397
397
|
company = Harpy::Spec::Company.new "name" => "Harpy Ltd"
|
398
398
|
company.attributes = {:name => "Harpy Inc"}
|
399
|
-
company.name.
|
399
|
+
expect(company.name).to eql "Harpy Ltd"
|
400
400
|
end
|
401
401
|
it "doesn't define writers for each attribute" do
|
402
402
|
company = Harpy::Spec::Company.new "name" => "Harpy Ltd"
|
403
|
-
|
404
|
-
|
403
|
+
expect{ company.name = "test" }.to raise_error NoMethodError
|
404
|
+
expect{ company[1] }.to raise_error NoMethodError
|
405
405
|
end
|
406
406
|
it "allows accessing undefined attributes when not persisted" do
|
407
|
-
subject.name.
|
407
|
+
expect(subject.name).to be_nil
|
408
408
|
end
|
409
409
|
it "doesn't allows accessing undefined attributes when not persisted" do
|
410
|
-
subject.
|
411
|
-
|
410
|
+
expect(subject).to receive(:persisted?).and_return true
|
411
|
+
expect{ subject.name }.to raise_error NoMethodError
|
412
412
|
end
|
413
413
|
it "use existing setters if available" do
|
414
414
|
company = Harpy::Spec::Company.new "tax_id" => "123"
|
415
|
-
company.tax_id.
|
416
|
-
company.as_json.
|
415
|
+
expect(company.tax_id).to eq("123")
|
416
|
+
expect(company.as_json).to eq({})
|
417
417
|
company.attributes = {:tax_id => 123}
|
418
|
-
company.tax_id.
|
419
|
-
company.as_json.
|
418
|
+
expect(company.tax_id).to eq(123)
|
419
|
+
expect(company.as_json).to eq({})
|
420
420
|
end
|
421
421
|
end
|
422
422
|
describe "advanced attribute readers" do
|
@@ -424,111 +424,111 @@ describe "class including Harpy::Resource" do
|
|
424
424
|
subject{ Harpy::Spec::Company.new "link" => [{"rel" => "self", "href" => url}] }
|
425
425
|
describe "#link(rel)" do
|
426
426
|
it "searches link with matching rel and return href" do
|
427
|
-
subject.link("self").
|
427
|
+
expect(subject.link("self")).to eq(url)
|
428
428
|
end
|
429
429
|
it "works with symbols too" do
|
430
|
-
subject.link(:self).
|
430
|
+
expect(subject.link(:self)).to eq(url)
|
431
431
|
end
|
432
432
|
it "is nil if no matching link can be found" do
|
433
|
-
subject.link("user").
|
433
|
+
expect(subject.link("user")).to be_nil
|
434
434
|
end
|
435
435
|
end
|
436
436
|
describe "#url" do
|
437
437
|
it "searches url to self inside links" do
|
438
|
-
subject.
|
439
|
-
subject.url.
|
438
|
+
expect(subject).to receive(:link).with("self").and_return (expected = double)
|
439
|
+
expect(subject.url).to be expected
|
440
440
|
end
|
441
441
|
it "is nil when no link to self can be found" do
|
442
|
-
subject.
|
443
|
-
subject.url.
|
442
|
+
expect(subject).to receive(:link).with "self"
|
443
|
+
expect(subject.url).to be_nil
|
444
444
|
end
|
445
445
|
end
|
446
446
|
describe "#url_collection" do
|
447
447
|
it "defaults to entry_point link which rel matches resource name" do
|
448
448
|
Harpy.entry_point = double
|
449
|
-
Harpy.entry_point.
|
450
|
-
subject.url_collection.
|
449
|
+
expect(Harpy.entry_point).to receive(:resource_url).with("harpy/spec/company").and_return (expected = double)
|
450
|
+
expect(subject.url_collection).to be expected
|
451
451
|
end
|
452
452
|
end
|
453
453
|
describe "#id" do
|
454
454
|
it "extracts last part from urn" do
|
455
455
|
company = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
|
456
|
-
company.id.
|
456
|
+
expect(company.id).to eq("1")
|
457
457
|
end
|
458
458
|
it "works with alphanumeric ids too" do
|
459
459
|
company = Harpy::Spec::Company.new "urn" => "urn:harpy:company:e{39,^"
|
460
|
-
company.id.
|
460
|
+
expect(company.id).to eq("e{39,^")
|
461
461
|
end
|
462
462
|
it "works with urns having more than 4 parts" do
|
463
463
|
company = Harpy::Spec::Company.new "urn" => "urn:harpy:api:company:1"
|
464
|
-
company.id.
|
464
|
+
expect(company.id).to eq("1")
|
465
465
|
end
|
466
466
|
it "is nil without urn" do
|
467
|
-
subject.id.
|
467
|
+
expect(subject.id).to be_nil
|
468
468
|
end
|
469
469
|
it "is nil if urn is an empty string" do
|
470
470
|
company = Harpy::Spec::Company.new "urn" => ""
|
471
|
-
company.id.
|
471
|
+
expect(company.id).to be_nil
|
472
472
|
end
|
473
473
|
it "never uses manually assigned id attribute" do
|
474
474
|
company = Harpy::Spec::Company.new "id" => "1"
|
475
|
-
company.id.
|
475
|
+
expect(company.id).to be_nil
|
476
476
|
end
|
477
477
|
end
|
478
478
|
describe "#persisted?" do
|
479
479
|
it "defaults to false when no urn is defined" do
|
480
480
|
company = Harpy::Spec::Company.new
|
481
|
-
company.persisted
|
481
|
+
expect(company.persisted?).to be_falsey
|
482
482
|
end
|
483
483
|
it "is true when an urn is present" do
|
484
484
|
company = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
|
485
|
-
company.persisted
|
485
|
+
expect(company.persisted?).to be_truthy
|
486
486
|
end
|
487
487
|
it "is false when urn is an empty string" do
|
488
488
|
company = Harpy::Spec::Company.new "urn" => ""
|
489
|
-
company.persisted
|
489
|
+
expect(company.persisted?).to be_falsey
|
490
490
|
end
|
491
491
|
end
|
492
492
|
describe "#inspect" do
|
493
493
|
subject { Harpy::Spec::Company.new "firstname" => "Anthony" }
|
494
494
|
it "shows class name, attributes, errors and persisted state" do
|
495
|
-
subject.inspect.
|
495
|
+
expect(subject.inspect).to eq('<Harpy::Spec::Company @attrs:{"firstname"=>"Anthony"} @errors:[] persisted:false>')
|
496
496
|
end
|
497
497
|
end
|
498
498
|
describe "#has_key?(key)" do
|
499
499
|
it "is true when attribute is present" do
|
500
|
-
subject.has_key?("link").
|
500
|
+
expect(subject.has_key?("link")).to be_truthy
|
501
501
|
end
|
502
502
|
it "does accept symbols too" do
|
503
|
-
subject.has_key?(:link).
|
503
|
+
expect(subject.has_key?(:link)).to be_truthy
|
504
504
|
end
|
505
505
|
it "is true when attribute is an empty string" do
|
506
506
|
company = Harpy::Spec::Company.new "urn" => ""
|
507
|
-
company.has_key?("urn").
|
507
|
+
expect(company.has_key?("urn")).to be_truthy
|
508
508
|
end
|
509
509
|
it "is false when attribute is not defined" do
|
510
|
-
subject.has_key?("custom").
|
510
|
+
expect(subject.has_key?("custom")).to be_falsey
|
511
511
|
end
|
512
512
|
it "is false when key matches an existing method but not an attribute" do
|
513
|
-
subject.has_key?(:url).
|
513
|
+
expect(subject.has_key?(:url)).to be_falsey
|
514
514
|
end
|
515
515
|
it "does not raise error when checking for an undefined attribute even when persisted" do
|
516
|
-
subject.
|
517
|
-
subject.has_key?("custom").
|
516
|
+
allow(subject).to receive(:persisted?).and_return true
|
517
|
+
expect(subject.has_key?("custom")).to be_falsey
|
518
518
|
end
|
519
519
|
end
|
520
520
|
end
|
521
521
|
describe "#valid?" do
|
522
522
|
it "has ActiveModel validations" do
|
523
523
|
user = Harpy::Spec::User.new "lastname" => "Stark"
|
524
|
-
user.
|
525
|
-
user.
|
526
|
-
user.errors[:firstname].
|
524
|
+
expect(user).not_to be_valid
|
525
|
+
expect(user.errors.size).to eq(1)
|
526
|
+
expect(user.errors[:firstname]).to match_array(["can't be blank"])
|
527
527
|
end
|
528
|
-
it "calls before_validation which prevents validation on
|
528
|
+
it "calls before_validation which prevents validation on throw" do
|
529
529
|
user = Harpy::Spec::User.new
|
530
|
-
user.
|
531
|
-
user.
|
530
|
+
expect(user).not_to be_valid
|
531
|
+
expect(user.errors.size).to eq(0)
|
532
532
|
end
|
533
533
|
end
|
534
534
|
describe "#as_json" do
|
@@ -542,27 +542,27 @@ describe "class including Harpy::Resource" do
|
|
542
542
|
end
|
543
543
|
|
544
544
|
it "exclude link and urn from attributes" do
|
545
|
-
subject.as_json.
|
545
|
+
expect(subject.as_json).to eq({"company_name" => "Stark Enterprises"})
|
546
546
|
end
|
547
547
|
it "does not remove link and urn from object attributes" do
|
548
548
|
subject.as_json
|
549
|
-
subject.urn.
|
550
|
-
subject.url.
|
549
|
+
expect(subject.urn).to eq("urn:harpy:user:1")
|
550
|
+
expect(subject.url).to eq(url)
|
551
551
|
end
|
552
552
|
end
|
553
553
|
describe "#save" do
|
554
554
|
subject{ Harpy::Spec::User.new "company_name" => "Stark Enterprises" }
|
555
555
|
it "is false and does not call before_save callback if not valid" do
|
556
|
-
subject.
|
557
|
-
subject.save.
|
558
|
-
subject.callbacks.
|
556
|
+
expect(subject).to receive :valid?
|
557
|
+
expect(subject.save).to be_falsey
|
558
|
+
expect(subject.callbacks).to match_array([])
|
559
559
|
end
|
560
560
|
context "on create (valid, not persisted)" do
|
561
561
|
let(:url) { "http://localhost/user" }
|
562
562
|
let(:body) { '{"company_name":"Stark Enterprises"}' }
|
563
563
|
before do
|
564
|
-
subject.
|
565
|
-
subject.
|
564
|
+
expect(subject).to receive(:valid?).and_return true
|
565
|
+
expect(subject).to receive(:url_collection).and_return url
|
566
566
|
end
|
567
567
|
[200, 201, 302].each do |response_code|
|
568
568
|
it "is true and merges response attributes on #{response_code}" do
|
@@ -575,25 +575,25 @@ describe "class including Harpy::Resource" do
|
|
575
575
|
]
|
576
576
|
}
|
577
577
|
eos
|
578
|
-
Harpy.client.
|
579
|
-
subject.save.
|
580
|
-
subject.callbacks.
|
581
|
-
subject.firstname.
|
582
|
-
subject.company_name.
|
583
|
-
subject.urn.
|
578
|
+
expect(Harpy.client).to receive(:post).with(url, :body => body).and_return response
|
579
|
+
expect(subject.save).to be_truthy
|
580
|
+
expect(subject.callbacks).to match_array([:save, :create])
|
581
|
+
expect(subject.firstname).to eq("Anthony")
|
582
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
583
|
+
expect(subject.urn).to eq("urn:harpy:user:1")
|
584
584
|
end
|
585
585
|
end
|
586
586
|
it "raises Harpy::InvalidResponseCode on 204" do
|
587
587
|
response = Typhoeus::Response.new :code => 204
|
588
|
-
Harpy.client.
|
589
|
-
|
590
|
-
subject.callbacks.
|
588
|
+
expect(Harpy.client).to receive(:post).with(url, :body => body).and_return response
|
589
|
+
expect { subject.save }.to raise_error Harpy::InvalidResponseCode, "204"
|
590
|
+
expect(subject.callbacks).to match_array([:save, :create])
|
591
591
|
end
|
592
592
|
it "raises Harpy::Unauthorized on 401" do
|
593
593
|
response = Typhoeus::Response.new :code => 401
|
594
|
-
Harpy.client.
|
595
|
-
|
596
|
-
subject.callbacks.
|
594
|
+
expect(Harpy.client).to receive(:post).with(url, :body => body).and_return response
|
595
|
+
expect { subject.save }.to raise_error Harpy::Unauthorized, "Server returned a 401 response code"
|
596
|
+
expect(subject.callbacks).to match_array([:save, :create])
|
597
597
|
end
|
598
598
|
it "is false and fills in errors on 422" do
|
599
599
|
response = Typhoeus::Response.new :code => 422, :body => <<-eos
|
@@ -604,28 +604,28 @@ describe "class including Harpy::Resource" do
|
|
604
604
|
}
|
605
605
|
}
|
606
606
|
eos
|
607
|
-
Harpy.client.
|
608
|
-
subject.save.
|
609
|
-
subject.callbacks.
|
610
|
-
subject.
|
611
|
-
subject.errors[:lastname].
|
612
|
-
subject.firstname.
|
613
|
-
subject.company_name.
|
607
|
+
expect(Harpy.client).to receive(:post).with(url, :body => body).and_return response
|
608
|
+
expect(subject.save).to be_falsey
|
609
|
+
expect(subject.callbacks).to match_array([:save, :create])
|
610
|
+
expect(subject.errors.size).to eq(2)
|
611
|
+
expect(subject.errors[:lastname]).to match_array(["can't be blank", "must be unique"])
|
612
|
+
expect(subject.firstname).to be_nil
|
613
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
614
614
|
end
|
615
615
|
it "delegates other response codes to client" do
|
616
616
|
response = Typhoeus::Response.new :code => 500
|
617
|
-
Harpy.client.
|
618
|
-
Harpy.client.
|
617
|
+
expect(Harpy.client).to receive(:post).with(url, :body => body).and_return response
|
618
|
+
expect(Harpy.client).to receive(:invalid_code).with(response)
|
619
619
|
subject.save
|
620
|
-
subject.callbacks.
|
620
|
+
expect(subject.callbacks).to match_array([:save, :create])
|
621
621
|
end
|
622
622
|
end
|
623
623
|
context "on update (valid, persisted but link to self is not present)" do
|
624
624
|
it "raises Harpy::UrlRequired" do
|
625
|
-
subject.
|
626
|
-
subject.
|
627
|
-
|
628
|
-
subject.callbacks.
|
625
|
+
expect(subject).to receive(:valid?).and_return true
|
626
|
+
expect(subject).to receive(:persisted?).and_return true
|
627
|
+
expect{ subject.save }.to raise_error Harpy::UrlRequired
|
628
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
629
629
|
end
|
630
630
|
end
|
631
631
|
context "on update (valid, persisted and link to self is present)" do
|
@@ -639,7 +639,7 @@ describe "class including Harpy::Resource" do
|
|
639
639
|
})
|
640
640
|
end
|
641
641
|
before do
|
642
|
-
subject.
|
642
|
+
expect(subject).to receive(:valid?).and_return true
|
643
643
|
end
|
644
644
|
[200, 201, 302].each do |response_code|
|
645
645
|
it "is true and merges response attributes on #{response_code}" do
|
@@ -652,25 +652,25 @@ describe "class including Harpy::Resource" do
|
|
652
652
|
]
|
653
653
|
}
|
654
654
|
eos
|
655
|
-
Harpy.client.
|
656
|
-
subject.save.
|
657
|
-
subject.callbacks.
|
658
|
-
subject.firstname.
|
659
|
-
subject.company_name.
|
655
|
+
expect(Harpy.client).to receive(:put).with(url, :body => body).and_return response
|
656
|
+
expect(subject.save).to be_truthy
|
657
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
658
|
+
expect(subject.firstname).to eq("Anthony")
|
659
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
660
660
|
end
|
661
661
|
end
|
662
662
|
it "is true but doesn't touch attributes on 204" do
|
663
663
|
response = Typhoeus::Response.new :code => 204
|
664
|
-
Harpy.client.
|
665
|
-
subject.save.
|
666
|
-
subject.callbacks.
|
667
|
-
subject.company_name.
|
664
|
+
expect(Harpy.client).to receive(:put).with(url, :body => body).and_return response
|
665
|
+
expect(subject.save).to be_truthy
|
666
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
667
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
668
668
|
end
|
669
669
|
it "raises Harpy::Unauthorized on 401" do
|
670
670
|
response = Typhoeus::Response.new :code => 401
|
671
|
-
Harpy.client.
|
672
|
-
|
673
|
-
subject.callbacks.
|
671
|
+
expect(Harpy.client).to receive(:put).with(url, :body => body).and_return response
|
672
|
+
expect { subject.save }.to raise_error Harpy::Unauthorized, "Server returned a 401 response code"
|
673
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
674
674
|
end
|
675
675
|
it "is false and fills in errors on 422" do
|
676
676
|
response = Typhoeus::Response.new :code => 422, :body => <<-eos
|
@@ -681,20 +681,20 @@ describe "class including Harpy::Resource" do
|
|
681
681
|
}
|
682
682
|
}
|
683
683
|
eos
|
684
|
-
Harpy.client.
|
685
|
-
subject.save.
|
686
|
-
subject.callbacks.
|
687
|
-
subject.
|
688
|
-
subject.errors[:lastname].
|
689
|
-
|
690
|
-
subject.company_name.
|
684
|
+
expect(Harpy.client).to receive(:put).with(url, :body => body).and_return response
|
685
|
+
expect(subject.save).to be_falsey
|
686
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
687
|
+
expect(subject.errors.size).to eq(2)
|
688
|
+
expect(subject.errors[:lastname]).to match_array(["can't be blank", "must be unique"])
|
689
|
+
expect { subject.firstname }.to raise_error NoMethodError
|
690
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
691
691
|
end
|
692
692
|
it "delegates other response codes to client" do
|
693
693
|
response = Typhoeus::Response.new :code => 500
|
694
|
-
Harpy.client.
|
695
|
-
Harpy.client.
|
694
|
+
expect(Harpy.client).to receive(:put).with(url, :body => body).and_return response
|
695
|
+
expect(Harpy.client).to receive(:invalid_code).with(response)
|
696
696
|
subject.save
|
697
|
-
subject.callbacks.
|
697
|
+
expect(subject.callbacks).to match_array([:save, :update])
|
698
698
|
end
|
699
699
|
end
|
700
700
|
end
|
@@ -702,8 +702,8 @@ describe "class including Harpy::Resource" do
|
|
702
702
|
subject{ Harpy::Spec::User.new "company_name" => "Stark Enterprises" }
|
703
703
|
context "when link to self is missing" do
|
704
704
|
it "raises Harpy::UrlRequired" do
|
705
|
-
|
706
|
-
subject.callbacks.
|
705
|
+
expect{ subject.destroy }.to raise_error Harpy::UrlRequired
|
706
|
+
expect(subject.callbacks).to match_array([])
|
707
707
|
end
|
708
708
|
end
|
709
709
|
context "when link to self is present" do
|
@@ -726,25 +726,25 @@ describe "class including Harpy::Resource" do
|
|
726
726
|
]
|
727
727
|
}
|
728
728
|
eos
|
729
|
-
Harpy.client.
|
730
|
-
subject.destroy.
|
731
|
-
subject.callbacks.
|
732
|
-
subject.firstname.
|
733
|
-
subject.company_name.
|
729
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
730
|
+
expect(subject.destroy).to be_truthy
|
731
|
+
expect(subject.callbacks).to match_array([:destroy])
|
732
|
+
expect(subject.firstname).to eq("Anthony")
|
733
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
734
734
|
end
|
735
735
|
end
|
736
736
|
it "is true but doesn't touch attributes on 204" do
|
737
737
|
response = Typhoeus::Response.new :code => 204
|
738
|
-
Harpy.client.
|
739
|
-
subject.destroy.
|
740
|
-
subject.callbacks.
|
741
|
-
subject.company_name.
|
738
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
739
|
+
expect(subject.destroy).to be_truthy
|
740
|
+
expect(subject.callbacks).to match_array([:destroy])
|
741
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
742
742
|
end
|
743
743
|
it "raises Harpy::Unauthorized on 401" do
|
744
744
|
response = Typhoeus::Response.new :code => 401
|
745
|
-
Harpy.client.
|
746
|
-
|
747
|
-
subject.callbacks.
|
745
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
746
|
+
expect { subject.destroy }.to raise_error Harpy::Unauthorized, "Server returned a 401 response code"
|
747
|
+
expect(subject.callbacks).to match_array([:destroy])
|
748
748
|
end
|
749
749
|
it "is false and fills in errors on 422" do
|
750
750
|
response = Typhoeus::Response.new :code => 422, :body => <<-eos
|
@@ -755,20 +755,20 @@ describe "class including Harpy::Resource" do
|
|
755
755
|
}
|
756
756
|
}
|
757
757
|
eos
|
758
|
-
Harpy.client.
|
759
|
-
subject.destroy.
|
760
|
-
subject.callbacks.
|
761
|
-
subject.
|
762
|
-
subject.errors[:lastname].
|
763
|
-
|
764
|
-
subject.company_name.
|
758
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
759
|
+
expect(subject.destroy).to be_falsey
|
760
|
+
expect(subject.callbacks).to match_array([:destroy])
|
761
|
+
expect(subject.errors.size).to eq(2)
|
762
|
+
expect(subject.errors[:lastname]).to match_array(["can't be blank", "must be unique"])
|
763
|
+
expect { subject.firstname }.to raise_error NoMethodError
|
764
|
+
expect(subject.company_name).to eq("Stark Enterprises")
|
765
765
|
end
|
766
766
|
it "delegates other response codes to client" do
|
767
767
|
response = Typhoeus::Response.new :code => 500
|
768
|
-
Harpy.client.
|
769
|
-
Harpy.client.
|
768
|
+
expect(Harpy.client).to receive(:delete).with(url).and_return response
|
769
|
+
expect(Harpy.client).to receive(:invalid_code).with(response)
|
770
770
|
subject.destroy
|
771
|
-
subject.callbacks.
|
771
|
+
expect(subject.callbacks).to match_array([:destroy])
|
772
772
|
end
|
773
773
|
end
|
774
774
|
end
|
@@ -776,22 +776,22 @@ describe "class including Harpy::Resource" do
|
|
776
776
|
it "is equal to itself even without urn" do
|
777
777
|
company1 = Harpy::Spec::Company.new
|
778
778
|
company2 = company1
|
779
|
-
company1.
|
779
|
+
expect(company1).to eq(company2)
|
780
780
|
end
|
781
781
|
it "two instances without urn are not equal" do
|
782
782
|
company1 = Harpy::Spec::Company.new
|
783
783
|
company2 = Harpy::Spec::Company.new
|
784
|
-
company1.
|
784
|
+
expect(company1).not_to eq(company2)
|
785
785
|
end
|
786
786
|
it "two instances of the same class with the same urn are equal" do
|
787
787
|
company1 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
|
788
788
|
company2 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
|
789
|
-
company1.
|
789
|
+
expect(company1).to eq(company2)
|
790
790
|
end
|
791
791
|
it "two instances of the same class with different urns are not equal" do
|
792
792
|
company1 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
|
793
793
|
company2 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:2"
|
794
|
-
company1.
|
794
|
+
expect(company1).not_to eq(company2)
|
795
795
|
end
|
796
796
|
end
|
797
797
|
end
|