discourse_api 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/discourse_api/client.rb +2 -2
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +9 -18
- data/spec/discourse_api/api/backups_spec.rb +2 -2
- data/spec/discourse_api/api/badges_spec.rb +4 -4
- data/spec/discourse_api/api/categories_spec.rb +7 -7
- data/spec/discourse_api/api/email_spec.rb +4 -4
- data/spec/discourse_api/api/groups_spec.rb +17 -18
- data/spec/discourse_api/api/notifications_spec.rb +2 -2
- data/spec/discourse_api/api/posts_spec.rb +6 -6
- data/spec/discourse_api/api/private_messages_spec.rb +6 -6
- data/spec/discourse_api/api/search_spec.rb +3 -3
- data/spec/discourse_api/api/site_settings_spec.rb +2 -2
- data/spec/discourse_api/api/topics_spec.rb +13 -13
- data/spec/discourse_api/api/uploads_spec.rb +1 -1
- data/spec/discourse_api/api/user_actions_spec.rb +4 -4
- data/spec/discourse_api/api/users_spec.rb +37 -37
- data/spec/discourse_api/client_spec.rb +12 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52056720fe38a8e6345ebdaa427c8da352681b88bcf3a2de2b21636b251181ce
|
4
|
+
data.tar.gz: 81f2c6c41121d1b15cc5c389d4f067314b271eb96b7976a12ed2625e1927861b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75583ba2ac5bc68bba59ba127d87b9660de4101baf7eeb5a79454b536254eb07596d98df5610b67f47445e0f362f1a928d36e2cbdf08a74b57e66eb7aef20409
|
7
|
+
data.tar.gz: '019c08c76bd3150b6eea2f990f7e3194931d04d96522e51a7662b5a2aa1b3cbbc7424b43833ef549d5e351baeeb7890564c0c0f473b6fa8af42ec871666b458d'
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.34.0] - 2019-04-02
|
6
|
+
### Added
|
7
|
+
- Header based authentication
|
8
|
+
### Removed
|
9
|
+
- Query param based authentication
|
10
|
+
|
5
11
|
## [0.33.0] - 2019-03-04
|
6
12
|
### Added
|
7
13
|
- Added a new method to update a users notification level in a category
|
data/lib/discourse_api/client.rb
CHANGED
@@ -121,8 +121,8 @@ module DiscourseApi
|
|
121
121
|
conn.adapter Faraday.default_adapter
|
122
122
|
#pass api_key and api_username on every request
|
123
123
|
unless api_username.nil?
|
124
|
-
conn.
|
125
|
-
conn.
|
124
|
+
conn.headers['Api-key'] = api_key
|
125
|
+
conn.headers['Api-username'] = api_username
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
@@ -11,16 +11,14 @@ describe DiscourseApi::API::ApiKey do
|
|
11
11
|
|
12
12
|
describe "#api" do
|
13
13
|
before do
|
14
|
-
url = "http://localhost:3000/admin/api.json"
|
15
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
14
|
+
url = "http://localhost:3000/admin/api.json"
|
16
15
|
stub_get(url).to_return(body: fixture("api.json"),
|
17
16
|
headers: { content_type: "application/json" })
|
18
17
|
end
|
19
18
|
|
20
19
|
it "requests the correct resource" do
|
21
20
|
subject.api
|
22
|
-
url = "http://localhost:3000/admin/api.json"
|
23
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
21
|
+
url = "http://localhost:3000/admin/api.json"
|
24
22
|
expect(a_get(url)).to have_been_made
|
25
23
|
end
|
26
24
|
|
@@ -34,8 +32,7 @@ describe DiscourseApi::API::ApiKey do
|
|
34
32
|
|
35
33
|
describe "#generate_user_api_key" do
|
36
34
|
before do
|
37
|
-
url = "http://localhost:3000/admin/users/2/generate_api_key.json"
|
38
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
35
|
+
url = "http://localhost:3000/admin/users/2/generate_api_key.json"
|
39
36
|
stub_post(url).to_return(body: fixture("generate_api_key.json"),
|
40
37
|
headers: { content_type: "application/json" })
|
41
38
|
end
|
@@ -49,8 +46,7 @@ describe DiscourseApi::API::ApiKey do
|
|
49
46
|
|
50
47
|
describe "#revoke_user_api_key" do
|
51
48
|
before do
|
52
|
-
url = "http://localhost:3000/admin/users/2/revoke_api_key.json"
|
53
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
49
|
+
url = "http://localhost:3000/admin/users/2/revoke_api_key.json"
|
54
50
|
stub_delete(url).to_return(body: "",
|
55
51
|
headers: { content_type: "application/json" })
|
56
52
|
end
|
@@ -63,8 +59,7 @@ describe DiscourseApi::API::ApiKey do
|
|
63
59
|
|
64
60
|
describe "#generate_master_key" do
|
65
61
|
before do
|
66
|
-
url = "http://localhost:3000/admin/api/key"
|
67
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
62
|
+
url = "http://localhost:3000/admin/api/key"
|
68
63
|
stub_post(url).to_return(body: fixture("generate_master_key.json"),
|
69
64
|
headers: { content_type: "application/json" })
|
70
65
|
end
|
@@ -79,16 +74,14 @@ describe DiscourseApi::API::ApiKey do
|
|
79
74
|
|
80
75
|
describe "#revoke_api_key" do
|
81
76
|
before do
|
82
|
-
url = "http://localhost:3000/admin/api/key"
|
83
|
-
"?api_key=test_d7fd0429940&api_username=test_user&id=10"
|
77
|
+
url = "http://localhost:3000/admin/api/key?id=10"
|
84
78
|
stub_delete(url).to_return(body: "",
|
85
79
|
headers: { content_type: "application/json" })
|
86
80
|
end
|
87
81
|
|
88
82
|
it "requests the correct resource" do
|
89
83
|
subject.revoke_api_key(10)
|
90
|
-
url = "http://localhost:3000/admin/api/key"
|
91
|
-
"?api_key=test_d7fd0429940&api_username=test_user&id=10"
|
84
|
+
url = "http://localhost:3000/admin/api/key?id=10"
|
92
85
|
expect(a_delete(url)).to have_been_made
|
93
86
|
end
|
94
87
|
|
@@ -100,16 +93,14 @@ describe DiscourseApi::API::ApiKey do
|
|
100
93
|
|
101
94
|
describe "#regenerate_api_key" do
|
102
95
|
before do
|
103
|
-
url = "http://localhost:3000/admin/api/key"
|
104
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
96
|
+
url = "http://localhost:3000/admin/api/key"
|
105
97
|
stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
|
106
98
|
headers: { content_type: "application/json" })
|
107
99
|
end
|
108
100
|
|
109
101
|
it "requests the correct resource" do
|
110
102
|
subject.regenerate_api_key(10)
|
111
|
-
url = "http://localhost:3000/admin/api/key"
|
112
|
-
"?api_key=test_d7fd0429940&api_username=test_user"
|
103
|
+
url = "http://localhost:3000/admin/api/key"
|
113
104
|
expect(a_put(url)).to have_been_made
|
114
105
|
end
|
115
106
|
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Backups do
|
|
5
5
|
|
6
6
|
describe "#backups" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/admin/backups.json
|
8
|
+
stub_get("http://localhost:3000/admin/backups.json").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.backups
|
13
|
-
expect(a_get("http://localhost:3000/admin/backups.json
|
13
|
+
expect(a_get("http://localhost:3000/admin/backups.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested backups" do
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Badges do
|
|
5
5
|
|
6
6
|
describe "#badges" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/admin/badges.json
|
8
|
+
stub_get("http://localhost:3000/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.badges
|
13
|
-
expect(a_get("http://localhost:3000/admin/badges.json
|
13
|
+
expect(a_get("http://localhost:3000/admin/badges.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested badges" do
|
@@ -22,12 +22,12 @@ describe DiscourseApi::API::Badges do
|
|
22
22
|
|
23
23
|
describe "#user_badges" do
|
24
24
|
before do
|
25
|
-
stub_get("http://localhost:3000/users/test_user/activity/badges.json
|
25
|
+
stub_get("http://localhost:3000/users/test_user/activity/badges.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
|
26
26
|
end
|
27
27
|
|
28
28
|
it "requests the correct resource" do
|
29
29
|
subject.user_badges('test_user')
|
30
|
-
expect(a_get("http://localhost:3000/users/test_user/activity/badges.json
|
30
|
+
expect(a_get("http://localhost:3000/users/test_user/activity/badges.json")).to have_been_made
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the requested user badges" do
|
@@ -5,13 +5,13 @@ describe DiscourseApi::API::Categories do
|
|
5
5
|
|
6
6
|
describe "#categories" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/categories.json
|
8
|
+
stub_get("http://localhost:3000/categories.json")
|
9
9
|
.to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
|
10
10
|
end
|
11
11
|
|
12
12
|
it "requests the correct resource" do
|
13
13
|
subject.categories
|
14
|
-
expect(a_get("http://localhost:3000/categories.json
|
14
|
+
expect(a_get("http://localhost:3000/categories.json")).to have_been_made
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns the requested categories" do
|
@@ -29,7 +29,7 @@ describe DiscourseApi::API::Categories do
|
|
29
29
|
|
30
30
|
describe '#category_latest_topics' do
|
31
31
|
before do
|
32
|
-
stub_get("http://localhost:3000/c/category-slug/l/latest.json
|
32
|
+
stub_get("http://localhost:3000/c/category-slug/l/latest.json")
|
33
33
|
.to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
|
34
34
|
end
|
35
35
|
|
@@ -41,7 +41,7 @@ describe DiscourseApi::API::Categories do
|
|
41
41
|
|
42
42
|
describe '#category_top_topics' do
|
43
43
|
before do
|
44
|
-
stub_get("http://localhost:3000/c/category-slug/l/top.json
|
44
|
+
stub_get("http://localhost:3000/c/category-slug/l/top.json")
|
45
45
|
.to_return(
|
46
46
|
body: fixture("category_topics.json"),
|
47
47
|
headers: { content_type: "application/json" }
|
@@ -56,7 +56,7 @@ describe DiscourseApi::API::Categories do
|
|
56
56
|
|
57
57
|
describe '#category_new_topics' do
|
58
58
|
before do
|
59
|
-
stub_get("http://localhost:3000/c/category-slug/l/new.json
|
59
|
+
stub_get("http://localhost:3000/c/category-slug/l/new.json")
|
60
60
|
.to_return(
|
61
61
|
body: fixture("category_topics.json"),
|
62
62
|
headers: { content_type: "application/json" }
|
@@ -71,14 +71,14 @@ describe DiscourseApi::API::Categories do
|
|
71
71
|
|
72
72
|
describe '#category_new_category' do
|
73
73
|
before do
|
74
|
-
stub_post("http://localhost:3000/categories
|
74
|
+
stub_post("http://localhost:3000/categories")
|
75
75
|
subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
|
76
76
|
description: "This is a description",
|
77
77
|
permissions: {"group_1" => 1, "admins" => 1})
|
78
78
|
end
|
79
79
|
|
80
80
|
it "makes a create category request" do
|
81
|
-
expect(a_post("http://localhost:3000/categories
|
81
|
+
expect(a_post("http://localhost:3000/categories").with(body:
|
82
82
|
"color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
|
83
83
|
).to have_been_made
|
84
84
|
end
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Email do
|
|
5
5
|
|
6
6
|
describe "#email_settings" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/admin/email.json
|
8
|
+
stub_get("http://localhost:3000/admin/email.json").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.email_settings
|
13
|
-
expect(a_get("http://localhost:3000/admin/email.json
|
13
|
+
expect(a_get("http://localhost:3000/admin/email.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested settings" do
|
@@ -23,12 +23,12 @@ describe DiscourseApi::API::Email do
|
|
23
23
|
|
24
24
|
describe "#list_email_all" do
|
25
25
|
before do
|
26
|
-
stub_get("http://localhost:3000/admin/email/all.json
|
26
|
+
stub_get("http://localhost:3000/admin/email/all.json").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
|
27
27
|
end
|
28
28
|
|
29
29
|
it "requests the correct resource" do
|
30
30
|
subject.list_email('all')
|
31
|
-
expect(a_get("http://localhost:3000/admin/email/all.json
|
31
|
+
expect(a_get("http://localhost:3000/admin/email/all.json")).to have_been_made
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns all email" do
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Groups do
|
|
5
5
|
|
6
6
|
describe "#groups" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/groups.json
|
8
|
+
stub_get("http://localhost:3000/groups.json").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.groups
|
13
|
-
expect(a_get("http://localhost:3000/groups.json
|
13
|
+
expect(a_get("http://localhost:3000/groups.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested groups" do
|
@@ -20,65 +20,65 @@ describe DiscourseApi::API::Groups do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns a single group" do
|
23
|
-
stub_get("http://localhost:3000/groups/some-group.json
|
23
|
+
stub_get("http://localhost:3000/groups/some-group.json").to_return(body: fixture("group.json"), headers: { content_type: "application/json" })
|
24
24
|
group = subject.group('some-group')
|
25
25
|
expect(group['basic_group']).to be_a Hash
|
26
26
|
end
|
27
27
|
|
28
28
|
it "create new groups" do
|
29
|
-
stub_post("http://localhost:3000/admin/groups
|
29
|
+
stub_post("http://localhost:3000/admin/groups")
|
30
30
|
subject.create_group(name: "test_group")
|
31
31
|
params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
|
32
|
-
expect(a_post("http://localhost:3000/admin/groups
|
32
|
+
expect(a_post("http://localhost:3000/admin/groups").
|
33
33
|
with(body: params)
|
34
34
|
).to have_been_made
|
35
35
|
end
|
36
36
|
|
37
37
|
it "update an existing group" do
|
38
|
-
stub_put("http://localhost:3000/groups/42
|
38
|
+
stub_put("http://localhost:3000/groups/42")
|
39
39
|
subject.update_group(42, name: "test_group")
|
40
40
|
params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
|
41
|
-
expect(a_put("http://localhost:3000/groups/42
|
41
|
+
expect(a_put("http://localhost:3000/groups/42").
|
42
42
|
with(body: params)
|
43
43
|
).to have_been_made
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "add members" do
|
47
47
|
before do
|
48
|
-
stub_request(:put, "http://localhost:3000/admin/groups/123/members.json
|
48
|
+
stub_request(:put, "http://localhost:3000/admin/groups/123/members.json")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "adds a single member by username" do
|
52
52
|
subject.group_add(123, username: "sam")
|
53
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json
|
53
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
|
54
54
|
with(body: {usernames: "sam"})
|
55
55
|
).to have_been_made
|
56
56
|
end
|
57
57
|
|
58
58
|
it "adds an array of members by username" do
|
59
59
|
subject.group_add(123, usernames: ["sam", "jeff"])
|
60
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json
|
60
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
|
61
61
|
with(body: {usernames: "sam,jeff"})
|
62
62
|
).to have_been_made
|
63
63
|
end
|
64
64
|
|
65
65
|
it "adds a single member by user_id" do
|
66
66
|
subject.group_add(123, user_id: 456)
|
67
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json
|
67
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
|
68
68
|
with(body: {user_ids: "456"})
|
69
69
|
).to have_been_made
|
70
70
|
end
|
71
71
|
|
72
72
|
it "adds an array of members by user_id" do
|
73
73
|
subject.group_add(123, user_id: [123, 456])
|
74
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json
|
74
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
|
75
75
|
with(body: {user_ids: "123,456"})
|
76
76
|
).to have_been_made
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "remove members" do
|
81
|
-
let(:url) { "http://localhost:3000/admin/groups/123/members.json?
|
81
|
+
let(:url) { "http://localhost:3000/admin/groups/123/members.json?usernames=sam" }
|
82
82
|
|
83
83
|
before do
|
84
84
|
stub_delete(url)
|
@@ -92,20 +92,19 @@ describe DiscourseApi::API::Groups do
|
|
92
92
|
|
93
93
|
describe "group members" do
|
94
94
|
before do
|
95
|
-
stub_get("http://localhost:3000/groups/mygroup/members.json?
|
96
|
-
stub_get("http://localhost:3000/groups/mygroup/members.json?
|
95
|
+
stub_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
|
96
|
+
stub_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
|
97
97
|
end
|
98
98
|
|
99
99
|
it "list members" do
|
100
100
|
members = subject.group_members('mygroup')
|
101
|
-
expect(a_get("http://localhost:3000/groups/mygroup/members.json?
|
101
|
+
expect(a_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
|
102
102
|
expect(members.length).to eq(100)
|
103
103
|
members = subject.group_members('mygroup', offset: 100)
|
104
|
-
expect(a_get("http://localhost:3000/groups/mygroup/members.json?
|
104
|
+
expect(a_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
|
105
105
|
expect(members.length).to eq(90)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
|
110
109
|
end
|
111
110
|
end
|
@@ -6,12 +6,12 @@ describe DiscourseApi::API::Notifications do
|
|
6
6
|
describe "#notifications" do
|
7
7
|
|
8
8
|
before do
|
9
|
-
stub_get("http://localhost:3000/notifications.json
|
9
|
+
stub_get("http://localhost:3000/notifications.json").to_return(body: fixture("notifications.json"), headers: { content_type: "application/json" })
|
10
10
|
end
|
11
11
|
|
12
12
|
it "requests the correct resource" do
|
13
13
|
subject.notifications
|
14
|
-
expect(a_get("http://localhost:3000/notifications.json
|
14
|
+
expect(a_get("http://localhost:3000/notifications.json")).to have_been_made
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns the requested notifications" do
|
@@ -5,7 +5,7 @@ describe DiscourseApi::API::Posts do
|
|
5
5
|
|
6
6
|
describe "#get_post" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/posts/11.json
|
8
|
+
stub_get("http://localhost:3000/posts/11.json").to_return(body: fixture("post.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "fetches a post" do
|
@@ -17,29 +17,29 @@ describe DiscourseApi::API::Posts do
|
|
17
17
|
|
18
18
|
describe "#wikify_post" do
|
19
19
|
before do
|
20
|
-
stub_put("http://localhost:3000/posts/9999/wiki
|
20
|
+
stub_put("http://localhost:3000/posts/9999/wiki")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "fails on unknown post" do
|
24
24
|
client.wikify_post(9999)
|
25
|
-
expect(a_put("http://localhost:3000/posts/9999/wiki
|
25
|
+
expect(a_put("http://localhost:3000/posts/9999/wiki")).to have_been_made
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#delete_post" do
|
30
30
|
before do
|
31
|
-
stub_delete("http://localhost:3000/posts/9999.json
|
31
|
+
stub_delete("http://localhost:3000/posts/9999.json")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "deletes a post" do
|
35
35
|
client.delete_post(9999)
|
36
|
-
expect(a_delete("http://localhost:3000/posts/9999.json
|
36
|
+
expect(a_delete("http://localhost:3000/posts/9999.json")).to have_been_made
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#post_action_users" do
|
41
41
|
before do
|
42
|
-
stub_get("http://localhost:3000/post_action_users.json?
|
42
|
+
stub_get("http://localhost:3000/post_action_users.json?id=11&post_action_type_id=2").to_return(body: fixture("post_action_users.json"), headers: { content_type: "application/json" })
|
43
43
|
end
|
44
44
|
|
45
45
|
it "fetches post_action_users" do
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::PrivateMessages do
|
|
5
5
|
|
6
6
|
describe "#private_messages" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/topics/private-messages/test_user.json
|
8
|
+
stub_get("http://localhost:3000/topics/private-messages/test_user.json").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.private_messages('test_user')
|
13
|
-
expect(a_get("http://localhost:3000/topics/private-messages/test_user.json
|
13
|
+
expect(a_get("http://localhost:3000/topics/private-messages/test_user.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested private messages" do
|
@@ -21,12 +21,12 @@ describe DiscourseApi::API::PrivateMessages do
|
|
21
21
|
|
22
22
|
describe "#sent_private_messages" do
|
23
23
|
before do
|
24
|
-
stub_get("http://localhost:3000/topics/private-messages-sent/test_user.json
|
24
|
+
stub_get("http://localhost:3000/topics/private-messages-sent/test_user.json").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
|
25
25
|
end
|
26
26
|
|
27
27
|
it "requests the correct resource" do
|
28
28
|
subject.sent_private_messages('test_user')
|
29
|
-
expect(a_get("http://localhost:3000/topics/private-messages-sent/test_user.json
|
29
|
+
expect(a_get("http://localhost:3000/topics/private-messages-sent/test_user.json")).to have_been_made
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns the requested sent private messages" do
|
@@ -37,7 +37,7 @@ describe DiscourseApi::API::PrivateMessages do
|
|
37
37
|
|
38
38
|
describe '#create_private_message' do
|
39
39
|
before do
|
40
|
-
stub_post("http://localhost:3000/posts
|
40
|
+
stub_post("http://localhost:3000/posts")
|
41
41
|
subject.create_private_message(
|
42
42
|
title: "Confidential: Hello World!",
|
43
43
|
raw: "This is the raw markdown for my private message",
|
@@ -46,7 +46,7 @@ describe DiscourseApi::API::PrivateMessages do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "makes a create private message request" do
|
49
|
-
expect(a_post("http://localhost:3000/posts
|
49
|
+
expect(a_post("http://localhost:3000/posts").with(body:
|
50
50
|
'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_usernames=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
|
51
51
|
).to have_been_made
|
52
52
|
end
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Search do
|
|
5
5
|
|
6
6
|
describe "#search" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/search/query
|
8
|
+
stub_get("http://localhost:3000/search/query").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.search("test")
|
13
|
-
expect(a_get("http://localhost:3000/search/query
|
13
|
+
expect(a_get("http://localhost:3000/search/query").with(query: { term: "test"} )).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested search" do
|
@@ -18,7 +18,7 @@ describe DiscourseApi::API::Search do
|
|
18
18
|
expect(results).to be_an Array
|
19
19
|
expect(results.first).to be_a Hash
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "raises an ArgumentError for nil" do
|
23
23
|
expect { subject.search(nil) }.to raise_error(ArgumentError)
|
24
24
|
end
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::SiteSettings do
|
|
5
5
|
|
6
6
|
describe "#site_setting_update" do
|
7
7
|
before do
|
8
|
-
stub_put("http://localhost:3000/admin/site_settings/foo
|
8
|
+
stub_put("http://localhost:3000/admin/site_settings/foo")
|
9
9
|
subject.site_setting_update(name: "foo", value: "bar")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "makes a site_settings_update request" do
|
13
|
-
expect(a_put("http://localhost:3000/admin/site_settings/foo
|
13
|
+
expect(a_put("http://localhost:3000/admin/site_settings/foo")
|
14
14
|
.with(body: "foo=bar")).to have_been_made
|
15
15
|
end
|
16
16
|
end
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Topics do
|
|
5
5
|
|
6
6
|
describe "#invite_user_to_topic" do
|
7
7
|
before do
|
8
|
-
stub_post("http://localhost:3000/t/12/invite
|
8
|
+
stub_post("http://localhost:3000/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
13
|
-
expect(a_post("http://localhost:3000/t/12/invite
|
13
|
+
expect(a_post("http://localhost:3000/t/12/invite")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns success" do
|
@@ -22,12 +22,12 @@ describe DiscourseApi::API::Topics do
|
|
22
22
|
|
23
23
|
describe "#latest_topics" do
|
24
24
|
before do
|
25
|
-
stub_get("http://localhost:3000/latest.json
|
25
|
+
stub_get("http://localhost:3000/latest.json").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
|
26
26
|
end
|
27
27
|
|
28
28
|
it "requests the correct resource" do
|
29
29
|
subject.latest_topics
|
30
|
-
expect(a_get("http://localhost:3000/latest.json
|
30
|
+
expect(a_get("http://localhost:3000/latest.json")).to have_been_made
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the requested topics" do
|
@@ -45,12 +45,12 @@ describe DiscourseApi::API::Topics do
|
|
45
45
|
|
46
46
|
describe "#new_topics" do
|
47
47
|
before do
|
48
|
-
stub_get("http://localhost:3000/new.json
|
48
|
+
stub_get("http://localhost:3000/new.json").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
|
49
49
|
end
|
50
50
|
|
51
51
|
it "requests the correct resource" do
|
52
52
|
subject.new_topics
|
53
|
-
expect(a_get("http://localhost:3000/new.json
|
53
|
+
expect(a_get("http://localhost:3000/new.json")).to have_been_made
|
54
54
|
end
|
55
55
|
|
56
56
|
it "returns the requested topics" do
|
@@ -63,12 +63,12 @@ describe DiscourseApi::API::Topics do
|
|
63
63
|
|
64
64
|
describe "#topic" do
|
65
65
|
before do
|
66
|
-
stub_get("http://localhost:3000/t/57.json
|
66
|
+
stub_get("http://localhost:3000/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
67
67
|
end
|
68
68
|
|
69
69
|
it "requests the correct resource" do
|
70
70
|
subject.topic(57)
|
71
|
-
expect(a_get("http://localhost:3000/t/57.json
|
71
|
+
expect(a_get("http://localhost:3000/t/57.json")).to have_been_made
|
72
72
|
end
|
73
73
|
|
74
74
|
it "returns the requested topic" do
|
@@ -80,28 +80,28 @@ describe DiscourseApi::API::Topics do
|
|
80
80
|
|
81
81
|
describe "#update_topic" do
|
82
82
|
before do
|
83
|
-
stub_put("http://localhost:3000/t/57.json
|
83
|
+
stub_put("http://localhost:3000/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
84
84
|
end
|
85
85
|
|
86
86
|
it "renames the topic" do
|
87
87
|
subject.rename_topic(57, "A new title!")
|
88
|
-
expect(a_put("http://localhost:3000/t/57.json
|
88
|
+
expect(a_put("http://localhost:3000/t/57.json")).to have_been_made
|
89
89
|
end
|
90
90
|
|
91
91
|
it "assigns the topic a new category" do
|
92
92
|
subject.recategorize_topic(57, 3)
|
93
|
-
expect(a_put("http://localhost:3000/t/57.json
|
93
|
+
expect(a_put("http://localhost:3000/t/57.json")).to have_been_made
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "#topics_by" do
|
98
98
|
before do
|
99
|
-
stub_get("http://localhost:3000/topics/created-by/test.json
|
99
|
+
stub_get("http://localhost:3000/topics/created-by/test.json").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
|
100
100
|
end
|
101
101
|
|
102
102
|
it "requests the correct resource" do
|
103
103
|
subject.topics_by('test')
|
104
|
-
expect(a_get("http://localhost:3000/topics/created-by/test.json
|
104
|
+
expect(a_get("http://localhost:3000/topics/created-by/test.json")).to have_been_made
|
105
105
|
end
|
106
106
|
|
107
107
|
it "returns the requested topics" do
|
@@ -5,7 +5,7 @@ describe DiscourseApi::API::Uploads do
|
|
5
5
|
|
6
6
|
describe "#upload_file" do
|
7
7
|
before do
|
8
|
-
stub_post("http://localhost:3000/uploads
|
8
|
+
stub_post("http://localhost:3000/uploads").to_return(body: fixture("upload_file.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "uploads an image via URL" do
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::UserActions do
|
|
5
5
|
|
6
6
|
describe "#user_replies" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/user_actions.json?
|
8
|
+
stub_get("http://localhost:3000/user_actions.json?username=testuser&filter=5").to_return(body: fixture("replies.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.user_replies("testuser")
|
13
|
-
expect(a_get("http://localhost:3000/user_actions.json?
|
13
|
+
expect(a_get("http://localhost:3000/user_actions.json?username=testuser&filter=5")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested user" do
|
@@ -21,12 +21,12 @@ describe DiscourseApi::API::UserActions do
|
|
21
21
|
|
22
22
|
describe "#user_topics_and_replies" do
|
23
23
|
before do
|
24
|
-
stub_get("http://localhost:3000/user_actions.json?
|
24
|
+
stub_get("http://localhost:3000/user_actions.json?username=testuser&filter=4,5").to_return(body: fixture("replies_and_topics.json"), headers: { content_type: "application/json" })
|
25
25
|
end
|
26
26
|
|
27
27
|
it "requests the correct resource" do
|
28
28
|
subject.user_topics_and_replies("testuser")
|
29
|
-
expect(a_get("http://localhost:3000/user_actions.json?
|
29
|
+
expect(a_get("http://localhost:3000/user_actions.json?username=testuser&filter=4,5")).to have_been_made
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns the requested user" do
|
@@ -5,12 +5,12 @@ describe DiscourseApi::API::Users do
|
|
5
5
|
|
6
6
|
describe "#user" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/users/test.json
|
8
|
+
stub_get("http://localhost:3000/users/test.json").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "requests the correct resource" do
|
12
12
|
subject.user("test")
|
13
|
-
expect(a_get("http://localhost:3000/users/test.json
|
13
|
+
expect(a_get("http://localhost:3000/users/test.json")).to have_been_made
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns the requested user" do
|
@@ -26,12 +26,12 @@ describe DiscourseApi::API::Users do
|
|
26
26
|
|
27
27
|
describe "#user_sso" do
|
28
28
|
before do
|
29
|
-
stub_get("http://localhost:3000/admin/users/15.json
|
29
|
+
stub_get("http://localhost:3000/admin/users/15.json").to_return(body: fixture("admin_user.json"), headers: { content_type: "application/json" })
|
30
30
|
end
|
31
31
|
|
32
32
|
it "requests the correct resource" do
|
33
33
|
subject.user_sso(15)
|
34
|
-
expect(a_get("http://localhost:3000/admin/users/15.json
|
34
|
+
expect(a_get("http://localhost:3000/admin/users/15.json")).to have_been_made
|
35
35
|
end
|
36
36
|
|
37
37
|
it "has single_sign_on_record" do
|
@@ -43,8 +43,8 @@ describe DiscourseApi::API::Users do
|
|
43
43
|
|
44
44
|
describe "#update_avatar" do
|
45
45
|
before do
|
46
|
-
stub_post("http://localhost:3000/uploads
|
47
|
-
stub_put("http://localhost:3000/users/test_user/preferences/avatar/pick
|
46
|
+
stub_post("http://localhost:3000/uploads").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
|
47
|
+
stub_put("http://localhost:3000/users/test_user/preferences/avatar/pick").to_return(body: fixture("user_update_avatar_success.json"), headers: { content_type: "application/json" })
|
48
48
|
end
|
49
49
|
|
50
50
|
it "uploads an image" do
|
@@ -57,12 +57,12 @@ describe DiscourseApi::API::Users do
|
|
57
57
|
|
58
58
|
describe "#update_email" do
|
59
59
|
before do
|
60
|
-
stub_put("http://localhost:3000/users/fake_user/preferences/email
|
60
|
+
stub_put("http://localhost:3000/users/fake_user/preferences/email").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
61
61
|
end
|
62
62
|
|
63
63
|
it "makes the put request" do
|
64
64
|
subject.update_email("fake_user", "fake_user_2@example.com")
|
65
|
-
expect(a_put("http://localhost:3000/users/fake_user/preferences/email
|
65
|
+
expect(a_put("http://localhost:3000/users/fake_user/preferences/email")).to have_been_made
|
66
66
|
end
|
67
67
|
|
68
68
|
it "returns success" do
|
@@ -73,14 +73,14 @@ describe DiscourseApi::API::Users do
|
|
73
73
|
|
74
74
|
describe "#update_user" do
|
75
75
|
before do
|
76
|
-
stub_put("http://localhost:3000/users/fake_user
|
76
|
+
stub_put("http://localhost:3000/users/fake_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
77
77
|
end
|
78
78
|
|
79
79
|
it "makes the put request" do
|
80
80
|
subject.api_key = 'test_d7fd0429940'
|
81
81
|
subject.api_username = 'test_user'
|
82
82
|
subject.update_user("fake_user", name: "Fake User 2")
|
83
|
-
expect(a_put("http://localhost:3000/users/fake_user
|
83
|
+
expect(a_put("http://localhost:3000/users/fake_user")).to have_been_made
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns success" do
|
@@ -93,12 +93,12 @@ describe DiscourseApi::API::Users do
|
|
93
93
|
|
94
94
|
describe "#update_username" do
|
95
95
|
before do
|
96
|
-
stub_put("http://localhost:3000/users/fake_user/preferences/username
|
96
|
+
stub_put("http://localhost:3000/users/fake_user/preferences/username").to_return(body: fixture("user_update_username.json"), headers: { content_type: "application/json" })
|
97
97
|
end
|
98
98
|
|
99
99
|
it "makes the put request" do
|
100
100
|
subject.update_username("fake_user", "fake_user_2")
|
101
|
-
expect(a_put("http://localhost:3000/users/fake_user/preferences/username
|
101
|
+
expect(a_put("http://localhost:3000/users/fake_user/preferences/username")).to have_been_made
|
102
102
|
end
|
103
103
|
|
104
104
|
it "returns the updated username" do
|
@@ -109,12 +109,12 @@ describe DiscourseApi::API::Users do
|
|
109
109
|
|
110
110
|
describe "#create_user" do
|
111
111
|
before do
|
112
|
-
stub_post("http://localhost:3000/users
|
112
|
+
stub_post("http://localhost:3000/users").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
|
113
113
|
end
|
114
114
|
|
115
115
|
it "makes the post request" do
|
116
116
|
subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
117
|
-
expect(a_post("http://localhost:3000/users
|
117
|
+
expect(a_post("http://localhost:3000/users")).to have_been_made
|
118
118
|
end
|
119
119
|
|
120
120
|
it "returns success" do
|
@@ -126,12 +126,12 @@ describe DiscourseApi::API::Users do
|
|
126
126
|
|
127
127
|
describe "#activate_user" do
|
128
128
|
before do
|
129
|
-
stub_put("http://localhost:3000/admin/users/15/activate
|
129
|
+
stub_put("http://localhost:3000/admin/users/15/activate").to_return(body: fixture("user_activate_success.json"), headers: { content_type: "application/json" })
|
130
130
|
end
|
131
131
|
|
132
132
|
it "makes the put request" do
|
133
133
|
subject.activate(15)
|
134
|
-
expect(a_put("http://localhost:3000/admin/users/15/activate
|
134
|
+
expect(a_put("http://localhost:3000/admin/users/15/activate")).to have_been_made
|
135
135
|
end
|
136
136
|
|
137
137
|
it "returns success" do
|
@@ -142,12 +142,12 @@ describe DiscourseApi::API::Users do
|
|
142
142
|
|
143
143
|
describe "#log_out_success" do
|
144
144
|
before do
|
145
|
-
stub_post("http://localhost:3000/admin/users/4/log_out
|
145
|
+
stub_post("http://localhost:3000/admin/users/4/log_out").to_return(body: fixture("user_log_out_success.json"), headers: { content_type: "application/json" })
|
146
146
|
end
|
147
147
|
|
148
148
|
it "makes a post request" do
|
149
149
|
subject.log_out(4)
|
150
|
-
expect(a_post("http://localhost:3000/admin/users/4/log_out
|
150
|
+
expect(a_post("http://localhost:3000/admin/users/4/log_out")).to have_been_made
|
151
151
|
end
|
152
152
|
|
153
153
|
it "returns success" do
|
@@ -159,7 +159,7 @@ describe DiscourseApi::API::Users do
|
|
159
159
|
|
160
160
|
describe "#log_out_unsuccessful" do
|
161
161
|
before do
|
162
|
-
stub_post("http://localhost:3000/admin/users/90/log_out
|
162
|
+
stub_post("http://localhost:3000/admin/users/90/log_out").to_return(status: 404, headers: { content_type: "application/json" })
|
163
163
|
end
|
164
164
|
|
165
165
|
it "Raises API Error" do
|
@@ -169,12 +169,12 @@ describe DiscourseApi::API::Users do
|
|
169
169
|
|
170
170
|
describe "#list_users" do
|
171
171
|
before do
|
172
|
-
stub_get("http://localhost:3000/admin/users/list/active.json
|
172
|
+
stub_get("http://localhost:3000/admin/users/list/active.json").to_return(body: fixture("user_list.json"), headers: { content_type: "application/json" })
|
173
173
|
end
|
174
174
|
|
175
175
|
it "requests the correct resource" do
|
176
176
|
subject.list_users('active')
|
177
|
-
expect(a_get("http://localhost:3000/admin/users/list/active.json
|
177
|
+
expect(a_get("http://localhost:3000/admin/users/list/active.json")).to have_been_made
|
178
178
|
end
|
179
179
|
|
180
180
|
it "returns the requested users" do
|
@@ -186,7 +186,7 @@ describe DiscourseApi::API::Users do
|
|
186
186
|
|
187
187
|
describe "#update_trust_level" do
|
188
188
|
before do
|
189
|
-
url = "http://localhost:3000/admin/users/2/trust_level
|
189
|
+
url = "http://localhost:3000/admin/users/2/trust_level"
|
190
190
|
stub_put(url).to_return(body: fixture("update_trust_level.json"),
|
191
191
|
headers: { content_type: "application/json" })
|
192
192
|
end
|
@@ -194,7 +194,7 @@ describe DiscourseApi::API::Users do
|
|
194
194
|
it "makes the correct put request" do
|
195
195
|
params = { user_id: 2, level: 2 }
|
196
196
|
subject.update_trust_level(params)
|
197
|
-
url = "http://localhost:3000/admin/users/2/trust_level
|
197
|
+
url = "http://localhost:3000/admin/users/2/trust_level"
|
198
198
|
expect(a_put(url)).to have_been_made
|
199
199
|
end
|
200
200
|
|
@@ -208,14 +208,14 @@ describe DiscourseApi::API::Users do
|
|
208
208
|
|
209
209
|
describe "#grant admin" do
|
210
210
|
before do
|
211
|
-
url = "http://localhost:3000/admin/users/11/grant_admin
|
211
|
+
url = "http://localhost:3000/admin/users/11/grant_admin"
|
212
212
|
stub_put(url).to_return(body: fixture("user_grant_admin.json"),
|
213
213
|
headers: { content_type: "application/json" })
|
214
214
|
end
|
215
215
|
|
216
216
|
it "makes the correct put request" do
|
217
217
|
subject.grant_admin(11)
|
218
|
-
url = "http://localhost:3000/admin/users/11/grant_admin
|
218
|
+
url = "http://localhost:3000/admin/users/11/grant_admin"
|
219
219
|
expect(a_put(url)).to have_been_made
|
220
220
|
end
|
221
221
|
|
@@ -228,12 +228,12 @@ describe DiscourseApi::API::Users do
|
|
228
228
|
|
229
229
|
describe "#by_external_id" do
|
230
230
|
before do
|
231
|
-
stub_get("http://localhost:3000/users/by-external/1
|
231
|
+
stub_get("http://localhost:3000/users/by-external/1").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
232
232
|
end
|
233
233
|
|
234
234
|
it "requests the correct resource" do
|
235
235
|
subject.by_external_id(1)
|
236
|
-
expect(a_get("http://localhost:3000/users/by-external/1
|
236
|
+
expect(a_get("http://localhost:3000/users/by-external/1")).to have_been_made
|
237
237
|
end
|
238
238
|
|
239
239
|
it "returns the requested user" do
|
@@ -244,13 +244,13 @@ describe DiscourseApi::API::Users do
|
|
244
244
|
|
245
245
|
describe "#suspend" do
|
246
246
|
before do
|
247
|
-
url = "http://localhost:3000/admin/users/11/suspend
|
247
|
+
url = "http://localhost:3000/admin/users/11/suspend"
|
248
248
|
stub_put(url).to_return(body: '', status: 200)
|
249
249
|
end
|
250
250
|
|
251
251
|
it "makes the correct put request" do
|
252
252
|
result = subject.suspend(11, '2030-01-01', "no reason")
|
253
|
-
url = "http://localhost:3000/admin/users/11/suspend
|
253
|
+
url = "http://localhost:3000/admin/users/11/suspend"
|
254
254
|
expect(a_put(url)).to have_been_made
|
255
255
|
expect(result.status).to eq(200)
|
256
256
|
end
|
@@ -258,13 +258,13 @@ describe DiscourseApi::API::Users do
|
|
258
258
|
|
259
259
|
describe "#unsuspend" do
|
260
260
|
before do
|
261
|
-
url = "http://localhost:3000/admin/users/11/unsuspend
|
261
|
+
url = "http://localhost:3000/admin/users/11/unsuspend"
|
262
262
|
stub_put(url).to_return(body: '', status: 200)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "makes the correct put request" do
|
266
266
|
result = subject.unsuspend(11)
|
267
|
-
url = "http://localhost:3000/admin/users/11/unsuspend
|
267
|
+
url = "http://localhost:3000/admin/users/11/unsuspend"
|
268
268
|
expect(a_put(url)).to have_been_made
|
269
269
|
expect(result.status).to eq(200)
|
270
270
|
end
|
@@ -272,13 +272,13 @@ describe DiscourseApi::API::Users do
|
|
272
272
|
|
273
273
|
describe "#delete_user" do
|
274
274
|
before do
|
275
|
-
url = "http://localhost:3000/admin/users/11.json?delete_posts=true
|
275
|
+
url = "http://localhost:3000/admin/users/11.json?delete_posts=true"
|
276
276
|
stub_delete(url).to_return(body: '{"deleted": true}', status: 200)
|
277
277
|
end
|
278
278
|
|
279
279
|
it "makes the correct delete request" do
|
280
280
|
result = subject.delete_user(11, true)
|
281
|
-
url = "http://localhost:3000/admin/users/11.json?delete_posts=true
|
281
|
+
url = "http://localhost:3000/admin/users/11.json?delete_posts=true"
|
282
282
|
expect(a_delete(url)).to have_been_made
|
283
283
|
expect(result.body).to eq('{"deleted": true}')
|
284
284
|
expect(result.status).to eq(200)
|
@@ -286,7 +286,7 @@ describe DiscourseApi::API::Users do
|
|
286
286
|
end
|
287
287
|
|
288
288
|
describe "#check_username" do
|
289
|
-
let(:url) { "http://localhost:3000/users/check_username.json?username=sparrow
|
289
|
+
let(:url) { "http://localhost:3000/users/check_username.json?username=sparrow" }
|
290
290
|
let(:body) { '{"available":false,"suggestion":"sparrow1"}' }
|
291
291
|
|
292
292
|
before do
|
@@ -304,7 +304,7 @@ describe DiscourseApi::API::Users do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
context "when non-URI characters are used" do
|
307
|
-
let(:url) { "http://localhost:3000/users/check_username.json?username=1_%5B4%5D%21+%40the%24%23%3F
|
307
|
+
let(:url) { "http://localhost:3000/users/check_username.json?username=1_%5B4%5D%21+%40the%24%23%3F" }
|
308
308
|
let(:body) { '{"errors":["must only include numbers, letters, dashes, and underscores"]}' }
|
309
309
|
|
310
310
|
it "escapes them" do
|
@@ -321,12 +321,12 @@ describe DiscourseApi::API::Users do
|
|
321
321
|
|
322
322
|
describe "#deactivate" do
|
323
323
|
before do
|
324
|
-
stub_put("http://localhost:3000/admin/users/15/deactivate
|
324
|
+
stub_put("http://localhost:3000/admin/users/15/deactivate").to_return(body: nil)
|
325
325
|
end
|
326
326
|
|
327
327
|
it "makes the put request" do
|
328
328
|
subject.deactivate(15)
|
329
|
-
expect(a_put("http://localhost:3000/admin/users/15/deactivate
|
329
|
+
expect(a_put("http://localhost:3000/admin/users/15/deactivate")).to have_been_made
|
330
330
|
end
|
331
331
|
|
332
332
|
it "returns success" 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
|
67
|
+
stub_delete("http://localhost:3000/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
|
74
|
+
expect(a_delete("http://localhost:3000/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
78
|
subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
|
79
79
|
|
80
80
|
before do
|
81
|
-
stub_delete("http://localhost:3000/forum/test/delete
|
81
|
+
stub_delete("http://localhost:3000/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
|
86
|
+
expect(a_delete("http://localhost:3000/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
|
93
|
+
stub_post("http://localhost:3000/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
|
100
|
+
expect(a_post("http://localhost:3000/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
104
|
subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
|
105
105
|
|
106
106
|
before do
|
107
|
-
stub_post("http://localhost:3000/forum/test/post
|
107
|
+
stub_post("http://localhost:3000/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
|
112
|
+
expect(a_post("http://localhost:3000/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
|
119
|
+
stub_put("http://localhost:3000/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
|
126
|
+
expect(a_put("http://localhost:3000/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
130
|
subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
|
131
131
|
|
132
132
|
before do
|
133
|
-
stub_put("http://localhost:3000/forum/test/put
|
133
|
+
stub_put("http://localhost:3000/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
|
138
|
+
expect(a_put("http://localhost:3000/forum/test/put").with(body: { updated: "object" })).to have_been_made
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-
|
14
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|