discourse_api 0.39.3 → 0.40.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/.rubocop.yml +2 -6
- data/CHANGELOG.md +7 -0
- data/discourse_api.gemspec +2 -4
- data/lib/discourse_api/api/categories.rb +5 -0
- data/lib/discourse_api/api/sso.rb +3 -0
- data/lib/discourse_api/single_sign_on.rb +1 -1
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +3 -2
- data/spec/discourse_api/api/backups_spec.rb +2 -1
- data/spec/discourse_api/api/badges_spec.rb +2 -1
- data/spec/discourse_api/api/categories_spec.rb +9 -8
- data/spec/discourse_api/api/email_spec.rb +2 -1
- data/spec/discourse_api/api/groups_spec.rb +7 -6
- data/spec/discourse_api/api/notifications_spec.rb +1 -0
- data/spec/discourse_api/api/params_spec.rb +8 -7
- data/spec/discourse_api/api/polls_spec.rb +7 -6
- data/spec/discourse_api/api/posts_spec.rb +1 -0
- data/spec/discourse_api/api/private_messages_spec.rb +1 -0
- data/spec/discourse_api/api/search_spec.rb +4 -3
- data/spec/discourse_api/api/site_settings_spec.rb +2 -1
- data/spec/discourse_api/api/sso_spec.rb +3 -2
- data/spec/discourse_api/api/topics_spec.rb +1 -0
- data/spec/discourse_api/api/uploads_spec.rb +1 -0
- data/spec/discourse_api/api/user_actions_spec.rb +1 -0
- data/spec/discourse_api/api/users_spec.rb +4 -3
- data/spec/discourse_api/client_spec.rb +11 -10
- data/spec/spec_helper.rb +2 -1
- metadata +10 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12aa5327c6d59b3d258745ef391b3ce97da58367cd0056b7513735a6a530d42
|
4
|
+
data.tar.gz: f8b5f8eca097239993c8553bb0de9f3a1ec70348d511c16304e8586a0eda2e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f454b2b7b8ea518a03298fbcd179b5ecd7d4463a68ca574f081c7f6b261093bb2ffa10ea01ab752d281f33e2c028d56a639342e30481c9227dc7603467d840
|
7
|
+
data.tar.gz: 852e2a8aa5082f3850fbfd6e404d71a5d3a074c613305d0018c6d1b3c735182a45295043784954a8fd0a9d25caea585c87092971c9c5db730d6f60f67b3b67fc
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.40.0] - 2020-05-07
|
6
|
+
### Fixed
|
7
|
+
- Add missing attributes to `sync_sso`
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Add delete category method
|
11
|
+
|
5
12
|
## [0.39.3] - 2020-04-30
|
6
13
|
### Fixed
|
7
14
|
- Add `reviewable_by_group_name` to categories
|
data/discourse_api.gemspec
CHANGED
@@ -25,14 +25,12 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
26
|
spec.add_development_dependency 'guard', '~> 2.14'
|
27
27
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
28
|
-
spec.add_development_dependency 'rake', '
|
28
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
29
29
|
spec.add_development_dependency 'rb-inotify', '~> 0.9'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
|
-
spec.add_development_dependency 'rubocop', '~> 0.69'
|
32
31
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
33
32
|
spec.add_development_dependency 'webmock', '~> 2.0'
|
34
|
-
spec.add_development_dependency 'rubocop-discourse'
|
35
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.0'
|
33
|
+
spec.add_development_dependency 'rubocop-discourse'
|
36
34
|
|
37
35
|
spec.required_ruby_version = '>= 2.2.3'
|
38
36
|
end
|
@@ -28,6 +28,11 @@ module DiscourseApi
|
|
28
28
|
response['body']['category'] if response['body']
|
29
29
|
end
|
30
30
|
|
31
|
+
def delete_category(id)
|
32
|
+
response = delete("/categories/#{id}")
|
33
|
+
response[:body]['success']
|
34
|
+
end
|
35
|
+
|
31
36
|
def categories(params = {})
|
32
37
|
response = get('/categories.json', params)
|
33
38
|
response[:body]['category_list']['categories']
|
@@ -11,6 +11,9 @@ module DiscourseApi
|
|
11
11
|
sso.external_id = params[:external_id]
|
12
12
|
sso.suppress_welcome_message = params[:suppress_welcome_message] === true
|
13
13
|
sso.avatar_url = params[:avatar_url]
|
14
|
+
sso.profile_background_url = params[:profile_background_url]
|
15
|
+
sso.card_background_url = params[:card_background_url]
|
16
|
+
sso.bio = params[:bio]
|
14
17
|
sso.title = params[:title]
|
15
18
|
sso.avatar_force_update = params[:avatar_force_update] === true
|
16
19
|
sso.add_groups = params[:add_groups]
|
@@ -5,7 +5,7 @@ require 'openssl'
|
|
5
5
|
|
6
6
|
module DiscourseApi
|
7
7
|
class SingleSignOn
|
8
|
-
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
|
8
|
+
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :profile_background_url, :card_background_url, :avatar_force_update, :require_activation,
|
9
9
|
:bio, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title,
|
10
10
|
:add_groups, :remove_groups, :groups, :locale, :locale_force_update]
|
11
11
|
FIXNUMS = []
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::ApiKey do
|
@@ -48,7 +49,7 @@ describe DiscourseApi::API::ApiKey do
|
|
48
49
|
before do
|
49
50
|
url = "#{host}/admin/users/2/revoke_api_key.json"
|
50
51
|
stub_delete(url).to_return(body: "",
|
51
|
-
|
52
|
+
headers: { content_type: "application/json" })
|
52
53
|
end
|
53
54
|
|
54
55
|
it "returns 200" do
|
@@ -95,7 +96,7 @@ describe DiscourseApi::API::ApiKey do
|
|
95
96
|
before do
|
96
97
|
url = "#{host}/admin/api/key"
|
97
98
|
stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
|
98
|
-
|
99
|
+
headers: { content_type: "application/json" })
|
99
100
|
end
|
100
101
|
|
101
102
|
it "requests the correct resource" do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Backups do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#backups" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Badges do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#badges" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Categories do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#categories" do
|
7
8
|
before do
|
@@ -42,8 +43,8 @@ describe DiscourseApi::API::Categories do
|
|
42
43
|
describe '#category_top_topics' do
|
43
44
|
before do
|
44
45
|
stub_get("#{host}/c/category-slug/l/top.json")
|
45
|
-
|
46
|
-
body: fixture("category_topics.json"),
|
46
|
+
.to_return(
|
47
|
+
body: fixture("category_topics.json"),
|
47
48
|
headers: { content_type: "application/json" }
|
48
49
|
)
|
49
50
|
end
|
@@ -57,8 +58,8 @@ describe DiscourseApi::API::Categories do
|
|
57
58
|
describe '#category_new_topics' do
|
58
59
|
before do
|
59
60
|
stub_get("#{host}/c/category-slug/l/new.json")
|
60
|
-
|
61
|
-
body: fixture("category_topics.json"),
|
61
|
+
.to_return(
|
62
|
+
body: fixture("category_topics.json"),
|
62
63
|
headers: { content_type: "application/json" }
|
63
64
|
)
|
64
65
|
end
|
@@ -74,14 +75,14 @@ describe DiscourseApi::API::Categories do
|
|
74
75
|
stub_post("#{host}/categories")
|
75
76
|
subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
|
76
77
|
description: "This is a description",
|
77
|
-
permissions: {"group_1" => 1, "admins" => 1})
|
78
|
+
permissions: { "group_1" => 1, "admins" => 1 })
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
it "makes a create category request" do
|
81
82
|
expect(a_post("#{host}/categories").with(body:
|
82
83
|
"color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
|
83
84
|
).to have_been_made
|
84
85
|
end
|
85
|
-
end
|
86
|
+
end
|
86
87
|
|
87
88
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Email do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#email_settings" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Groups do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#groups" do
|
7
8
|
before do
|
@@ -51,28 +52,28 @@ describe DiscourseApi::API::Groups do
|
|
51
52
|
it "adds a single member by username" do
|
52
53
|
subject.group_add(123, username: "sam")
|
53
54
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
54
|
-
with(body: {usernames: "sam"})
|
55
|
+
with(body: { usernames: "sam" })
|
55
56
|
).to have_been_made
|
56
57
|
end
|
57
58
|
|
58
59
|
it "adds an array of members by username" do
|
59
60
|
subject.group_add(123, usernames: ["sam", "jeff"])
|
60
61
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
61
|
-
with(body: {usernames: "sam,jeff"})
|
62
|
+
with(body: { usernames: "sam,jeff" })
|
62
63
|
).to have_been_made
|
63
64
|
end
|
64
65
|
|
65
66
|
it "adds a single member by user_id" do
|
66
67
|
subject.group_add(123, user_id: 456)
|
67
68
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
68
|
-
with(body: {user_ids: "456"})
|
69
|
+
with(body: { user_ids: "456" })
|
69
70
|
).to have_been_made
|
70
71
|
end
|
71
72
|
|
72
73
|
it "adds an array of members by user_id" do
|
73
74
|
subject.group_add(123, user_id: [123, 456])
|
74
75
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
75
|
-
with(body: {user_ids: "123,456"})
|
76
|
+
with(body: { user_ids: "123,456" })
|
76
77
|
).to have_been_made
|
77
78
|
end
|
78
79
|
end
|
@@ -122,7 +123,7 @@ describe DiscourseApi::API::Groups do
|
|
122
123
|
it "updates user's notification level for group" do
|
123
124
|
subject.group_set_user_notification_level("mygroup", 77, 3)
|
124
125
|
expect(a_post("#{host}/groups/mygroup/notifications?user_id=77¬ification_level=3"))
|
125
|
-
|
126
|
+
.to have_been_made
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Params do
|
@@ -6,31 +7,31 @@ describe DiscourseApi::API::Params do
|
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should raise on missing required params" do
|
9
|
-
expect { params_for({o1: "test"}).to_h }.to raise_error(ArgumentError)
|
10
|
+
expect { params_for({ o1: "test" }).to_h }.to raise_error(ArgumentError)
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should not raise when a required param is false" do
|
13
|
-
expect { params_for({r1: false}).to_h }.not_to raise_error
|
14
|
+
expect { params_for({ r1: false }).to_h }.not_to raise_error
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should not include optional params when not provided" do
|
17
|
-
expect(params_for({r1: "test"}).to_h).not_to include(:o1)
|
18
|
+
expect(params_for({ r1: "test" }).to_h).not_to include(:o1)
|
18
19
|
end
|
19
20
|
|
20
21
|
it "should include optional params if provided but blank" do
|
21
|
-
expect(params_for({r1: "test", o2: nil}).to_h).to include(:o2)
|
22
|
+
expect(params_for({ r1: "test", o2: nil }).to_h).to include(:o2)
|
22
23
|
end
|
23
24
|
|
24
25
|
it "should include default params when defined but not provided" do
|
25
|
-
expect(params_for({r1: "test"}).to_h).to include(d1: "default")
|
26
|
+
expect(params_for({ r1: "test" }).to_h).to include(d1: "default")
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should include default params when defined and provided" do
|
29
|
-
expect(params_for({r1: "test", d1: "override"}).to_h).to include(d1: "override")
|
30
|
+
expect(params_for({ r1: "test", d1: "override" }).to_h).to include(d1: "override")
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should include optional and default params when defined and provided" do
|
33
|
-
expect(params_for({r1: "test", o1: "optional", d1: "override"}).to_h).to include(o1: "optional", d1: "override")
|
34
|
+
expect(params_for({ r1: "test", o1: "optional", d1: "override" }).to_h).to include(o1: "optional", d1: "override")
|
34
35
|
end
|
35
36
|
|
36
37
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Polls do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#poll vote" do
|
7
8
|
before do
|
8
9
|
path = "#{host}/polls/vote"
|
9
10
|
stub_put(path)
|
10
|
-
|
11
|
-
|
11
|
+
.to_return(body: fixture("polls_vote.json"), headers: { content_type: "application/json" })
|
12
|
+
|
12
13
|
end
|
13
14
|
|
14
15
|
it "requests the correct resource" do
|
@@ -29,7 +30,7 @@ describe DiscourseApi::API::Polls do
|
|
29
30
|
before do
|
30
31
|
path = "#{host}/polls/toggle_status"
|
31
32
|
stub_put(path)
|
32
|
-
|
33
|
+
.to_return(body: fixture("polls_toggle_status.json"), headers: { content_type: "application/json" })
|
33
34
|
|
34
35
|
end
|
35
36
|
|
@@ -49,7 +50,7 @@ describe DiscourseApi::API::Polls do
|
|
49
50
|
describe "#poll voters" do
|
50
51
|
before do
|
51
52
|
stub_get("#{host}/polls/voters.json?post_id=5&poll_name=poll")
|
52
|
-
|
53
|
+
.to_return(body: fixture("polls_voters.json"), headers: { content_type: "application/json" })
|
53
54
|
end
|
54
55
|
|
55
56
|
it "requests the correct resource" do
|
@@ -64,7 +65,7 @@ describe DiscourseApi::API::Polls do
|
|
64
65
|
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf']).to be_an Array
|
65
66
|
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf'][0]['id']).to eq(356)
|
66
67
|
end
|
67
|
-
|
68
|
+
end
|
68
69
|
|
69
70
|
end
|
70
71
|
end
|
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Search do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#search" do
|
7
8
|
before do
|
8
|
-
stub_get("#{host}/search/query").with(query: { term: "test"}
|
9
|
+
stub_get("#{host}/search/query").with(query: { term: "test" }).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
|
9
10
|
end
|
10
11
|
|
11
12
|
it "requests the correct resource" do
|
12
13
|
subject.search("test")
|
13
|
-
expect(a_get("#{host}/search/query").with(query: { term: "test"}
|
14
|
+
expect(a_get("#{host}/search/query").with(query: { term: "test" })).to have_been_made
|
14
15
|
end
|
15
16
|
|
16
17
|
it "returns the requested search" do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::SiteSettings do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#site_setting_update" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::SSO do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#sync_sso" do
|
7
8
|
before do
|
@@ -9,7 +10,7 @@ describe DiscourseApi::API::SSO do
|
|
9
10
|
end
|
10
11
|
|
11
12
|
it "requests the correct resource" do
|
12
|
-
subject.sync_sso({sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test"})
|
13
|
+
subject.sync_sso({ sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test" })
|
13
14
|
expect(a_post(/.*sync_sso.*/)).to have_been_made
|
14
15
|
end
|
15
16
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Users do
|
@@ -113,12 +114,12 @@ describe DiscourseApi::API::Users do
|
|
113
114
|
end
|
114
115
|
|
115
116
|
it "makes the post request" do
|
116
|
-
subject.create_user :
|
117
|
+
subject.create_user name: "Test User", email: "test2@example.com", password: "P@ssword", username: "test2"
|
117
118
|
expect(a_post("#{host}/users")).to have_been_made
|
118
119
|
end
|
119
120
|
|
120
121
|
it "returns success" do
|
121
|
-
response = subject.create_user :
|
122
|
+
response = subject.create_user name: "Test User", email: "test2@example.com", password: "P@ssword", username: "test2"
|
122
123
|
expect(response).to be_a Hash
|
123
124
|
expect(response['success']).to be_truthy
|
124
125
|
end
|
@@ -163,7 +164,7 @@ describe DiscourseApi::API::Users do
|
|
163
164
|
end
|
164
165
|
|
165
166
|
it "Raises API Error" do
|
166
|
-
expect{subject.log_out(90)}.to raise_error DiscourseApi::NotFoundError
|
167
|
+
expect { subject.log_out(90) }.to raise_error DiscourseApi::NotFoundError
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::Client do
|
@@ -90,26 +91,26 @@ describe DiscourseApi::Client do
|
|
90
91
|
|
91
92
|
describe "#post" do
|
92
93
|
before do
|
93
|
-
stub_post("#{host}/test/post").with(body: { created: "object"})
|
94
|
+
stub_post("#{host}/test/post").with(body: { created: "object" })
|
94
95
|
subject.api_key = 'test_d7fd0429940'
|
95
96
|
subject.api_username = 'test_user'
|
96
97
|
end
|
97
98
|
|
98
99
|
it "allows custom post requests" do
|
99
100
|
subject.post("/test/post", { created: "object" })
|
100
|
-
expect(a_post("#{host}/test/post").with(body: { created: "object"})).to have_been_made
|
101
|
+
expect(a_post("#{host}/test/post").with(body: { created: "object" })).to have_been_made
|
101
102
|
end
|
102
103
|
|
103
104
|
context 'when using a host with a subdirectory' do
|
104
105
|
subject { DiscourseApi::Client.new("#{host}/forum") }
|
105
106
|
|
106
107
|
before do
|
107
|
-
stub_post("#{host}/forum/test/post").with(body: { created: "object"})
|
108
|
+
stub_post("#{host}/forum/test/post").with(body: { created: "object" })
|
108
109
|
end
|
109
110
|
|
110
111
|
it "allows custom post requests" do
|
111
112
|
subject.post("/test/post", { created: "object" })
|
112
|
-
expect(a_post("#{host}/forum/test/post").with(body: { created: "object"})).to have_been_made
|
113
|
+
expect(a_post("#{host}/forum/test/post").with(body: { created: "object" })).to have_been_made
|
113
114
|
end
|
114
115
|
end
|
115
116
|
end
|
@@ -144,18 +145,18 @@ describe DiscourseApi::Client do
|
|
144
145
|
it "catches 500 errors" do
|
145
146
|
connection = instance_double(Faraday::Connection)
|
146
147
|
allow(connection).to receive(:get).and_return(OpenStruct.new(env: { body: 'error page html' }, status: 500))
|
147
|
-
allow(
|
148
|
-
expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
|
148
|
+
allow(Faraday).to receive(:new).and_return(connection)
|
149
|
+
expect { subject.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
149
150
|
end
|
150
151
|
|
151
152
|
it "catches Faraday errors" do
|
152
|
-
allow(
|
153
|
-
expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
|
153
|
+
allow(Faraday).to receive(:new).and_raise(Faraday::ClientError.new("BOOM!"))
|
154
|
+
expect { subject.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
154
155
|
end
|
155
156
|
|
156
157
|
it "catches JSON::ParserError errors" do
|
157
|
-
allow(
|
158
|
-
expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
|
158
|
+
allow(Faraday).to receive(:new).and_raise(JSON::ParserError.new("unexpected token"))
|
159
|
+
expect { subject.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
159
160
|
end
|
160
161
|
end
|
161
162
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'simplecov'
|
2
3
|
|
3
4
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
@@ -18,7 +19,7 @@ RSpec.configure do |config|
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
WebMock.disable_net_connect!(:
|
22
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
22
23
|
|
23
24
|
def host
|
24
25
|
'http://localhost:3000'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.40.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-
|
14
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -101,16 +101,16 @@ dependencies:
|
|
101
101
|
name: rake
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: 12.3.3
|
107
107
|
type: :development
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - "
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: 12.3.3
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rb-inotify
|
116
116
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,20 +139,6 @@ dependencies:
|
|
139
139
|
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '3.4'
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: rubocop
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
requirements:
|
146
|
-
- - "~>"
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
version: '0.69'
|
149
|
-
type: :development
|
150
|
-
prerelease: false
|
151
|
-
version_requirements: !ruby/object:Gem::Requirement
|
152
|
-
requirements:
|
153
|
-
- - "~>"
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
version: '0.69'
|
156
142
|
- !ruby/object:Gem::Dependency
|
157
143
|
name: simplecov
|
158
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,30 +171,16 @@ dependencies:
|
|
185
171
|
name: rubocop-discourse
|
186
172
|
requirement: !ruby/object:Gem::Requirement
|
187
173
|
requirements:
|
188
|
-
- - "
|
189
|
-
- !ruby/object:Gem::Version
|
190
|
-
version: '1.0'
|
191
|
-
type: :development
|
192
|
-
prerelease: false
|
193
|
-
version_requirements: !ruby/object:Gem::Requirement
|
194
|
-
requirements:
|
195
|
-
- - "~>"
|
196
|
-
- !ruby/object:Gem::Version
|
197
|
-
version: '1.0'
|
198
|
-
- !ruby/object:Gem::Dependency
|
199
|
-
name: rubocop-rspec
|
200
|
-
requirement: !ruby/object:Gem::Requirement
|
201
|
-
requirements:
|
202
|
-
- - "~>"
|
174
|
+
- - ">="
|
203
175
|
- !ruby/object:Gem::Version
|
204
|
-
version: '
|
176
|
+
version: '0'
|
205
177
|
type: :development
|
206
178
|
prerelease: false
|
207
179
|
version_requirements: !ruby/object:Gem::Requirement
|
208
180
|
requirements:
|
209
|
-
- - "
|
181
|
+
- - ">="
|
210
182
|
- !ruby/object:Gem::Version
|
211
|
-
version: '
|
183
|
+
version: '0'
|
212
184
|
description: Discourse API
|
213
185
|
email:
|
214
186
|
- sam.saffron@gmail.com
|