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,17 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Notifications do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#notifications" do
7
7
 
8
8
  before do
9
- stub_get("http://localhost:3000/notifications.json").to_return(body: fixture("notifications.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/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")).to have_been_made
14
+ expect(a_get("#{host}/notifications.json")).to have_been_made
15
15
  end
16
16
 
17
17
  it "returns the requested notifications" do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Polls do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#poll vote" do
7
7
  before do
8
- path = "http://localhost:3000/polls/vote"
8
+ path = "#{host}/polls/vote"
9
9
  stub_put(path)
10
10
  .to_return(body: fixture("polls_vote.json"), headers: { content_type: "application/json" })
11
11
 
@@ -14,7 +14,7 @@ describe DiscourseApi::API::Polls do
14
14
  it "requests the correct resource" do
15
15
  options = ['8b4736b1ae3dfb5a28088530f036f9e5']
16
16
  subject.poll_vote post_id: 5, poll_name: 'poll', options: options
17
- expect(a_put("http://localhost:3000/polls/vote")).to have_been_made
17
+ expect(a_put("#{host}/polls/vote")).to have_been_made
18
18
  end
19
19
 
20
20
  it "returns the expected votes" do
@@ -27,7 +27,7 @@ describe DiscourseApi::API::Polls do
27
27
 
28
28
  describe "#poll toggle_status" do
29
29
  before do
30
- path = "http://localhost:3000/polls/toggle_status"
30
+ path = "#{host}/polls/toggle_status"
31
31
  stub_put(path)
32
32
  .to_return(body: fixture("polls_toggle_status.json"), headers: { content_type: "application/json" })
33
33
 
@@ -35,7 +35,7 @@ describe DiscourseApi::API::Polls do
35
35
 
36
36
  it "toggles the poll status to closed" do
37
37
  subject.toggle_poll_status post_id: 5, poll_name: 'poll', status: 'closed'
38
- expect(a_put("http://localhost:3000/polls/toggle_status")).to have_been_made
38
+ expect(a_put("#{host}/polls/toggle_status")).to have_been_made
39
39
  end
40
40
 
41
41
  it "returns the expected results of closed poll" do
@@ -48,13 +48,13 @@ describe DiscourseApi::API::Polls do
48
48
 
49
49
  describe "#poll voters" do
50
50
  before do
51
- stub_get("http://localhost:3000/polls/voters.json?post_id=5&poll_name=poll")
51
+ stub_get("#{host}/polls/voters.json?post_id=5&poll_name=poll")
52
52
  .to_return(body: fixture("polls_voters.json"), headers: { content_type: "application/json" })
53
53
  end
54
54
 
55
55
  it "requests the correct resource" do
56
56
  subject.poll_voters post_id: 5, poll_name: 'poll'
57
- expect(a_get("http://localhost:3000/polls/voters.json?post_id=5&poll_name=poll")).to have_been_made
57
+ expect(a_get("#{host}/polls/voters.json?post_id=5&poll_name=poll")).to have_been_made
58
58
  end
59
59
 
60
60
  it "returns the expected votes" do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Posts do
