discourse_api 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -21
- data/.travis.yml +5 -5
- data/CHANGELOG.md +105 -99
- data/Gemfile +4 -4
- data/Guardfile +5 -5
- data/LICENSE.txt +22 -22
- data/README.md +73 -73
- data/Rakefile +7 -7
- data/discourse_api.gemspec +35 -35
- data/examples/backups.rb +18 -18
- data/examples/category.rb +21 -21
- data/examples/change_topic_status.rb +33 -33
- data/examples/create_topic.rb +23 -23
- data/examples/create_user.rb +14 -14
- data/examples/dashboard.rb +13 -13
- data/examples/disposable_invite_tokens.rb +18 -18
- data/examples/example.rb +9 -9
- data/examples/groups.rb +25 -25
- data/examples/invite_users.rb +15 -15
- data/examples/post_action.rb +25 -25
- data/examples/search.rb +9 -9
- data/examples/sso.rb +14 -14
- data/examples/topic_lists.rb +15 -15
- data/examples/update_user.rb +22 -22
- data/lib/discourse_api.rb +5 -5
- data/lib/discourse_api/api/api_key.rb +31 -31
- data/lib/discourse_api/api/backups.rb +24 -24
- data/lib/discourse_api/api/badges.rb +28 -28
- data/lib/discourse_api/api/categories.rb +57 -57
- data/lib/discourse_api/api/dashboard.rb +24 -24
- data/lib/discourse_api/api/email.rb +15 -15
- data/lib/discourse_api/api/groups.rb +52 -52
- data/lib/discourse_api/api/invite.rb +17 -17
- data/lib/discourse_api/api/notifications.rb +9 -9
- data/lib/discourse_api/api/params.rb +55 -55
- data/lib/discourse_api/api/posts.rb +41 -41
- data/lib/discourse_api/api/private_messages.rb +10 -10
- data/lib/discourse_api/api/search.rb +19 -19
- data/lib/discourse_api/api/sso.rb +22 -22
- data/lib/discourse_api/api/tags.rb +10 -10
- data/lib/discourse_api/api/topics.rb +78 -78
- data/lib/discourse_api/api/users.rb +93 -85
- data/lib/discourse_api/client.rb +133 -133
- data/lib/discourse_api/error.rb +17 -17
- data/lib/discourse_api/single_sign_on.rb +110 -110
- data/lib/discourse_api/version.rb +3 -3
- data/routes.txt +203 -203
- data/spec/discourse_api/api/api_key_spec.rb +121 -121
- data/spec/discourse_api/api/backups_spec.rb +23 -23
- data/spec/discourse_api/api/badges_spec.rb +40 -40
- data/spec/discourse_api/api/categories_spec.rb +87 -87
- data/spec/discourse_api/api/email_spec.rb +39 -39
- data/spec/discourse_api/api/groups_spec.rb +94 -94
- data/spec/discourse_api/api/notifications_spec.rb +24 -24
- data/spec/discourse_api/api/params_spec.rb +32 -32
- data/spec/discourse_api/api/posts_spec.rb +41 -41
- data/spec/discourse_api/api/private_messages_spec.rb +22 -22
- data/spec/discourse_api/api/search_spec.rb +30 -30
- data/spec/discourse_api/api/sso_spec.rb +16 -16
- data/spec/discourse_api/api/topics_spec.rb +113 -113
- data/spec/discourse_api/api/users_spec.rb +255 -227
- data/spec/discourse_api/client_spec.rb +115 -115
- data/spec/fixtures/api.json +12 -12
- data/spec/fixtures/backups.json +12 -12
- data/spec/fixtures/badges.json +569 -569
- data/spec/fixtures/categories.json +72 -72
- data/spec/fixtures/category_latest_topics.json +92 -92
- data/spec/fixtures/category_topics.json +91 -91
- data/spec/fixtures/email_list_all.json +749 -749
- data/spec/fixtures/email_settings.json +13 -13
- data/spec/fixtures/generate_api_key.json +12 -12
- data/spec/fixtures/generate_master_key.json +7 -7
- data/spec/fixtures/groups.json +18 -18
- data/spec/fixtures/hot.json +113 -113
- data/spec/fixtures/latest.json +115 -115
- data/spec/fixtures/members_0.json +403 -403
- data/spec/fixtures/members_1.json +363 -363
- data/spec/fixtures/new.json +113 -113
- data/spec/fixtures/notifications.json +16 -16
- data/spec/fixtures/post.json +94 -94
- data/spec/fixtures/post_action_users.json +18 -18
- data/spec/fixtures/private_messages.json +69 -69
- data/spec/fixtures/regenerate_api_key.json +7 -7
- data/spec/fixtures/search.json +24 -24
- data/spec/fixtures/topic.json +739 -739
- data/spec/fixtures/topic_invite_user.json +3 -3
- data/spec/fixtures/topics_created_by.json +49 -49
- data/spec/fixtures/update_trust_level.json +37 -37
- data/spec/fixtures/upload_avatar.json +13 -13
- data/spec/fixtures/user.json +65 -65
- data/spec/fixtures/user_activate_success.json +3 -3
- data/spec/fixtures/user_badges.json +170 -170
- data/spec/fixtures/user_create_success.json +5 -5
- data/spec/fixtures/user_grant_admin.json +37 -37
- data/spec/fixtures/user_list.json +583 -583
- data/spec/fixtures/user_log_out_success.json +3 -3
- data/spec/fixtures/user_update_avatar_success.json +3 -3
- data/spec/fixtures/user_update_user.json +3 -3
- data/spec/fixtures/user_update_username.json +4 -4
- data/spec/spec_helper.rb +61 -61
- metadata +2 -2
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DiscourseApi::API::PrivateMessages do
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
-
|
6
|
-
describe "#private_messages" do
|
7
|
-
before do
|
8
|
-
stub_get("http://localhost:3000/topics/private-messages/test_user.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
|
9
|
-
end
|
10
|
-
|
11
|
-
it "requests the correct resource" do
|
12
|
-
subject.private_messages('test_user')
|
13
|
-
expect(a_get("http://localhost:3000/topics/private-messages/test_user.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns the requested private messages" do
|
17
|
-
private_messages = subject.private_messages('test_user')
|
18
|
-
expect(private_messages).to be_an Array
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::PrivateMessages do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
+
|
6
|
+
describe "#private_messages" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/topics/private-messages/test_user.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.private_messages('test_user')
|
13
|
+
expect(a_get("http://localhost:3000/topics/private-messages/test_user.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested private messages" do
|
17
|
+
private_messages = subject.private_messages('test_user')
|
18
|
+
expect(private_messages).to be_an Array
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DiscourseApi::API::Search do
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
-
|
6
|
-
describe "#search" do
|
7
|
-
before do
|
8
|
-
stub_get("http://localhost:3000/search/query?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
|
9
|
-
end
|
10
|
-
|
11
|
-
it "requests the correct resource" do
|
12
|
-
subject.search("test")
|
13
|
-
expect(a_get("http://localhost:3000/search/query?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} )).to have_been_made
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns the requested search" do
|
17
|
-
results = subject.search("test")
|
18
|
-
expect(results).to be_an Array
|
19
|
-
expect(results.first).to be_a Hash
|
20
|
-
end
|
21
|
-
|
22
|
-
it "raises an ArgumentError for nil" do
|
23
|
-
expect { subject.search(nil) }.to raise_error(ArgumentError)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "raises an ArgumentError for empty string" do
|
27
|
-
expect { subject.search('') }.to raise_error(ArgumentError)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Search do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#search" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/search/query?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.search("test")
|
13
|
+
expect(a_get("http://localhost:3000/search/query?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} )).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested search" do
|
17
|
+
results = subject.search("test")
|
18
|
+
expect(results).to be_an Array
|
19
|
+
expect(results.first).to be_a Hash
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an ArgumentError for nil" do
|
23
|
+
expect { subject.search(nil) }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an ArgumentError for empty string" do
|
27
|
+
expect { subject.search('') }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DiscourseApi::API::SSO do
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
-
|
6
|
-
describe "#sync_sso" do
|
7
|
-
before do
|
8
|
-
stub_post(/.*sync_sso.*/).to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
9
|
-
end
|
10
|
-
|
11
|
-
it "requests the correct resource" do
|
12
|
-
subject.sync_sso({sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test"})
|
13
|
-
expect(a_post(/.*sync_sso.*/)).to have_been_made
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::SSO do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#sync_sso" do
|
7
|
+
before do
|
8
|
+
stub_post(/.*sync_sso.*/).to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.sync_sso({sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test"})
|
13
|
+
expect(a_post(/.*sync_sso.*/)).to have_been_made
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,113 +1,113 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DiscourseApi::API::Topics do
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
-
|
6
|
-
describe "#invite_user_to_topic" do
|
7
|
-
before do
|
8
|
-
stub_post("http://localhost:3000/t/12/invite?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
|
9
|
-
end
|
10
|
-
|
11
|
-
it "requests the correct resource" do
|
12
|
-
subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
13
|
-
expect(a_post("http://localhost:3000/t/12/invite?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns success" do
|
17
|
-
response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
18
|
-
expect(response).to be_a Hash
|
19
|
-
expect(response['success']).to be_truthy
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#latest_topics" do
|
24
|
-
before do
|
25
|
-
stub_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
|
26
|
-
end
|
27
|
-
|
28
|
-
it "requests the correct resource" do
|
29
|
-
subject.latest_topics
|
30
|
-
expect(a_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns the requested topics" do
|
34
|
-
topics = subject.latest_topics
|
35
|
-
expect(topics).to be_an Array
|
36
|
-
expect(topics.first).to be_a Hash
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can take a hash param" do
|
40
|
-
topics = subject.latest_topics({})
|
41
|
-
expect(topics).to be_an Array
|
42
|
-
expect(topics.first).to be_a Hash
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#new_topics" do
|
47
|
-
before do
|
48
|
-
stub_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
|
49
|
-
end
|
50
|
-
|
51
|
-
it "requests the correct resource" do
|
52
|
-
subject.new_topics
|
53
|
-
expect(a_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns the requested topics" do
|
57
|
-
subject.api_username = 'test_user'
|
58
|
-
topics = subject.new_topics
|
59
|
-
expect(topics).to be_an Array
|
60
|
-
expect(topics.first).to be_a Hash
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#topic" do
|
65
|
-
before do
|
66
|
-
stub_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
67
|
-
end
|
68
|
-
|
69
|
-
it "requests the correct resource" do
|
70
|
-
subject.topic(57)
|
71
|
-
expect(a_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
72
|
-
end
|
73
|
-
|
74
|
-
it "returns the requested topic" do
|
75
|
-
topic = subject.topic(57)
|
76
|
-
expect(topic).to be_a Hash
|
77
|
-
expect(topic["id"]).to eq(57)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#update_topic" do
|
82
|
-
before do
|
83
|
-
stub_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
84
|
-
end
|
85
|
-
|
86
|
-
it "renames the topic" do
|
87
|
-
subject.rename_topic(57, "A new title!")
|
88
|
-
expect(a_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
89
|
-
end
|
90
|
-
|
91
|
-
it "assigns the topic a new category" do
|
92
|
-
subject.recategorize_topic(57, 3)
|
93
|
-
expect(a_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#topics_by" do
|
98
|
-
before do
|
99
|
-
stub_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
|
100
|
-
end
|
101
|
-
|
102
|
-
it "requests the correct resource" do
|
103
|
-
subject.topics_by('test')
|
104
|
-
expect(a_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns the requested topics" do
|
108
|
-
topics = subject.topics_by('test')
|
109
|
-
expect(topics).to be_an Array
|
110
|
-
expect(topics.first).to be_a Hash
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Topics do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
+
|
6
|
+
describe "#invite_user_to_topic" do
|
7
|
+
before do
|
8
|
+
stub_post("http://localhost:3000/t/12/invite?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
13
|
+
expect(a_post("http://localhost:3000/t/12/invite?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns success" do
|
17
|
+
response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
18
|
+
expect(response).to be_a Hash
|
19
|
+
expect(response['success']).to be_truthy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#latest_topics" do
|
24
|
+
before do
|
25
|
+
stub_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
|
26
|
+
end
|
27
|
+
|
28
|
+
it "requests the correct resource" do
|
29
|
+
subject.latest_topics
|
30
|
+
expect(a_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns the requested topics" do
|
34
|
+
topics = subject.latest_topics
|
35
|
+
expect(topics).to be_an Array
|
36
|
+
expect(topics.first).to be_a Hash
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can take a hash param" do
|
40
|
+
topics = subject.latest_topics({})
|
41
|
+
expect(topics).to be_an Array
|
42
|
+
expect(topics.first).to be_a Hash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#new_topics" do
|
47
|
+
before do
|
48
|
+
stub_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
|
49
|
+
end
|
50
|
+
|
51
|
+
it "requests the correct resource" do
|
52
|
+
subject.new_topics
|
53
|
+
expect(a_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns the requested topics" do
|
57
|
+
subject.api_username = 'test_user'
|
58
|
+
topics = subject.new_topics
|
59
|
+
expect(topics).to be_an Array
|
60
|
+
expect(topics.first).to be_a Hash
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#topic" do
|
65
|
+
before do
|
66
|
+
stub_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
67
|
+
end
|
68
|
+
|
69
|
+
it "requests the correct resource" do
|
70
|
+
subject.topic(57)
|
71
|
+
expect(a_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns the requested topic" do
|
75
|
+
topic = subject.topic(57)
|
76
|
+
expect(topic).to be_a Hash
|
77
|
+
expect(topic["id"]).to eq(57)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#update_topic" do
|
82
|
+
before do
|
83
|
+
stub_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
|
84
|
+
end
|
85
|
+
|
86
|
+
it "renames the topic" do
|
87
|
+
subject.rename_topic(57, "A new title!")
|
88
|
+
expect(a_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "assigns the topic a new category" do
|
92
|
+
subject.recategorize_topic(57, 3)
|
93
|
+
expect(a_put("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#topics_by" do
|
98
|
+
before do
|
99
|
+
stub_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
|
100
|
+
end
|
101
|
+
|
102
|
+
it "requests the correct resource" do
|
103
|
+
subject.topics_by('test')
|
104
|
+
expect(a_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns the requested topics" do
|
108
|
+
topics = subject.topics_by('test')
|
109
|
+
expect(topics).to be_an Array
|
110
|
+
expect(topics.first).to be_a Hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -1,227 +1,255 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DiscourseApi::API::Users do
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
-
|
6
|
-
describe "#user" do
|
7
|
-
before do
|
8
|
-
stub_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
9
|
-
end
|
10
|
-
|
11
|
-
it "requests the correct resource" do
|
12
|
-
subject.user("test")
|
13
|
-
expect(a_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns the requested user" do
|
17
|
-
user = subject.user("test")
|
18
|
-
expect(user).to be_a Hash
|
19
|
-
end
|
20
|
-
|
21
|
-
it "works with optional params" do
|
22
|
-
user = subject.user("test", {})
|
23
|
-
expect(user).to be_a Hash
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#update_avatar" do
|
28
|
-
before do
|
29
|
-
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
|
30
|
-
stub_put("http://localhost:3000/users/test_user/preferences/avatar/pick?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_avatar_success.json"), headers: { content_type: "application/json" })
|
31
|
-
end
|
32
|
-
|
33
|
-
it "uploads an image" do
|
34
|
-
sam = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
35
|
-
args = { username: 'test_user', url: sam }
|
36
|
-
response = subject.update_avatar(args)
|
37
|
-
expect(response[:body]['success']).to eq('OK')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#update_email" do
|
42
|
-
before do
|
43
|
-
stub_put("http://localhost:3000/users/fake_user/preferences/email?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
44
|
-
end
|
45
|
-
|
46
|
-
it "makes the put request" do
|
47
|
-
subject.update_email("fake_user", "fake_user_2@example.com")
|
48
|
-
expect(a_put("http://localhost:3000/users/fake_user/preferences/email?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
49
|
-
end
|
50
|
-
|
51
|
-
it "returns success" do
|
52
|
-
response = subject.update_email("fake_user", "fake_user_2@example.com")
|
53
|
-
expect(response[:body]['success']).to be_truthy
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#update_user" do
|
58
|
-
before do
|
59
|
-
stub_put("http://localhost:3000/users/fake_user?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
60
|
-
end
|
61
|
-
|
62
|
-
it "makes the put request" do
|
63
|
-
subject.api_key = 'test_d7fd0429940'
|
64
|
-
subject.api_username = 'test_user'
|
65
|
-
subject.update_user("fake_user", name: "Fake User 2")
|
66
|
-
expect(a_put("http://localhost:3000/users/fake_user?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
67
|
-
end
|
68
|
-
|
69
|
-
it "returns success" do
|
70
|
-
subject.api_key = 'test_d7fd0429940'
|
71
|
-
subject.api_username = 'test_user'
|
72
|
-
response = subject.update_user("fake_user", name: "Fake User 2")
|
73
|
-
expect(response[:body]['success']).to be_truthy
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#update_username" do
|
78
|
-
before do
|
79
|
-
stub_put("http://localhost:3000/users/fake_user/preferences/username?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_username.json"), headers: { content_type: "application/json" })
|
80
|
-
end
|
81
|
-
|
82
|
-
it "makes the put request" do
|
83
|
-
subject.update_username("fake_user", "fake_user_2")
|
84
|
-
expect(a_put("http://localhost:3000/users/fake_user/preferences/username?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns the updated username" do
|
88
|
-
response = subject.update_username("fake_user", "fake_user_2")
|
89
|
-
expect(response[:body]['username']).to eq('fake_user_2')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "#create_user" do
|
94
|
-
before do
|
95
|
-
stub_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
|
96
|
-
end
|
97
|
-
|
98
|
-
it "makes the post request" do
|
99
|
-
subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
100
|
-
expect(a_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
101
|
-
end
|
102
|
-
|
103
|
-
it "returns success" do
|
104
|
-
response = subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
105
|
-
expect(response).to be_a Hash
|
106
|
-
expect(response['success']).to be_truthy
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#activate_user" do
|
111
|
-
before do
|
112
|
-
stub_put("http://localhost:3000/admin/users/15/activate?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_activate_success.json"), headers: { content_type: "application/json" })
|
113
|
-
end
|
114
|
-
|
115
|
-
it "makes the put request" do
|
116
|
-
subject.activate(15)
|
117
|
-
expect(a_put("http://localhost:3000/admin/users/15/activate?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
118
|
-
end
|
119
|
-
|
120
|
-
it "returns success" do
|
121
|
-
response = subject.activate(15)
|
122
|
-
expect(response[:body]['success']).to eq('OK')
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#log_out_success" do
|
127
|
-
before do
|
128
|
-
stub_post("http://localhost:3000/admin/users/4/log_out?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_log_out_success.json"), headers: { content_type: "application/json" })
|
129
|
-
end
|
130
|
-
|
131
|
-
it "makes a post request" do
|
132
|
-
subject.log_out(4)
|
133
|
-
expect(a_post("http://localhost:3000/admin/users/4/log_out?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
134
|
-
end
|
135
|
-
|
136
|
-
it "returns success" do
|
137
|
-
response = subject.log_out(4)
|
138
|
-
expect(response).to be_a Hash
|
139
|
-
expect(response['success']).to eq('OK')
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "#log_out_unsuccessful" do
|
144
|
-
before do
|
145
|
-
stub_post("http://localhost:3000/admin/users/90/log_out?api_key=test_d7fd0429940&api_username=test_user").to_return(status: 404, headers: { content_type: "application/json" })
|
146
|
-
end
|
147
|
-
|
148
|
-
it "Raises API Error" do
|
149
|
-
expect{subject.log_out(90)}.to raise_error DiscourseApi::Error
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "#list_users" do
|
154
|
-
before do
|
155
|
-
stub_get("http://localhost:3000/admin/users/list/active.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_list.json"), headers: { content_type: "application/json" })
|
156
|
-
end
|
157
|
-
|
158
|
-
it "requests the correct resource" do
|
159
|
-
subject.list_users('active')
|
160
|
-
expect(a_get("http://localhost:3000/admin/users/list/active.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
161
|
-
end
|
162
|
-
|
163
|
-
it "returns the requested users" do
|
164
|
-
users = subject.list_users('active')
|
165
|
-
expect(users).to be_an Array
|
166
|
-
expect(users.first).to be_a Hash
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "#update_trust_level" do
|
171
|
-
before do
|
172
|
-
url = "http://localhost:3000/admin/users/2/trust_level?api_key=test_d7fd0429940&api_username=test_user"
|
173
|
-
stub_put(url).to_return(body: fixture("update_trust_level.json"),
|
174
|
-
headers: { content_type: "application/json" })
|
175
|
-
end
|
176
|
-
|
177
|
-
it "makes the correct put request" do
|
178
|
-
params = { user_id: 2, level: 2 }
|
179
|
-
subject.update_trust_level(params)
|
180
|
-
url = "http://localhost:3000/admin/users/2/trust_level?api_key=test_d7fd0429940&api_username=test_user"
|
181
|
-
expect(a_put(url)).to have_been_made
|
182
|
-
end
|
183
|
-
|
184
|
-
it "updates the trust_level" do
|
185
|
-
params = { user_id: 2, level: 2 }
|
186
|
-
admin_user = subject.update_trust_level(params)
|
187
|
-
expect(admin_user).to be_a Hash
|
188
|
-
expect(admin_user['admin_user']).to have_key('trust_level')
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "#grant admin" do
|
193
|
-
before do
|
194
|
-
url = "http://localhost:3000/admin/users/11/grant_admin?api_key=test_d7fd0429940&api_username=test_user"
|
195
|
-
stub_put(url).to_return(body: fixture("user_grant_admin.json"),
|
196
|
-
headers: { content_type: "application/json" })
|
197
|
-
end
|
198
|
-
|
199
|
-
it "makes the correct put request" do
|
200
|
-
result = subject.grant_admin(11)
|
201
|
-
url = "http://localhost:3000/admin/users/11/grant_admin?api_key=test_d7fd0429940&api_username=test_user"
|
202
|
-
expect(a_put(url)).to have_been_made
|
203
|
-
end
|
204
|
-
|
205
|
-
it "makes the user an admin" do
|
206
|
-
result = subject.grant_admin(11)
|
207
|
-
expect(result).to be_a Hash
|
208
|
-
expect(result['admin_user']['admin']).to eq(true)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "#by_external_id" do
|
213
|
-
before do
|
214
|
-
stub_get("http://localhost:3000/users/by-external/1?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
215
|
-
end
|
216
|
-
|
217
|
-
it "requests the correct resource" do
|
218
|
-
subject.by_external_id(1)
|
219
|
-
expect(a_get("http://localhost:3000/users/by-external/1?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
220
|
-
end
|
221
|
-
|
222
|
-
it "returns the requested user" do
|
223
|
-
user = subject.by_external_id(1)
|
224
|
-
expect(user['id']).to eq 1
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Users do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
+
|
6
|
+
describe "#user" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.user("test")
|
13
|
+
expect(a_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested user" do
|
17
|
+
user = subject.user("test")
|
18
|
+
expect(user).to be_a Hash
|
19
|
+
end
|
20
|
+
|
21
|
+
it "works with optional params" do
|
22
|
+
user = subject.user("test", {})
|
23
|
+
expect(user).to be_a Hash
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#update_avatar" do
|
28
|
+
before do
|
29
|
+
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
|
30
|
+
stub_put("http://localhost:3000/users/test_user/preferences/avatar/pick?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_avatar_success.json"), headers: { content_type: "application/json" })
|
31
|
+
end
|
32
|
+
|
33
|
+
it "uploads an image" do
|
34
|
+
sam = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
35
|
+
args = { username: 'test_user', url: sam }
|
36
|
+
response = subject.update_avatar(args)
|
37
|
+
expect(response[:body]['success']).to eq('OK')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#update_email" do
|
42
|
+
before do
|
43
|
+
stub_put("http://localhost:3000/users/fake_user/preferences/email?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
44
|
+
end
|
45
|
+
|
46
|
+
it "makes the put request" do
|
47
|
+
subject.update_email("fake_user", "fake_user_2@example.com")
|
48
|
+
expect(a_put("http://localhost:3000/users/fake_user/preferences/email?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns success" do
|
52
|
+
response = subject.update_email("fake_user", "fake_user_2@example.com")
|
53
|
+
expect(response[:body]['success']).to be_truthy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#update_user" do
|
58
|
+
before do
|
59
|
+
stub_put("http://localhost:3000/users/fake_user?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
|
60
|
+
end
|
61
|
+
|
62
|
+
it "makes the put request" do
|
63
|
+
subject.api_key = 'test_d7fd0429940'
|
64
|
+
subject.api_username = 'test_user'
|
65
|
+
subject.update_user("fake_user", name: "Fake User 2")
|
66
|
+
expect(a_put("http://localhost:3000/users/fake_user?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns success" do
|
70
|
+
subject.api_key = 'test_d7fd0429940'
|
71
|
+
subject.api_username = 'test_user'
|
72
|
+
response = subject.update_user("fake_user", name: "Fake User 2")
|
73
|
+
expect(response[:body]['success']).to be_truthy
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#update_username" do
|
78
|
+
before do
|
79
|
+
stub_put("http://localhost:3000/users/fake_user/preferences/username?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_username.json"), headers: { content_type: "application/json" })
|
80
|
+
end
|
81
|
+
|
82
|
+
it "makes the put request" do
|
83
|
+
subject.update_username("fake_user", "fake_user_2")
|
84
|
+
expect(a_put("http://localhost:3000/users/fake_user/preferences/username?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns the updated username" do
|
88
|
+
response = subject.update_username("fake_user", "fake_user_2")
|
89
|
+
expect(response[:body]['username']).to eq('fake_user_2')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#create_user" do
|
94
|
+
before do
|
95
|
+
stub_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
|
96
|
+
end
|
97
|
+
|
98
|
+
it "makes the post request" do
|
99
|
+
subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
100
|
+
expect(a_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns success" do
|
104
|
+
response = subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
105
|
+
expect(response).to be_a Hash
|
106
|
+
expect(response['success']).to be_truthy
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#activate_user" do
|
111
|
+
before do
|
112
|
+
stub_put("http://localhost:3000/admin/users/15/activate?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_activate_success.json"), headers: { content_type: "application/json" })
|
113
|
+
end
|
114
|
+
|
115
|
+
it "makes the put request" do
|
116
|
+
subject.activate(15)
|
117
|
+
expect(a_put("http://localhost:3000/admin/users/15/activate?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns success" do
|
121
|
+
response = subject.activate(15)
|
122
|
+
expect(response[:body]['success']).to eq('OK')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#log_out_success" do
|
127
|
+
before do
|
128
|
+
stub_post("http://localhost:3000/admin/users/4/log_out?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_log_out_success.json"), headers: { content_type: "application/json" })
|
129
|
+
end
|
130
|
+
|
131
|
+
it "makes a post request" do
|
132
|
+
subject.log_out(4)
|
133
|
+
expect(a_post("http://localhost:3000/admin/users/4/log_out?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
134
|
+
end
|
135
|
+
|
136
|
+
it "returns success" do
|
137
|
+
response = subject.log_out(4)
|
138
|
+
expect(response).to be_a Hash
|
139
|
+
expect(response['success']).to eq('OK')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#log_out_unsuccessful" do
|
144
|
+
before do
|
145
|
+
stub_post("http://localhost:3000/admin/users/90/log_out?api_key=test_d7fd0429940&api_username=test_user").to_return(status: 404, headers: { content_type: "application/json" })
|
146
|
+
end
|
147
|
+
|
148
|
+
it "Raises API Error" do
|
149
|
+
expect{subject.log_out(90)}.to raise_error DiscourseApi::Error
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#list_users" do
|
154
|
+
before do
|
155
|
+
stub_get("http://localhost:3000/admin/users/list/active.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_list.json"), headers: { content_type: "application/json" })
|
156
|
+
end
|
157
|
+
|
158
|
+
it "requests the correct resource" do
|
159
|
+
subject.list_users('active')
|
160
|
+
expect(a_get("http://localhost:3000/admin/users/list/active.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
161
|
+
end
|
162
|
+
|
163
|
+
it "returns the requested users" do
|
164
|
+
users = subject.list_users('active')
|
165
|
+
expect(users).to be_an Array
|
166
|
+
expect(users.first).to be_a Hash
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "#update_trust_level" do
|
171
|
+
before do
|
172
|
+
url = "http://localhost:3000/admin/users/2/trust_level?api_key=test_d7fd0429940&api_username=test_user"
|
173
|
+
stub_put(url).to_return(body: fixture("update_trust_level.json"),
|
174
|
+
headers: { content_type: "application/json" })
|
175
|
+
end
|
176
|
+
|
177
|
+
it "makes the correct put request" do
|
178
|
+
params = { user_id: 2, level: 2 }
|
179
|
+
subject.update_trust_level(params)
|
180
|
+
url = "http://localhost:3000/admin/users/2/trust_level?api_key=test_d7fd0429940&api_username=test_user"
|
181
|
+
expect(a_put(url)).to have_been_made
|
182
|
+
end
|
183
|
+
|
184
|
+
it "updates the trust_level" do
|
185
|
+
params = { user_id: 2, level: 2 }
|
186
|
+
admin_user = subject.update_trust_level(params)
|
187
|
+
expect(admin_user).to be_a Hash
|
188
|
+
expect(admin_user['admin_user']).to have_key('trust_level')
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#grant admin" do
|
193
|
+
before do
|
194
|
+
url = "http://localhost:3000/admin/users/11/grant_admin?api_key=test_d7fd0429940&api_username=test_user"
|
195
|
+
stub_put(url).to_return(body: fixture("user_grant_admin.json"),
|
196
|
+
headers: { content_type: "application/json" })
|
197
|
+
end
|
198
|
+
|
199
|
+
it "makes the correct put request" do
|
200
|
+
result = subject.grant_admin(11)
|
201
|
+
url = "http://localhost:3000/admin/users/11/grant_admin?api_key=test_d7fd0429940&api_username=test_user"
|
202
|
+
expect(a_put(url)).to have_been_made
|
203
|
+
end
|
204
|
+
|
205
|
+
it "makes the user an admin" do
|
206
|
+
result = subject.grant_admin(11)
|
207
|
+
expect(result).to be_a Hash
|
208
|
+
expect(result['admin_user']['admin']).to eq(true)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#by_external_id" do
|
213
|
+
before do
|
214
|
+
stub_get("http://localhost:3000/users/by-external/1?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
|
215
|
+
end
|
216
|
+
|
217
|
+
it "requests the correct resource" do
|
218
|
+
subject.by_external_id(1)
|
219
|
+
expect(a_get("http://localhost:3000/users/by-external/1?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
220
|
+
end
|
221
|
+
|
222
|
+
it "returns the requested user" do
|
223
|
+
user = subject.by_external_id(1)
|
224
|
+
expect(user['id']).to eq 1
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "#suspend" do
|
229
|
+
before do
|
230
|
+
url = "http://localhost:3000/admin/users/11/suspend?api_key=test_d7fd0429940&api_username=test_user"
|
231
|
+
stub_put(url).to_return(body: '', status: 200)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "makes the correct put request" do
|
235
|
+
result = subject.suspend(11, 1, "no reason")
|
236
|
+
url = "http://localhost:3000/admin/users/11/suspend?api_key=test_d7fd0429940&api_username=test_user"
|
237
|
+
expect(a_put(url)).to have_been_made
|
238
|
+
expect(result.status).to eq(200)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#unsuspend" do
|
243
|
+
before do
|
244
|
+
url = "http://localhost:3000/admin/users/11/unsuspend?api_key=test_d7fd0429940&api_username=test_user"
|
245
|
+
stub_put(url).to_return(body: '', status: 200)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "makes the correct put request" do
|
249
|
+
result = subject.unsuspend(11)
|
250
|
+
url = "http://localhost:3000/admin/users/11/unsuspend?api_key=test_d7fd0429940&api_username=test_user"
|
251
|
+
expect(a_put(url)).to have_been_made
|
252
|
+
expect(result.status).to eq(200)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|