Skip to content

Commit 745fb58

Browse files
authored
DEV: Fix ruby warnings and other issues (#242)
1 parent c6bd7aa commit 745fb58

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Pass params to get notifications API
1818

1919
### Deprecated
20-
- `invite_user_to_topic` has been deprecated, use `invite_user` instead.
20+
- `invite_user_to_topic` has been deprecated, use `invite_to_topic` instead.
2121
- `create_private_message` has been deprecated, use `create_pm` instead.
2222

2323
## [0.46.0] - 2021-04-12

examples/invite_users.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
client.resend_invite("namee@example.com")
1919

2020
# invite to a topic
21-
client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
21+
client.invite_to_topic(1, email: "foo@bar.com")
2222

2323
# if the user is an admin you may invite to a group as well
24-
client.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)
24+
client.invite_to_topic(1, email: "foo@bar.com", group_ids: "1,2,3")
2525

2626
# retrieve invite
2727
puts client.retrieve_invite(email: "foo@bar.com")

lib/discourse_api/api/dashboard.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def get_dashboard_stats_totals
1414
topics = global_reports[3]
1515
posts = global_reports[4]
1616

17-
totals = {
17+
{
1818
'users' => users['total'],
1919
'topics' => topics['total'],
20-
'posts' => posts['total']
20+
'posts' => posts['total'],
2121
}
2222
end
2323
end

lib/discourse_api/api/site_settings.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module DiscourseApi
33
module API
44
module SiteSettings
55
def site_setting_update(args = {})
6-
params = API.params(args)
7-
.required(:name, :value).to_h
6+
params = API.params(args).required(:name, :value).to_h
87
new_site_setting = { params[:name] => params[:value] }
9-
response = put("/admin/site_settings/#{params[:name]}", new_site_setting)
8+
9+
put("/admin/site_settings/#{params[:name]}", new_site_setting)
1010
end
1111
end
1212
end

lib/discourse_api/single_sign_on.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class SingleSignOn
1515
#NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
1616

1717
attr_accessor(*ACCESSORS)
18-
attr_accessor :custom_fields
19-
attr_writer :sso_secret, :sso_url
18+
attr_writer :custom_fields, :sso_secret, :sso_url
2019

2120
def self.sso_secret
2221
raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
@@ -27,7 +26,6 @@ def self.sso_url
2726
end
2827

2928
def self.parse_hash(payload)
30-
payload
3129
sso = new
3230

3331
sso.sso_secret = payload.delete(:sso_secret)
@@ -43,8 +41,10 @@ def self.parse_hash(payload)
4341
val = Array(val) if ARRAYS.include?(k) && !val.nil?
4442
sso.send("#{k}=", val)
4543
end
44+
4645
# Set custom_fields
4746
sso.custom_fields = payload[:custom_fields]
47+
4848
# Add custom_fields (old format)
4949
payload.each do |k, v|
5050
if field = k[/^custom\.(.+)$/, 1]
@@ -127,7 +127,7 @@ def unsigned_payload
127127

128128
ACCESSORS.each do |k|
129129
next if (val = send k) == nil
130-
payload[k] = val
130+
payload[k] = val
131131
end
132132

133133
if @custom_fields

spec/discourse_api/api/topics_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@
1515
end
1616
end
1717

18-
describe "#invite_user_to_topic" do
18+
describe "#invite_to_topic" do
1919
before do
2020
stub_post("#{host}/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
2121
end
2222

2323
it "requests the correct resource" do
24-
subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
25-
expect(a_post("#{host}/t/12/invite")).to have_been_made
26-
end
27-
28-
it "requests the correct resource with new method 'invite_to_topic'" do
2924
subject.invite_to_topic(12, email: "fake_user@example.com")
3025
expect(a_post("#{host}/t/12/invite")).to have_been_made
3126
end
3227

3328
it "returns success" do
34-
response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
29+
response = subject.invite_to_topic(12, email: "fake_user@example.com")
3530
expect(response).to be_a Hash
3631
expect(response['success']).to be_truthy
3732
end

0 commit comments

Comments
 (0)