4
- let (:client) { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ let (:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#get_post" do
7
7
  before do
8
- stub_get("http://localhost:3000/posts/11.json").to_return(body: fixture("post.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/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("#{host}/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")).to have_been_made
25
+ expect(a_put("#{host}/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("#{host}/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")).to have_been_made
36
+ expect(a_delete("#{host}/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?id=11&post_action_type_id=2").to_return(body: fixture("post_action_users.json"), headers: { content_type: "application/json" })
42
+ stub_get("#{host}/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
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::PrivateMessages do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#private_messages" do
7
7
  before do
8
- stub_get("http://localhost:3000/topics/private-messages/test_user.json").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/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")).to have_been_made
13
+ expect(a_get("#{host}/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").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
24
+ stub_get("#{host}/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")).to have_been_made
29
+ expect(a_get("#{host}/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("#{host}/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").with(body:
49
+ expect(a_post("#{host}/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
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Search do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#search" do
7
7
  before do
8
- stub_get("http://localhost:3000/search/query").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/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").with(query: { term: "test"} )).to have_been_made
13
+ expect(a_get("#{host}/search/query").with(query: { term: "test"} )).to have_been_made
14
14
  end
15
15
 
16
16
  it "returns the requested search" do
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::SiteSettings do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
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("#{host}/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("#{host}/admin/site_settings/foo")
14
14
  .with(body: "foo=bar")).to have_been_made
15
15
  end
16
16
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::SSO do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#sync_sso" do
7
7
  before do
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Topics do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#invite_user_to_topic" do
7
7
  before do
8
- stub_post("http://localhost:3000/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
8
+ stub_post("#{host}/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")).to have_been_made
13
+ expect(a_post("#{host}/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").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
25
+ stub_get("#{host}/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")).to have_been_made
30
+ expect(a_get("#{host}/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").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
48
+ stub_get("#{host}/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")).to have_been_made
53
+ expect(a_get("#{host}/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").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
66
+ stub_get("#{host}/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")).to have_been_made
71
+ expect(a_get("#{host}/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").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
83
+ stub_put("#{host}/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")).to have_been_made
88
+ expect(a_put("#{host}/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")).to have_been_made
93
+ expect(a_put("#{host}/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").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
99
+ stub_get("#{host}/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")).to have_been_made
104
+ expect(a_get("#{host}/topics/created-by/test.json")).to have_been_made
105
105
  end
106
106
 
107
107
  it "returns the requested topics" do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Uploads do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#upload_file" do
7
7
  before do
8
- stub_post("http://localhost:3000/uploads").to_return(body: fixture("upload_file.json"), headers: { content_type: "application/json" })
8
+ stub_post("#{host}/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
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::UserActions do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#user_replies" do
7
7
  before do
8
- stub_get("http://localhost:3000/user_actions.json?username=testuser&filter=5").to_return(body: fixture("replies.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/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?username=testuser&filter=5")).to have_been_made
13
+ expect(a_get("#{host}/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?username=testuser&filter=4,5").to_return(body: fixture("replies_and_topics.json"), headers: { content_type: "application/json" })
24
+ stub_get("#{host}/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?username=testuser&filter=4,5")).to have_been_made
29
+ expect(a_get("#{host}/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
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Users do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
5
 
6
6
  describe "#user" do
7
7
  before do
8
- stub_get("http://localhost:3000/users/test.json").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/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")).to have_been_made
13
+ expect(a_get("#{host}/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").to_return(body: fixture("admin_user.json"), headers: { content_type: "application/json" })
29
+ stub_get("#{host}/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")).to have_been_made
34
+ expect(a_get("#{host}/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").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
47
- stub_put("http://localhost:3000/u/test_user/preferences/avatar/pick").to_return(body: fixture("user_update_avatar_success.json"), headers: { content_type: "application/json" })
46
+ stub_post("#{host}/uploads").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
47
+ stub_put("#{host}/u/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/u/fake_user/preferences/email").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
60
+ stub_put("#{host}/u/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/u/fake_user/preferences/email")).to have_been_made
65
+ expect(a_put("#{host}/u/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/u/fake_user").to_return(body: fixture("user_update_user.json"), headers: { content_type: "application/json" })
76
+ stub_put("#{host}/u/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/u/fake_user")).to have_been_made
83
+ expect(a_put("#{host}/u/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/u/fake_user/preferences/username").to_return(body: fixture("user_update_username.json"), headers: { content_type: "application/json" })
96
+ stub_put("#{host}/u/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/u/fake_user/preferences/username")).to have_been_made
101
+ expect(a_put("#{host}/u/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").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
112
+ stub_post("#{host}/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")).to have_been_made
117
+ expect(a_post("#{host}/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").to_return(body: fixture("user_activate_success.json"), headers: { content_type: "application/json" })
129
+ stub_put("#{host}/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")).to have_been_made
134
+ expect(a_put("#{host}/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").to_return(body: fixture("user_log_out_success.json"), headers: { content_type: "application/json" })
145
+ stub_post("#{host}/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")).to have_been_made
150
+ expect(a_post("#{host}/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").to_return(status: 404, headers: { content_type: "application/json" })
162
+ stub_post("#{host}/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").to_return(body: fixture("user_list.json"), headers: { content_type: "application/json" })
172
+ stub_get("#{host}/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")).to have_been_made
177
+ expect(a_get("#{host}/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 = "#{host}/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 = { level: 2 }
196
196
  subject.update_trust_level(2, params)
197
- url = "http://localhost:3000/admin/users/2/trust_level"
197
+ url = "#{host}/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 = "#{host}/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 = "#{host}/admin/users/11/grant_admin"
219
219
  expect(a_put(url)).to have_been_made
220
220
  end
221
221
 
@@ -228,14 +228,14 @@ describe DiscourseApi::API::Users do
228
228
 
229
229
  describe "#grant moderation" do
230
230
  before do
231
- url = "http://localhost:3000/admin/users/11/grant_moderation"
231
+ url = "#{host}/admin/users/11/grant_moderation"
232
232
  stub_put(url).to_return(body: fixture("user_grant_moderator.json"),
233
233
  headers: { content_type: "application/json" })
234
234
  end
235
235
 
236
236
  it "makes the correct put request" do
237
237
  subject.grant_moderation(11)
238
- url = "http://localhost:3000/admin/users/11/grant_moderation"
238
+ url = "#{host}/admin/users/11/grant_moderation"
239
239
  expect(a_put(url)).to have_been_made
240
240
  end
241
241
 
@@ -248,13 +248,13 @@ describe DiscourseApi::API::Users do
248
248
 
249
249
  describe "#revoke moderation" do
250
250
  before do
251
- url = "http://localhost:3000/admin/users/11/revoke_moderation"
251
+ url = "#{host}/admin/users/11/revoke_moderation"
252
252
  stub_put(url).to_return(body: '', status: 200)
253
253
  end
254
254
 
255
255
  it "makes the correct put request" do
256
256
  result = subject.revoke_moderation(11)
257
- url = "http://localhost:3000/admin/users/11/revoke_moderation"
257
+ url = "#{host}/admin/users/11/revoke_moderation"
258
258
  expect(a_put(url)).to have_been_made
259
259
  expect(result.status).to eq(200)
260
260
  end
@@ -263,12 +263,12 @@ describe DiscourseApi::API::Users do
263
263
 
264
264
  describe "#by_external_id" do
265
265
  before do
266
- stub_get("http://localhost:3000/users/by-external/1").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
266
+ stub_get("#{host}/users/by-external/1").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
267
267
  end
268
268
 
269
269
  it "requests the correct resource" do
270
270
  subject.by_external_id(1)
271
- expect(a_get("http://localhost:3000/users/by-external/1")).to have_been_made
271
+ expect(a_get("#{host}/users/by-external/1")).to have_been_made
272
272
  end
273
273
 
274
274
  it "returns the requested user" do
@@ -279,13 +279,13 @@ describe DiscourseApi::API::Users do
279
279
 
280
280
  describe "#suspend" do
281
281
  before do
282
- url = "http://localhost:3000/admin/users/11/suspend"
282
+ url = "#{host}/admin/users/11/suspend"
283
283
  stub_put(url).to_return(body: '', status: 200)
284
284
  end
285
285
 
286
286
  it "makes the correct put request" do
287
287
  result = subject.suspend(11, '2030-01-01', "no reason")
288
- url = "http://localhost:3000/admin/users/11/suspend"
288
+ url = "#{host}/admin/users/11/suspend"
289
289
  expect(a_put(url)).to have_been_made
290
290
  expect(result.status).to eq(200)
291
291
  end
@@ -293,13 +293,13 @@ describe DiscourseApi::API::Users do
293
293
 
294
294
  describe "#unsuspend" do
295
295
  before do
296
- url = "http://localhost:3000/admin/users/11/unsuspend"
296
+ url = "#{host}/admin/users/11/unsuspend"
297
297
  stub_put(url).to_return(body: '', status: 200)
298
298
  end
299
299
 
300
300
  it "makes the correct put request" do
301
301
  result = subject.unsuspend(11)
302
- url = "http://localhost:3000/admin/users/11/unsuspend"
302
+ url = "#{host}/admin/users/11/unsuspend"
303
303
  expect(a_put(url)).to have_been_made
304
304
  expect(result.status).to eq(200)
305
305
  end
@@ -307,13 +307,13 @@ describe DiscourseApi::API::Users do
307
307
 
308
308
  describe "#delete_user" do
309
309
  before do
310
- url = "http://localhost:3000/admin/users/11.json?delete_posts=true"
310
+ url = "#{host}/admin/users/11.json?delete_posts=true"
311
311
  stub_delete(url).to_return(body: '{"deleted": true}', status: 200)
312
312
  end
313
313
 
314
314
  it "makes the correct delete request" do
315
315
  result = subject.delete_user(11, true)
316
- url = "http://localhost:3000/admin/users/11.json?delete_posts=true"
316
+ url = "#{host}/admin/users/11.json?delete_posts=true"
317
317
  expect(a_delete(url)).to have_been_made
318
318
  expect(result.body).to eq('{"deleted": true}')
319
319
  expect(result.status).to eq(200)
@@ -321,7 +321,7 @@ describe DiscourseApi::API::Users do
321
321
  end
322
322
 
323
323
  describe "#check_username" do
324
- let(:url) { "http://localhost:3000/users/check_username.json?username=sparrow" }
324
+ let(:url) { "#{host}/users/check_username.json?username=sparrow" }
325
325
  let(:body) { '{"available":false,"suggestion":"sparrow1"}' }
326
326
 
327
327
  before do
@@ -339,7 +339,7 @@ describe DiscourseApi::API::Users do
339
339
  end
340
340
 
341
341
  context "when non-URI characters are used" do
342
- let(:url) { "http://localhost:3000/users/check_username.json?username=1_%5B4%5D%21+%40the%24%23%3F" }
342
+ let(:url) { "#{host}/users/check_username.json?username=1_%5B4%5D%21+%40the%24%23%3F" }
343
343
  let(:body) { '{"errors":["must only include numbers, letters, dashes, and underscores"]}' }
344
344
 
345
345
  it "escapes them" do
@@ -356,12 +356,12 @@ describe DiscourseApi::API::Users do
356
356
 
357
357
  describe "#deactivate" do
358
358
  before do
359
- stub_put("http://localhost:3000/admin/users/15/deactivate").to_return(body: nil)
359
+ stub_put("#{host}/admin/users/15/deactivate").to_return(body: nil)
360
360
  end
361
361
 
362
362
  it "makes the put request" do
363
363
  subject.deactivate(15)
364
- expect(a_put("http://localhost:3000/admin/users/15/deactivate")).to have_been_made
364
+ expect(a_put("#{host}/admin/users/15/deactivate")).to have_been_made
365
365
  end
366
366
 
367
367
  it "returns success" do