discourse_api 0.37.0 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::Client do
4
- subject { DiscourseApi::Client.new('http://localhost:3000') }
4
+ subject { DiscourseApi::Client.new(host) }
5
5
 
6
6
  describe ".new" do
7
7
  it "requires a host argument" do
@@ -17,12 +17,12 @@ describe DiscourseApi::Client do
17
17
  end
18
18
 
19
19
  it "accepts an api key argument" do
20
- client = DiscourseApi::Client.new('http://localhost:3000', 'test')
20
+ client = DiscourseApi::Client.new(host, 'test')
21
21
  expect(client.api_key).to eq('test')
22
22
  end
23
23
 
24
24
  it "accepts an api username argument" do
25
- client = DiscourseApi::Client.new('http://localhost:3000', 'test', 'test_user')
25
+ client = DiscourseApi::Client.new(host, 'test', 'test_user')
26
26
  expect(client.api_username).to eq('test_user')
27
27
  end
28
28
  end
@@ -43,7 +43,7 @@ describe DiscourseApi::Client do
43
43
 
44
44
  describe "#host" do
45
45
  it "is publically readable" do
46
- expect(subject.host).to eq("http://localhost:3000")
46
+ expect(subject.host).to eq("#{host}")
47
47
  end
48
48
 
49
49
  it "is not publically writeable" do
@@ -64,78 +64,78 @@ describe DiscourseApi::Client do
64
64
 
65
65
  describe "#delete" do
66
66
  before do
67
- stub_delete("http://localhost:3000/test/delete").with(query: { deleted: "object" })
67
+ stub_delete("#{host}/test/delete").with(query: { deleted: "object" })
68
68
  subject.api_key = 'test_d7fd0429940'
69
69
  subject.api_username = 'test_user'
70
70
  end
71
71
 
72
72
  it "allows custom delete requests" do
73
73
  subject.delete("/test/delete", { deleted: "object" })
74
- expect(a_delete("http://localhost:3000/test/delete").with(query: { deleted: "object" })).to have_been_made
74
+ expect(a_delete("#{host}/test/delete").with(query: { deleted: "object" })).to have_been_made
75
75
  end
76
76
 
77
77
  context 'when using a host with a subdirectory' do
78
- subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
78
+ subject { DiscourseApi::Client.new("#{host}/forum") }
79
79
 
80
80
  before do
81
- stub_delete("http://localhost:3000/forum/test/delete").with(query: { deleted: "object" })
81
+ stub_delete("#{host}/forum/test/delete").with(query: { deleted: "object" })
82
82
  end
83
83
 
84
84
  it "allows custom delete requests" do
85
85
  subject.delete("/test/delete", { deleted: "object" })
86
- expect(a_delete("http://localhost:3000/forum/test/delete").with(query: { deleted: "object" })).to have_been_made
86
+ expect(a_delete("#{host}/forum/test/delete").with(query: { deleted: "object" })).to have_been_made
87
87
  end
88
88
  end
89
89
  end
90
90
 
91
91
  describe "#post" do
92
92
  before do
93
- stub_post("http://localhost:3000/test/post").with(body: { created: "object"})
93
+ stub_post("#{host}/test/post").with(body: { created: "object"})
94
94
  subject.api_key = 'test_d7fd0429940'
95
95
  subject.api_username = 'test_user'
96
96
  end
97
97
 
98
98
  it "allows custom post requests" do
99
99
  subject.post("/test/post", { created: "object" })
100
- expect(a_post("http://localhost:3000/test/post").with(body: { created: "object"})).to have_been_made
100
+ expect(a_post("#{host}/test/post").with(body: { created: "object"})).to have_been_made
101
101
  end
102
102
 
103
103
  context 'when using a host with a subdirectory' do
104
- subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
104
+ subject { DiscourseApi::Client.new("#{host}/forum") }
105
105
 
106
106
  before do
107
- stub_post("http://localhost:3000/forum/test/post").with(body: { created: "object"})
107
+ stub_post("#{host}/forum/test/post").with(body: { created: "object"})
108
108
  end
109
109
 
110
110
  it "allows custom post requests" do
111
111
  subject.post("/test/post", { created: "object" })
112
- expect(a_post("http://localhost:3000/forum/test/post").with(body: { created: "object"})).to have_been_made
112
+ expect(a_post("#{host}/forum/test/post").with(body: { created: "object"})).to have_been_made
113
113
  end
114
114
  end
115
115
  end
116
116
 
117
117
  describe "#put" do
118
118
  before do
119
- stub_put("http://localhost:3000/test/put").with(body: { updated: "object" })
119
+ stub_put("#{host}/test/put").with(body: { updated: "object" })
120
120
  subject.api_key = 'test_d7fd0429940'
121
121
  subject.api_username = 'test_user'
122
122
  end
123
123
 
