crowdkit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +20 -0
- data/README.md +178 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/crowdkit.gemspec +122 -0
- data/lib/crowdkit.rb +77 -0
- data/lib/crowdkit/api.rb +171 -0
- data/lib/crowdkit/api/arguments.rb +187 -0
- data/lib/crowdkit/api/factory.rb +29 -0
- data/lib/crowdkit/api/request_methods.rb +70 -0
- data/lib/crowdkit/api/response_wrapper.rb +122 -0
- data/lib/crowdkit/client.rb +36 -0
- data/lib/crowdkit/client/account.rb +7 -0
- data/lib/crowdkit/client/jobs.rb +56 -0
- data/lib/crowdkit/client/judgments.rb +9 -0
- data/lib/crowdkit/client/poll.rb +48 -0
- data/lib/crowdkit/client/statuses.rb +14 -0
- data/lib/crowdkit/client/units.rb +54 -0
- data/lib/crowdkit/client/workers.rb +13 -0
- data/lib/crowdkit/client/worksets.rb +27 -0
- data/lib/crowdkit/config.rb +62 -0
- data/lib/crowdkit/core_ext/array.rb +7 -0
- data/lib/crowdkit/core_ext/hash.rb +30 -0
- data/lib/crowdkit/core_ext/sawyer.rb +7 -0
- data/lib/crowdkit/error.rb +198 -0
- data/lib/crowdkit/middleware/raise_error.rb +14 -0
- data/lib/crowdkit/ssl_certs/cacerts.pem +3868 -0
- data/lib/crowdkit/version.rb +3 -0
- data/spec/crowdkit/client/account_spec.rb +19 -0
- data/spec/crowdkit/client/jobs_spec.rb +275 -0
- data/spec/crowdkit/client/judgments_spec.rb +30 -0
- data/spec/crowdkit/client/statuses_spec.rb +30 -0
- data/spec/crowdkit/client/units_spec.rb +266 -0
- data/spec/crowdkit/client/workers_spec.rb +33 -0
- data/spec/crowdkit/client/worksets_spec.rb +113 -0
- data/spec/crowdkit/client_spec.rb +55 -0
- data/spec/crowdkit_spec.rb +139 -0
- data/spec/fixtures/account.json +7 -0
- data/spec/fixtures/jobs/copy.json +79 -0
- data/spec/fixtures/jobs/job.json +1 -0
- data/spec/fixtures/jobs/order.json +53 -0
- data/spec/fixtures/jobs/search.json +1 -0
- data/spec/fixtures/judgments/index.json +46 -0
- data/spec/fixtures/judgments/show.json +16 -0
- data/spec/fixtures/root.json +1 -0
- data/spec/fixtures/statuses/index.json +25 -0
- data/spec/fixtures/statuses/status.json +12 -0
- data/spec/fixtures/units/copy.json +34 -0
- data/spec/fixtures/units/index.json +1502 -0
- data/spec/fixtures/units/poll/normal.json +902 -0
- data/spec/fixtures/units/poll/small.json +602 -0
- data/spec/fixtures/units/show.json +34 -0
- data/spec/fixtures/upload.csv +25 -0
- data/spec/fixtures/worksets/index.json +20 -0
- data/spec/fixtures/worksets/show.json +9 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/base.rb +11 -0
- metadata +218 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Crowdkit::Client::Account do
|
4
|
+
context "show" do
|
5
|
+
let!(:request_stub) { stub_get("/account").to_return(fixture_response("account.json")) }
|
6
|
+
|
7
|
+
it "send request" do
|
8
|
+
client.account.get
|
9
|
+
expect(request_stub).to have_been_requested
|
10
|
+
end
|
11
|
+
|
12
|
+
it "parse response" do
|
13
|
+
account = client.account.get
|
14
|
+
expect(account.id).to eq(1)
|
15
|
+
expect(account.data[:email]).to eq('test@test.com')
|
16
|
+
expect(account.data[:name]).to eq('Test')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Crowdkit::Client::Jobs do
|
4
|
+
context "jobs" do
|
5
|
+
context "search" do
|
6
|
+
let!(:request_stub) { stub_get(/jobs/).to_return(fixture_response("jobs/search.json")) }
|
7
|
+
|
8
|
+
context "requests" do
|
9
|
+
it "should be made" do
|
10
|
+
client.jobs.search
|
11
|
+
expect(request_stub).to have_been_requested
|
12
|
+
end
|
13
|
+
|
14
|
+
it "sets search parameter" do
|
15
|
+
client.jobs.search("Rad")
|
16
|
+
expect(a_request(:get, /jobs/).with(query: {"query" => "Rad"})).to have_been_made
|
17
|
+
end
|
18
|
+
|
19
|
+
it "passes along other parameters" do
|
20
|
+
client.jobs.search(page: 2, state: :finished)
|
21
|
+
expect(a_request(:get, /jobs/).with(query: {"page" => "2", "state" => "finished"})).to have_been_made
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has list alias" do
|
25
|
+
client.jobs.list
|
26
|
+
expect(request_stub).to have_been_requested
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has all alias" do
|
30
|
+
client.jobs.all
|
31
|
+
expect(request_stub).to have_been_requested
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "responses" do
|
36
|
+
it "parses the data" do
|
37
|
+
expect(client.jobs.search.length).to eq(5)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "executes a block" do
|
41
|
+
i = 0
|
42
|
+
client.jobs.all {|job| i += 1 }
|
43
|
+
expect(i).to eq(5)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "get" do
|
49
|
+
let!(:request_stub) { stub_get("/jobs/1").to_return(fixture_response("jobs/job.json")) }
|
50
|
+
|
51
|
+
context "request" do
|
52
|
+
it "should be made" do
|
53
|
+
client.jobs.get(1)
|
54
|
+
expect(request_stub).to have_been_requested
|
55
|
+
end
|
56
|
+
|
57
|
+
it "accepts job parameter" do
|
58
|
+
client.jobs(1).get
|
59
|
+
expect(request_stub).to have_been_requested
|
60
|
+
end
|
61
|
+
|
62
|
+
it "blows up without id" do
|
63
|
+
expect { client.jobs.get }.to raise_error Crowdkit::ValidationError
|
64
|
+
end
|
65
|
+
|
66
|
+
it "has find alias" do
|
67
|
+
client.jobs.find(1)
|
68
|
+
expect(request_stub).to have_been_requested
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "response" do
|
73
|
+
it "parses" do
|
74
|
+
expect(client.jobs.get(1).id).to eq(1)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "forwards to data" do
|
78
|
+
expect(client.jobs.get(1).title).to eq("Some really awesome job that is so very very cool")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "copy" do
|
84
|
+
let!(:request_stub) { stub_post(/11\/copy/).to_return(fixture_response("jobs/copy.json", 202)) }
|
85
|
+
|
86
|
+
context "request" do
|
87
|
+
it "should be made" do
|
88
|
+
client.jobs(11).copy
|
89
|
+
expect(request_stub).to have_been_requested
|
90
|
+
end
|
91
|
+
|
92
|
+
it "passes parameters" do
|
93
|
+
client.jobs(11).copy(all_units: true)
|
94
|
+
expect(a_request(:post, /copy/).with(query: {"all_units" => "true"})).to have_been_made
|
95
|
+
end
|
96
|
+
|
97
|
+
it "blows up without id" do
|
98
|
+
expect { client.jobs.copy }.to raise_error Crowdkit::ValidationError
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "response" do
|
103
|
+
it "parses" do
|
104
|
+
expect(client.jobs.copy(11).id).to eq(12)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "is a 202" do
|
108
|
+
client.jobs(11).copy(all_units: true)
|
109
|
+
expect(client.last_response.status).to eq(202)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "provides current status" do
|
113
|
+
status = stub_get("/statuses/3d05fc4a1501dcebfb836434d8fc5cce").to_return(fixture_response("statuses/status.json"))
|
114
|
+
response = client.jobs(11).copy(all_units: true)
|
115
|
+
response.current_status
|
116
|
+
response.current_status
|
117
|
+
expect(status).to have_been_requested.twice
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "order" do
|
123
|
+
let!(:request_stub) { stub_post(/11\/order/).to_return(fixture_response("jobs/order.json", 202)) }
|
124
|
+
|
125
|
+
context "request" do
|
126
|
+
it "should be made" do
|
127
|
+
client.jobs(11).order
|
128
|
+
expect(request_stub).to have_been_requested
|
129
|
+
end
|
130
|
+
|
131
|
+
it "passes parameters" do
|
132
|
+
client.jobs(11).order(units_count: 10)
|
133
|
+
expect(a_request(:post, /order/).with(query: {"units_count" => "10"})).to have_been_made
|
134
|
+
end
|
135
|
+
|
136
|
+
it "blows up without id" do
|
137
|
+
expect { client.jobs.order }.to raise_error Crowdkit::ValidationError
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "response" do
|
142
|
+
it "parses" do
|
143
|
+
expect(client.jobs.order(11).id).to eq(1822)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "is a 202" do
|
147
|
+
client.jobs.order(units_count: 10, job_id: 11)
|
148
|
+
expect(client.last_response.status).to eq(202)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "provides current status" do
|
152
|
+
status = stub_get("/statuses/9e61a51bad819441e3d5fcfc6045b555").to_return(fixture_response("statuses/status.json"))
|
153
|
+
response = client.jobs(11).order
|
154
|
+
response.current_status
|
155
|
+
response.current_status
|
156
|
+
expect(status).to have_been_requested.twice
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "create" do
|
162
|
+
let!(:request_stub) { stub_post("/jobs").to_return(fixture_response("jobs/job.json", 201)) }
|
163
|
+
|
164
|
+
context "request" do
|
165
|
+
it "should be made" do
|
166
|
+
client.jobs.create(title: "My amazing job")
|
167
|
+
expect(request_stub).to have_been_requested
|
168
|
+
end
|
169
|
+
|
170
|
+
it "passes title in the body" do
|
171
|
+
client.jobs.create(title: "My amazing job")
|
172
|
+
expect(a_request(:post, /jobs/).with(body: {title: "My amazing job"}.to_json)).to have_been_made
|
173
|
+
end
|
174
|
+
|
175
|
+
it "blows up without title" do
|
176
|
+
expect { client.jobs.create }.to raise_error Crowdkit::ValidationError
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "response" do
|
181
|
+
it "parses" do
|
182
|
+
expect(client.jobs.create(title: "My amazing job").id).to eq(1)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "is a 201" do
|
186
|
+
client.jobs.create(title: "My amazing job")
|
187
|
+
expect(client.last_response.status).to eq(201)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "statuses" do
|
193
|
+
let!(:request_stub) { stub_get("/jobs/11/statuses").to_return(fixture_response("statuses/index.json")) }
|
194
|
+
|
195
|
+
describe "request" do
|
196
|
+
it "should be made" do
|
197
|
+
client.jobs(11).statuses
|
198
|
+
expect(request_stub).to have_been_requested
|
199
|
+
end
|
200
|
+
|
201
|
+
it "blows up without id" do
|
202
|
+
expect { client.jobs.statuses }.to raise_error Crowdkit::ValidationError
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "response" do
|
207
|
+
it "parses" do
|
208
|
+
expect(client.jobs(11).statuses.length).to eq(2)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "judgments" do
|
214
|
+
let(:get_judgments) { client.jobs(11).judgments(per_page: 3) }
|
215
|
+
let!(:request_stub) { stub_get("/jobs/11/judgments?per_page=3").to_return(fixture_response("judgments/index.json")) }
|
216
|
+
|
217
|
+
describe "request" do
|
218
|
+
it "should be made" do
|
219
|
+
get_judgments
|
220
|
+
expect(request_stub).to have_been_requested
|
221
|
+
end
|
222
|
+
|
223
|
+
it "passes parameters" do
|
224
|
+
get_judgments
|
225
|
+
expect(a_request(:get, /judgments/).with(query: {"per_page" => 3.to_s})).to have_been_made
|
226
|
+
end
|
227
|
+
|
228
|
+
it "blows up without id" do
|
229
|
+
expect { client.jobs.judgments }.to raise_error Crowdkit::ValidationError
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "response" do
|
234
|
+
it "parses" do
|
235
|
+
expect(get_judgments.length).to eq(3)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "namespaces" do
|
241
|
+
describe "units" do
|
242
|
+
it "provides association" do
|
243
|
+
expect(client.jobs.units.class).to eq(Crowdkit::Client::Units)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "passes along job_id" do
|
247
|
+
expect(client.jobs(1).units.stored_params).to eq({job_id: 1})
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "upload" do
|
253
|
+
let(:file) { fixture('upload.csv') }
|
254
|
+
let!(:request_stub) { stub_put('/jobs/1/upload').to_return(fixture_response('jobs/job.json', 201)) }
|
255
|
+
|
256
|
+
describe "request" do
|
257
|
+
it "should be made" do
|
258
|
+
client.jobs(1).upload(file)
|
259
|
+
expect(request_stub).to have_been_requested
|
260
|
+
end
|
261
|
+
|
262
|
+
it "blows up without id" do
|
263
|
+
expect { client.jobs.upload(file) }.to raise_error Crowdkit::ValidationError
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "response" do
|
268
|
+
it "parses" do
|
269
|
+
expect(client.jobs(1).upload(file).id).to eq(1)
|
270
|
+
expect(client.last_response.status).to eq(201)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Crowdkit::Client::Judgments do
|
4
|
+
context "show" do
|
5
|
+
let(:judgment_id) { 6634 }
|
6
|
+
let!(:request_stub) { stub_get("/judgments/#{judgment_id}").to_return(fixture_response("judgments/show.json")) }
|
7
|
+
|
8
|
+
context "requests" do
|
9
|
+
it "gets made" do
|
10
|
+
client.judgments.get(judgment_id)
|
11
|
+
expect(request_stub).to have_been_requested
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has find alias" do
|
15
|
+
client.judgments.find(judgment_id)
|
16
|
+
expect(request_stub).to have_been_requested
|
17
|
+
end
|
18
|
+
|
19
|
+
it "blows up without id" do
|
20
|
+
expect { client.judgments.get }.to raise_error(Crowdkit::ValidationError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "response" do
|
25
|
+
it "parses" do
|
26
|
+
expect(client.judgments.get(judgment_id).id).to eq(judgment_id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Crowdkit::Client::Statuses do
|
4
|
+
context "show" do
|
5
|
+
let(:status_id) { "4be60d841550b13d72acfb3aa0412596" }
|
6
|
+
let!(:request_stub) { stub_get("/statuses/#{status_id}").to_return(fixture_response("statuses/status.json")) }
|
7
|
+
|
8
|
+
context "requests" do
|
9
|
+
it "gets made" do
|
10
|
+
client.statuses.get(status_id)
|
11
|
+
expect(request_stub).to have_been_requested
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has find alias" do
|
15
|
+
client.statuses.find(status_id)
|
16
|
+
expect(request_stub).to have_been_requested
|
17
|
+
end
|
18
|
+
|
19
|
+
it "blows up without id" do
|
20
|
+
expect { client.statuses.get }.to raise_error Crowdkit::ValidationError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "response" do
|
25
|
+
it "parses" do
|
26
|
+
expect(client.statuses.get(status_id).id).to eq(status_id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,266 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Crowdkit::Client::Units do
|
4
|
+
context "show" do
|
5
|
+
let(:unit_id) { 47979 }
|
6
|
+
let!(:request_stub) { stub_get("/units/#{unit_id}").to_return(fixture_response("units/show.json")) }
|
7
|
+
|
8
|
+
context "requests" do
|
9
|
+
it "gets made" do
|
10
|
+
client.units.get(unit_id)
|
11
|
+
expect(request_stub).to have_been_requested
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has find alias" do
|
15
|
+
client.units.find(unit_id)
|
16
|
+
expect(request_stub).to have_been_requested
|
17
|
+
end
|
18
|
+
|
19
|
+
it "blows up without id" do
|
20
|
+
expect { client.units.get }.to raise_error Crowdkit::ValidationError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "response" do
|
25
|
+
it "parses" do
|
26
|
+
expect(client.units.get(unit_id).id).to eq(unit_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
specify "hypermedia" do
|
30
|
+
expect(client.units.get(unit_id).rels.to_hash).to eq({
|
31
|
+
self_url: "https://api.crowdflower.dev/v2/units/47979",
|
32
|
+
judgments_url: "https://api.crowdflower.dev/v2/units/47979/judgments"
|
33
|
+
})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "list" do
|
39
|
+
let!(:request_stub) { stub_get("/jobs/10/units").to_return(fixture_response("units/index.json")) }
|
40
|
+
|
41
|
+
context "requests" do
|
42
|
+
it "gets made" do
|
43
|
+
client.units(job_id: 10).list
|
44
|
+
expect(request_stub).to have_been_requested
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has all alias" do
|
48
|
+
client.units.all(job_id: 10)
|
49
|
+
expect(request_stub).to have_been_requested
|
50
|
+
end
|
51
|
+
|
52
|
+
it "blows up without job_id" do
|
53
|
+
expect { client.units.list }.to raise_error Crowdkit::ValidationError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "response" do
|
58
|
+
it "parses" do
|
59
|
+
expect(client.units(job_id: 10).list.length).to eq(50)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "create" do
|
65
|
+
let(:data) { Hash(data: {test: true}) }
|
66
|
+
let(:create_unit) { client.units(job_id: 10).create(data.dup) }
|
67
|
+
let!(:request_stub) { stub_post("/jobs/10/units").to_return(fixture_response("units/show.json", 201)) }
|
68
|
+
|
69
|
+
context "request" do
|
70
|
+
it "should be made" do
|
71
|
+
create_unit
|
72
|
+
expect(request_stub).to have_been_requested
|
73
|
+
end
|
74
|
+
|
75
|
+
it "passes data in the body" do
|
76
|
+
create_unit
|
77
|
+
expect(a_request(:post, /jobs/).with(body: data.to_json)).to have_been_made
|
78
|
+
end
|
79
|
+
|
80
|
+
it "blows up without job_id" do
|
81
|
+
expect { client.units.create }.to raise_error Crowdkit::ValidationError
|
82
|
+
end
|
83
|
+
|
84
|
+
it "support array of units data" do
|
85
|
+
units_data = [{test_1: true}, {test_2: true}]
|
86
|
+
client.units(job_id: 10).create(units_data)
|
87
|
+
expect(a_request(:post, /jobs\/10\/units/).with(body: units_data.to_json)).to have_been_made
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "response" do
|
92
|
+
it "parses" do
|
93
|
+
expect(create_unit.id).to eq(47979)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "is a 201" do
|
97
|
+
create_unit
|
98
|
+
expect(client.last_response.status).to eq(201)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "copy" do
|
104
|
+
let(:unit_id) { 47979 }
|
105
|
+
let(:destination_job_id) { 11 }
|
106
|
+
let(:copy_unit) { client.units(unit_id).copy(destination_job_id: destination_job_id) }
|
107
|
+
let!(:request_stub) do
|
108
|
+
url = "/units/#{unit_id}/copy?destination_job_id=#{destination_job_id}"
|
109
|
+
stub_post(url).to_return(fixture_response("units/copy.json", 201))
|
110
|
+
end
|
111
|
+
|
112
|
+
context "request" do
|
113
|
+
it "should be made" do
|
114
|
+
copy_unit
|
115
|
+
expect(request_stub).to have_been_requested
|
116
|
+
end
|
117
|
+
|
118
|
+
it "passes parameters" do
|
119
|
+
copy_unit
|
120
|
+
expect(a_request(:post, /copy/).with(query: {"destination_job_id" => destination_job_id.to_s})).to have_been_made
|
121
|
+
end
|
122
|
+
|
123
|
+
it "blows up without id" do
|
124
|
+
expect { client.units(unit_id).copy }.to raise_error Crowdkit::ValidationError
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "response" do
|
129
|
+
it "parses" do
|
130
|
+
expect(copy_unit.data[:job][:id]).to eq(destination_job_id)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "is a 201" do
|
134
|
+
copy_unit
|
135
|
+
expect(client.last_response.status).to eq(201)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "delete" do
|
141
|
+
let!(:request_stub) { stub_delete("/units/1").to_return(body: '', status: 204) }
|
142
|
+
before(:each) { client.units(1).delete }
|
143
|
+
|
144
|
+
it "request should be made" do
|
145
|
+
expect(request_stub).to have_been_requested
|
146
|
+
end
|
147
|
+
|
148
|
+
it "response status is 204" do
|
149
|
+
expect(client.last_response.status).to eq(204)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "pause" do
|
154
|
+
let!(:request_stub) { stub_put("/units/1/pause").to_return(body: '', status: 204) }
|
155
|
+
before(:each) { client.units(1).pause }
|
156
|
+
|
157
|
+
it "request should be made" do
|
158
|
+
expect(request_stub).to have_been_requested
|
159
|
+
end
|
160
|
+
|
161
|
+
it "response status is 204" do
|
162
|
+
expect(client.last_response.status).to eq(204)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "resume" do
|
167
|
+
let!(:request_stub) { stub_put("/units/1/resume").to_return(body: '', status: 204) }
|
168
|
+
before(:each) { client.units(1).resume }
|
169
|
+
|
170
|
+
it "request should be made" do
|
171
|
+
expect(request_stub).to have_been_requested
|
172
|
+
end
|
173
|
+
|
174
|
+
it "response status is 204" do
|
175
|
+
expect(client.last_response.status).to eq(204)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "judgments" do
|
180
|
+
let(:get_judgments) { client.units(1).judgments(per_page: 3) }
|
181
|
+
let!(:request_stub) { stub_get("/units/1/judgments?per_page=3").to_return(fixture_response("judgments/index.json")) }
|
182
|
+
|
183
|
+
describe "request" do
|
184
|
+
it "should be made" do
|
185
|
+
get_judgments
|
186
|
+
expect(request_stub).to have_been_requested
|
187
|
+
end
|
188
|
+
|
189
|
+
it "passes parameters" do
|
190
|
+
get_judgments
|
191
|
+
expect(a_request(:get, /judgments/).with(query: {"per_page" => 3.to_s})).to have_been_made
|
192
|
+
end
|
193
|
+
|
194
|
+
it "blows up without id" do
|
195
|
+
expect { client.units.judgments }.to raise_error Crowdkit::ValidationError
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "response" do
|
200
|
+
it "parses" do
|
201
|
+
expect(get_judgments.length).to eq(3)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "poll" do
|
207
|
+
let!(:request_stub) do
|
208
|
+
stub_get("/jobs/10/units/queue").to_return(fixture_response("units/poll/normal.json"))
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "request" do
|
212
|
+
it "should be made" do
|
213
|
+
client.units(job_id: 10).poll
|
214
|
+
expect(request_stub).to have_been_requested
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should handle 304" do
|
218
|
+
remove_request_stub(request_stub)
|
219
|
+
stub_get("/jobs/10/units/queue").to_return({status: 304})
|
220
|
+
result = client.jobs(10).units.poll
|
221
|
+
expect(result.any?).to be_falsey
|
222
|
+
end
|
223
|
+
|
224
|
+
it "passes parameters" do
|
225
|
+
stub_get("/jobs/10/units/queue?delete=true&limit=10").to_return({status: 304})
|
226
|
+
client.units(job_id: 10).poll(delete: true, limit: 10)
|
227
|
+
expect(a_request(:get, /queue/).with(query: {"delete" => "true", "limit" => "10"})).to have_been_made
|
228
|
+
end
|
229
|
+
|
230
|
+
it "blows up without job_id" do
|
231
|
+
expect { client.units.poll }.to raise_error Crowdkit::ValidationError
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "delete" do
|
235
|
+
let!(:request_delete_stub) { stub_delete(/queue/).to_return({status: 204}) }
|
236
|
+
it "should delete all units" do
|
237
|
+
client.units(job_id: 10).poll.delete
|
238
|
+
expect(request_delete_stub).to have_been_requested
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should delete units in block" do
|
242
|
+
client.units(job_id: 10).poll.each do |unit|
|
243
|
+
unit.delete if unit.id == 47979
|
244
|
+
end
|
245
|
+
expect(request_delete_stub).to have_been_requested
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'should delete single unit' do
|
249
|
+
unit = client.units(job_id: 10).poll.first
|
250
|
+
unit.delete
|
251
|
+
expect(request_delete_stub).to have_been_requested
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "response" do
|
257
|
+
it "parses" do
|
258
|
+
poll = client.units(job_id: 10).poll
|
259
|
+
expect(poll.length).to eq(30)
|
260
|
+
expect(poll.map(&:id).length).to eq(30)
|
261
|
+
expect(poll.first.id).to eq(47979)
|
262
|
+
expect(poll.last.id).to eq(48008)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|