discourse_api 0.10.1 → 0.11.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/.gitignore +21 -21
- data/.travis.yml +5 -7
- data/CHANGELOG.md +99 -85
- 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 -33
- data/examples/backups.rb +18 -18
- data/examples/category.rb +21 -21
- data/examples/change_topic_status.rb +33 -0
- 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 -42
- 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 -65
- data/lib/discourse_api/api/users.rb +85 -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 -29
- 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 +227 -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 -0
- 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 +31 -28
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe DiscourseApi::API::Email do
|
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
|
5
|
-
|
|
6
|
-
describe "#email_settings" do
|
|
7
|
-
before do
|
|
8
|
-
stub_get("http://localhost:3000/admin/email.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "requests the correct resource" do
|
|
12
|
-
subject.email_settings
|
|
13
|
-
expect(a_get("http://localhost:3000/admin/email.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns the requested settings" do
|
|
17
|
-
settings = subject.email_settings
|
|
18
|
-
expect(settings).to be_a Hash
|
|
19
|
-
expect(settings).to have_key('delivery_method')
|
|
20
|
-
expect(settings).to have_key('settings')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "#list_email_all" do
|
|
25
|
-
before do
|
|
26
|
-
stub_get("http://localhost:3000/admin/email/all.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "requests the correct resource" do
|
|
30
|
-
subject.list_email('all')
|
|
31
|
-
expect(a_get("http://localhost:3000/admin/email/all.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "returns all email" do
|
|
35
|
-
all_email = subject.list_email('all')
|
|
36
|
-
expect(all_email).to be_an Array
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DiscourseApi::API::Email do
|
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
|
5
|
+
|
|
6
|
+
describe "#email_settings" do
|
|
7
|
+
before do
|
|
8
|
+
stub_get("http://localhost:3000/admin/email.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "requests the correct resource" do
|
|
12
|
+
subject.email_settings
|
|
13
|
+
expect(a_get("http://localhost:3000/admin/email.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns the requested settings" do
|
|
17
|
+
settings = subject.email_settings
|
|
18
|
+
expect(settings).to be_a Hash
|
|
19
|
+
expect(settings).to have_key('delivery_method')
|
|
20
|
+
expect(settings).to have_key('settings')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#list_email_all" do
|
|
25
|
+
before do
|
|
26
|
+
stub_get("http://localhost:3000/admin/email/all.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "requests the correct resource" do
|
|
30
|
+
subject.list_email('all')
|
|
31
|
+
expect(a_get("http://localhost:3000/admin/email/all.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "returns all email" do
|
|
35
|
+
all_email = subject.list_email('all')
|
|
36
|
+
expect(all_email).to be_an Array
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe DiscourseApi::API::Groups do
|
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
|
5
|
-
|
|
6
|
-
describe "#groups" do
|
|
7
|
-
before do
|
|
8
|
-
stub_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "requests the correct resource" do
|
|
12
|
-
subject.groups
|
|
13
|
-
expect(a_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns the requested groups" do
|
|
17
|
-
groups = subject.groups
|
|
18
|
-
expect(groups).to be_an Array
|
|
19
|
-
groups.each { |g| expect(g).to be_a Hash }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "create new groups" do
|
|
23
|
-
stub_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user")
|
|
24
|
-
subject.create_group(name: "test_group")
|
|
25
|
-
expect(a_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user").
|
|
26
|
-
with(body: {name: "test_group", visible: "true"})
|
|
27
|
-
).to have_been_made
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "add members" do
|
|
31
|
-
before do
|
|
32
|
-
stub_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "adds a single member by username" do
|
|
36
|
-
subject.group_add(123, username: "sam")
|
|
37
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
38
|
-
with(body: {usernames: "sam"})
|
|
39
|
-
).to have_been_made
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "adds an array of members by username" do
|
|
43
|
-
subject.group_add(123, usernames: ["sam", "jeff"])
|
|
44
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
45
|
-
with(body: {usernames: "sam,jeff"})
|
|
46
|
-
).to have_been_made
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "adds a single member by user_id" do
|
|
50
|
-
subject.group_add(123, user_id: 456)
|
|
51
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
52
|
-
with(body: {user_ids: "456"})
|
|
53
|
-
).to have_been_made
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "adds an array of members by user_id" do
|
|
57
|
-
subject.group_add(123, user_id: [123, 456])
|
|
58
|
-
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
59
|
-
with(body: {user_ids: "123,456"})
|
|
60
|
-
).to have_been_made
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "remove members" do
|
|
65
|
-
before do
|
|
66
|
-
url = "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user&username=sam"
|
|
67
|
-
stub_delete(url)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "removes member" do
|
|
71
|
-
subject.group_remove(123, username: "sam")
|
|
72
|
-
expect(a_delete("http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user&username=sam")).to have_been_made
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "group members" do
|
|
77
|
-
before do
|
|
78
|
-
stub_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
|
|
79
|
-
stub_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "list members" do
|
|
83
|
-
members = subject.group_members('mygroup')
|
|
84
|
-
expect(a_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=0")).to have_been_made
|
|
85
|
-
expect(members.length).to eq(100)
|
|
86
|
-
members = subject.group_members('mygroup', offset: 100)
|
|
87
|
-
expect(a_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=100")).to have_been_made
|
|
88
|
-
expect(members.length).to eq(90)
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DiscourseApi::API::Groups do
|
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
|
5
|
+
|
|
6
|
+
describe "#groups" do
|
|
7
|
+
before do
|
|
8
|
+
stub_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "requests the correct resource" do
|
|
12
|
+
subject.groups
|
|
13
|
+
expect(a_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns the requested groups" do
|
|
17
|
+
groups = subject.groups
|
|
18
|
+
expect(groups).to be_an Array
|
|
19
|
+
groups.each { |g| expect(g).to be_a Hash }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "create new groups" do
|
|
23
|
+
stub_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user")
|
|
24
|
+
subject.create_group(name: "test_group")
|
|
25
|
+
expect(a_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user").
|
|
26
|
+
with(body: {name: "test_group", visible: "true"})
|
|
27
|
+
).to have_been_made
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "add members" do
|
|
31
|
+
before do
|
|
32
|
+
stub_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "adds a single member by username" do
|
|
36
|
+
subject.group_add(123, username: "sam")
|
|
37
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
38
|
+
with(body: {usernames: "sam"})
|
|
39
|
+
).to have_been_made
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "adds an array of members by username" do
|
|
43
|
+
subject.group_add(123, usernames: ["sam", "jeff"])
|
|
44
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
45
|
+
with(body: {usernames: "sam,jeff"})
|
|
46
|
+
).to have_been_made
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "adds a single member by user_id" do
|
|
50
|
+
subject.group_add(123, user_id: 456)
|
|
51
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
52
|
+
with(body: {user_ids: "456"})
|
|
53
|
+
).to have_been_made
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "adds an array of members by user_id" do
|
|
57
|
+
subject.group_add(123, user_id: [123, 456])
|
|
58
|
+
expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user").
|
|
59
|
+
with(body: {user_ids: "123,456"})
|
|
60
|
+
).to have_been_made
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "remove members" do
|
|
65
|
+
before do
|
|
66
|
+
url = "http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user&username=sam"
|
|
67
|
+
stub_delete(url)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "removes member" do
|
|
71
|
+
subject.group_remove(123, username: "sam")
|
|
72
|
+
expect(a_delete("http://localhost:3000/admin/groups/123/members.json?api_key=test_d7fd0429940&api_username=test_user&username=sam")).to have_been_made
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "group members" do
|
|
77
|
+
before do
|
|
78
|
+
stub_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
|
|
79
|
+
stub_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "list members" do
|
|
83
|
+
members = subject.group_members('mygroup')
|
|
84
|
+
expect(a_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=0")).to have_been_made
|
|
85
|
+
expect(members.length).to eq(100)
|
|
86
|
+
members = subject.group_members('mygroup', offset: 100)
|
|
87
|
+
expect(a_get("http://localhost:3000/groups/mygroup/members.json?api_key=test_d7fd0429940&api_username=test_user&limit=100&offset=100")).to have_been_made
|
|
88
|
+
expect(members.length).to eq(90)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe DiscourseApi::API::Notifications do
|
|
4
|
-
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
|
5
|
-
|
|
6
|
-
describe "#notifications" do
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
stub_get("http://localhost:3000/notifications.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("notifications.json"), headers: { content_type: "application/json" })
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "requests the correct resource" do
|
|
13
|
-
subject.notifications
|
|
14
|
-
expect(a_get("http://localhost:3000/notifications.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "returns the requested notifications" do
|
|
18
|
-
notifications = subject.notifications
|
|
19
|
-
expect(notifications).to be_an Array
|
|
20
|
-
expect(notifications.first).to be_an Hash
|
|
21
|
-
expect(notifications[0]['notification_type']).to eq(9)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DiscourseApi::API::Notifications do
|
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
|
5
|
+
|
|
6
|
+
describe "#notifications" do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
stub_get("http://localhost:3000/notifications.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("notifications.json"), headers: { content_type: "application/json" })
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "requests the correct resource" do
|
|
13
|
+
subject.notifications
|
|
14
|
+
expect(a_get("http://localhost:3000/notifications.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns the requested notifications" do
|
|
18
|
+
notifications = subject.notifications
|
|
19
|
+
expect(notifications).to be_an Array
|
|
20
|
+
expect(notifications.first).to be_an Hash
|
|
21
|
+
expect(notifications[0]['notification_type']).to eq(9)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe DiscourseApi::API::Params do
|
|
4
|
-
def params_for(h)
|
|
5
|
-
DiscourseApi::API::Params.new(h).required(:r1).optional(:o1, :o2).default(d1: "default")
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should raise on missing required params" do
|
|
9
|
-
expect { params_for({o1: "test"}).to_h }.to raise_error(ArgumentError)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should not include optional params when not provided" do
|
|
13
|
-
expect(params_for({r1: "test"}).to_h).not_to include(:o1)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should include optional params if provided but blank" do
|
|
17
|
-
expect(params_for({r1: "test", o2: nil}).to_h).to include(:o2)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should include default params when defined but not provided" do
|
|
21
|
-
expect(params_for({r1: "test"}).to_h).to include(d1: "default")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should include default params when defined and provided" do
|
|
25
|
-
expect(params_for({r1: "test", d1: "override"}).to_h).to include(d1: "override")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should include optional and default params when defined and provided" do
|
|
29
|
-
expect(params_for({r1: "test", o1: "optional", d1: "override"}).to_h).to include(o1: "optional", d1: "override")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DiscourseApi::API::Params do
|
|
4
|
+
def params_for(h)
|
|
5
|
+
DiscourseApi::API::Params.new(h).required(:r1).optional(:o1, :o2).default(d1: "default")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should raise on missing required params" do
|
|
9
|
+
expect { params_for({o1: "test"}).to_h }.to raise_error(ArgumentError)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should not include optional params when not provided" do
|
|
13
|
+
expect(params_for({r1: "test"}).to_h).not_to include(:o1)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should include optional params if provided but blank" do
|
|
17
|
+
expect(params_for({r1: "test", o2: nil}).to_h).to include(:o2)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should include default params when defined but not provided" do
|
|
21
|
+
expect(params_for({r1: "test"}).to_h).to include(d1: "default")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should include default params when defined and provided" do
|
|
25
|
+
expect(params_for({r1: "test", d1: "override"}).to_h).to include(d1: "override")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should include optional and default params when defined and provided" do
|
|
29
|
+
expect(params_for({r1: "test", o1: "optional", d1: "override"}).to_h).to include(o1: "optional", d1: "override")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe DiscourseApi::API::Posts do
|
|
4
|
-
let (:client) { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
|
5
|
-
|
|
6
|
-
describe "#get_post" do
|
|
7
|
-
before do
|
|
8
|
-
stub_get("http://localhost:3000/posts/11.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("post.json"), headers: { content_type: "application/json" })
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "fetches a post" do
|
|
12
|
-
the_post = client.get_post(11)
|
|
13
|
-
expect(the_post).to be_a Hash
|
|
14
|
-
expect(the_post['id']).to eq(11)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "#wikify_post" do
|
|
19
|
-
before do
|
|
20
|
-
stub_put("http://localhost:3000/posts/9999/wiki?api_key=test_d7fd0429940&api_username=test_user")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "fails on unknown post" do
|
|
24
|
-
client.wikify_post(9999)
|
|
25
|
-
expect(a_put("http://localhost:3000/posts/9999/wiki?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DiscourseApi::API::Posts do
|
|
4
|
+
let (:client) { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
|
5
|
+
|
|
6
|
+
describe "#get_post" do
|
|
7
|
+
before do
|
|
8
|
+
stub_get("http://localhost:3000/posts/11.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("post.json"), headers: { content_type: "application/json" })
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "fetches a post" do
|
|
12
|
+
the_post = client.get_post(11)
|
|
13
|
+
expect(the_post).to be_a Hash
|
|
14
|
+
expect(the_post['id']).to eq(11)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#wikify_post" do
|
|
19
|
+
before do
|
|
20
|
+
stub_put("http://localhost:3000/posts/9999/wiki?api_key=test_d7fd0429940&api_username=test_user")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "fails on unknown post" do
|
|
24
|
+
client.wikify_post(9999)
|
|
25
|
+
expect(a_put("http://localhost:3000/posts/9999/wiki?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#post_action_users" do
|
|
30
|
+
before do
|
|
31
|
+
stub_get("http://localhost:3000/post_action_users.json?api_key=test_d7fd0429940&api_username=test_user&id=11&post_action_type_id=2").to_return(body: fixture("post_action_users.json"), headers: { content_type: "application/json" })
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "fetches post_action_users" do
|
|
35
|
+
post_action_users = client.post_action_users(11, 2)
|
|
36
|
+
expect(post_action_users).to be_a Hash
|
|
37
|
+
expect(post_action_users["post_action_users"][0]["id"]).to eq(1286)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|