124
124
  it "allows custom put requests" do
125
125
  subject.put("/test/put", { updated: "object" })
126
- expect(a_put("http://localhost:3000/test/put").with(body: { updated: "object" })).to have_been_made
126
+ expect(a_put("#{host}/test/put").with(body: { updated: "object" })).to have_been_made
127
127
  end
128
128
 
129
129
  context 'when using a host with a subdirectory' do
130
- subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
130
+ subject { DiscourseApi::Client.new("#{host}/forum") }
131
131
 
132
132
  before do
133
- stub_put("http://localhost:3000/forum/test/put").with(body: { updated: "object" })
133
+ stub_put("#{host}/forum/test/put").with(body: { updated: "object" })
134
134
  end
135
135
 
136
136
  it "allows custom post requests" do
137
137
  subject.put("/test/put", { updated: "object" })
138
- expect(a_put("http://localhost:3000/forum/test/put").with(body: { updated: "object" })).to have_been_made
138
+ expect(a_put("#{host}/forum/test/put").with(body: { updated: "object" })).to have_been_made
139
139
  end
140
140
  end
141
141
  end
@@ -149,7 +149,7 @@ describe DiscourseApi::Client do
149
149
  end
150
150
 
151
151
  it "catches Faraday errors" do
152
- allow(subject).to receive(:connection).and_raise(Faraday::Error::ClientError.new("BOOM!"))
152
+ allow(subject).to receive(:connection).and_raise(Faraday::ClientError.new("BOOM!"))
153
153
  expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
154
154
  end
155
155
 
@@ -0,0 +1,437 @@
1
+ {
2
+ "members": [{
3
+ "id": 1,
4
+ "name": "Test 0",
5
+ "username": "Test_0"
6
+ }, {
7
+ "id": 2,
8
+ "name": "Test 1",
9
+ "username": "Test_1"
10
+ }, {
11
+ "id": 3,
12
+ "name": "Test 2",
13
+ "username": "Test_2"
14
+ }, {
15
+ "id": 4,
16
+ "name": "Test 3",
17
+ "username": "Test_3"
18
+ }, {
19
+ "id": 5,
20
+ "name": "Test 4",
21
+ "username": "Test_4"
22
+ }, {
23
+ "id": 6,
24
+ "name": "Test 5",
25
+ "username": "Test_5"
26
+ }, {
27
+ "id": 7,
28
+ "name": "Test 6",
29
+ "username": "Test_6"
30
+ }, {
31
+ "id": 8,
32
+ "name": "Test 7",
33
+ "username": "Test_7"
34
+ }, {
35
+ "id": 9,
36
+ "name": "Test 8",
37
+ "username": "Test_8"
38
+ }, {
39
+ "id": 10,
40
+ "name": "Test 9",
41
+ "username": "Test_9"
42
+ }, {
43
+ "id": 11,
44
+ "name": "Test 10",
45
+ "username": "Test_10"
46
+ }, {
47
+ "id": 12,
48
+ "name": "Test 11",
49
+ "username": "Test_11"
50
+ }, {
51
+ "id": 13,
52
+ "name": "Test 12",
53
+ "username": "Test_12"
54
+ }, {
55
+ "id": 14,
56
+ "name": "Test 13",
57
+ "username": "Test_13"
58
+ }, {
59
+ "id": 15,
60
+ "name": "Test 14",
61
+ "username": "Test_14"
62
+ }, {
63
+ "id": 16,
64
+ "name": "Test 15",
65
+ "username": "Test_15"
66
+ }, {
67
+ "id": 17,
68
+ "name": "Test 16",
69
+ "username": "Test_16"
70
+ }, {
71
+ "id": 18,
72
+ "name": "Test 17",
73
+ "username": "Test_17"
74
+ }, {
75
+ "id": 19,
76
+ "name": "Test 18",
77
+ "username": "Test_18"
78
+ }, {
79
+ "id": 20,
80
+ "name": "Test 19",
81
+ "username": "Test_19"
82
+ }, {
83
+ "id": 21,
84
+ "name": "Test 20",
85
+ "username": "Test_20"
86
+ }, {
87
+ "id": 22,
88
+ "name": "Test 21",
89
+ "username": "Test_21"
90
+ }, {
91
+ "id": 23,
92
+ "name": "Test 22",
93
+ "username": "Test_22"
94
+ }, {
95
+ "id": 24,
96
+ "name": "Test 23",
97
+ "username": "Test_23"
98
+ }, {
99
+ "id": 25,
100
+ "name": "Test 24",
101
+ "username": "Test_24"
102
+ }, {
103
+ "id": 26,
104
+ "name": "Test 25",
105
+ "username": "Test_25"
106
+ }, {
107
+ "id": 27,
108
+ "name": "Test 26",
109
+ "username": "Test_26"
110
+ }, {
111
+ "id": 28,
112
+ "name": "Test 27",
113
+ "username": "Test_27"
114
+ }, {
115
+ "id": 29,
116
+ "name": "Test 28",
117
+ "username": "Test_28"
118
+ }, {
119
+ "id": 30,
120
+ "name": "Test 29",
121
+ "username": "Test_29"
122
+ }, {
123
+ "id": 31,
124
+ "name": "Test 30",
125
+ "username": "Test_30"
126
+ }, {
127
+ "id": 32,
128
+ "name": "Test 31",
129
+ "username": "Test_31"
130
+ }, {
131
+ "id": 33,
132
+ "name": "Test 32",
133
+ "username": "Test_32"
134
+ }, {
135
+ "id": 34,
136
+ "name": "Test 33",
137
+ "username": "Test_33"
138
+ }, {
139
+ "id": 35,
140
+ "name": "Test 34",
141
+ "username": "Test_34"
142
+ }, {
143
+ "id": 36,
144
+ "name": "Test 35",
145
+ "username": "Test_35"
146
+ }, {
147
+ "id": 37,
148
+ "name": "Test 36",
149
+ "username": "Test_36"
150
+ }, {
151
+ "id": 38,
152
+ "name": "Test 37",
153
+ "username": "Test_37"
154
+ }, {
155
+ "id": 39,
156
+ "name": "Test 38",
157
+ "username": "Test_38"
158
+ }, {
159
+ "id": 40,
160
+ "name": "Test 39",
161
+ "username": "Test_39"
162
+ }, {
163
+ "id": 41,
164
+ "name": "Test 40",
165
+ "username": "Test_40"
166
+ }, {
167
+ "id": 42,
168
+ "name": "Test 41",
169
+ "username": "Test_41"
170
+ }, {
171
+ "id": 43,
172
+ "name": "Test 42",
173
+ "username": "Test_42"
174
+ }, {
175
+ "id": 44,
176
+ "name": "Test 43",
177
+ "username": "Test_43"
178
+ }, {
179
+ "id": 45,
180
+ "name": "Test 44",
181
+ "username": "Test_44"
182
+ }, {
183
+ "id": 46,
184
+ "name": "Test 45",
185
+ "username": "Test_45"
186
+ }, {
187
+ "id": 47,
188
+ "name": "Test 46",
189
+ "username": "Test_46"
190
+ }, {
191
+ "id": 48,
192
+ "name": "Test 47",
193
+ "username": "Test_47"
194
+ }, {
195
+ "id": 49,
196
+ "name": "Test 48",
197
+ "username": "Test_48"
198
+ }, {
199
+ "id": 50,
200
+ "name": "Test 49",
201
+ "username": "Test_49"
202
+ }, {
203
+ "id": 51,
204
+ "name": "Test 50",
205
+ "username": "Test_50"
206
+ }, {
207
+ "id": 52,
208
+ "name": "Test 51",
209
+ "username": "Test_51"
210
+ }, {
211
+ "id": 53,
212
+ "name": "Test 52",
213
+ "username": "Test_52"
214
+ }, {
215
+ "id": 54,
216
+ "name": "Test 53",
217
+ "username": "Test_53"
218
+ }, {
219
+ "id": 55,
220
+ "name": "Test 54",
221
+ "username": "Test_54"
222
+ }, {
223
+ "id": 56,
224
+ "name": "Test 55",
225
+ "username": "Test_55"
226
+ }, {
227
+ "id": 57,
228
+ "name": "Test 56",
229
+ "username": "Test_56"
230
+ }, {
231
+ "id": 58,
232
+ "name": "Test 57",
233
+ "username": "Test_57"
234
+ }, {
235
+ "id": 59,
236
+ "name": "Test 58",
237
+ "username": "Test_58"
238
+ }, {
239
+ "id": 60,
240
+ "name": "Test 59",
241
+ "username": "Test_59"
242
+ }, {
243
+ "id": 61,
244
+ "name": "Test 60",
245
+ "username": "Test_60"
246
+ }, {
247
+ "id": 62,
248
+ "name": "Test 61",
249
+ "username": "Test_61"
250
+ }, {
251
+ "id": 63,
252
+ "name": "Test 62",
253
+ "username": "Test_62"
254
+ }, {
255
+ "id": 64,
256
+ "name": "Test 63",
257
+ "username": "Test_63"
258
+ }, {
259
+ "id": 65,
260
+ "name": "Test 64",
261
+ "username": "Test_64"
262
+ }, {
263
+ "id": 66,
264
+ "name": "Test 65",
265
+ "username": "Test_65"
266
+ }, {
267
+ "id": 67,
268
+ "name": "Test 66",
269
+ "username": "Test_66"
270
+ }, {
271
+ "id": 68,
272
+ "name": "Test 67",
273
+ "username": "Test_67"
274
+ }, {
275
+ "id": 69,
276
+ "name": "Test 68",
277
+ "username": "Test_68"
278
+ }, {
279
+ "id": 70,
280
+ "name": "Test 69",
281
+ "username": "Test_69"
282
+ }, {
283
+ "id": 71,
284
+ "name": "Test 70",
285
+ "username": "Test_70"
286
+ }, {
287
+ "id": 72,
288
+ "name": "Test 71",
289
+ "username": "Test_71"
290
+ }, {
291
+ "id": 73,
292
+ "name": "Test 72",
293
+ "username": "Test_72"
294
+ }, {
295
+ "id": 74,
296
+ "name": "Test 73",
297
+ "username": "Test_73"
298
+ }, {
299
+ "id": 75,
300
+ "name": "Test 74",
301
+ "username": "Test_74"
302
+ }, {
303
+ "id": 76,
304
+ "name": "Test 75",
305
+ "username": "Test_75"
306
+ }, {
307
+ "id": 77,
308
+ "name": "Test 76",
309
+ "username": "Test_76"
310
+ }, {
311
+ "id": 78,
312
+ "name": "Test 77",
313
+ "username": "Test_77"
314
+ }, {
315
+ "id": 79,
316
+ "name": "Test 78",
317
+ "username": "Test_78"
318
+ }, {
319
+ "id": 80,
320
+ "name": "Test 79",
321
+ "username": "Test_79"
322
+ }, {
323
+ "id": 81,
324
+ "name": "Test 80",
325
+ "username": "Test_80"
326
+ }, {
327
+ "id": 82,
328
+ "name": "Test 81",
329
+ "username": "Test_81"
330
+ }, {
331
+ "id": 83,
332
+ "name": "Test 82",
333
+ "username": "Test_82"
334
+ }, {
335
+ "id": 84,
336
+ "name": "Test 83",
337
+ "username": "Test_83"
338
+ }, {
339
+ "id": 85,
340
+ "name": "Test 84",
341
+ "username": "Test_84"
342
+ }, {
343
+ "id": 86,
344
+ "name": "Test 85",
345
+ "username": "Test_85"
346
+ }, {
347
+ "id": 87,
348
+ "name": "Test 86",
349
+ "username": "Test_86"
350
+ }, {
351
+ "id": 88,
352
+ "name": "Test 87",
353
+ "username": "Test_87"
354
+ }, {
355
+ "id": 89,
356
+ "name": "Test 88",
357
+ "username": "Test_88"
358
+ }, {
359
+ "id": 90,
360
+ "name": "Test 89",
361
+ "username": "Test_89"
362
+ }, {
363
+ "id": 91,
364
+ "name": "Test 90",
365
+ "username": "Test_90"
366
+ }, {
367
+ "id": 92,
368
+ "name": "Test 91",
369
+ "username": "Test_91"
370
+ }, {
371
+ "id": 93,
372
+ "name": "Test 92",
373
+ "username": "Test_92"
374
+ }, {
375
+ "id": 94,
376
+ "name": "Test 93",
377
+ "username": "Test_93"
378
+ }, {
379
+ "id": 95,
380
+ "name": "Test 94",
381
+ "username": "Test_94"
382
+ }, {
383
+ "id": 96,
384
+ "name": "Test 95",
385
+ "username": "Test_95"
386
+ }, {
387
+ "id": 97,
388
+ "name": "Test 96",
389
+ "username": "Test_96"
390
+ }, {
391
+ "id": 98,
392
+ "name": "Test 97",
393
+ "username": "Test_97"
394
+ }, {
395
+ "id": 99,
396
+ "name": "Test 98",
397
+ "username": "Test_98"
398
+ }, {
399
+ "id": 100,
400
+ "name": "Test 99",
401
+ "username": "Test_99"
402
+ }],
403
+ "owners": [{
404
+ "id": 101,
405
+ "name": "Onwer 0",
406
+ "username": "Owner_0"
407
+ }, {
408
+ "id": 102,
409
+ "name": "Onwer 1",
410
+ "username": "Owner_1"
411
+ }, {
412
+ "id": 103,
413
+ "name": "Onwer 2",
414
+ "username": "Owner_2"
415
+ }, {
416
+ "id": 104,
417
+ "name": "Onwer 3",
418
+ "username": "Owner_3"
419
+ }, {
420
+ "id": 105,
421
+ "name": "Onwer 4",
422
+ "username": "Owner_4"
423
+ }, {
424
+ "id": 106,
425
+ "name": "Onwer 5",
426
+ "username": "Owner_5"
427
+ }, {
428
+ "id": 107,
429
+ "name": "Onwer 6",
430
+ "username": "Owner_6"
431
+ }],
432
+ "meta": {
433
+ "total": 107,
434
+ "limit": 0,
435
+ "offset": 0
436
+ }
437
+ }