discourse_api 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +23 -10
  3. data/.rubocop.yml +1 -1
  4. data/.streerc +2 -0
  5. data/CHANGELOG.md +10 -0
  6. data/Gemfile +1 -1
  7. data/README.md +0 -4
  8. data/discourse_api.gemspec +7 -4
  9. data/examples/backups.rb +5 -5
  10. data/examples/badges.rb +5 -5
  11. data/examples/bookmark_topic.rb +5 -5
  12. data/examples/category.rb +10 -6
  13. data/examples/change_topic_status.rb +12 -11
  14. data/examples/create_private_message.rb +6 -6
  15. data/examples/create_topic.rb +9 -9
  16. data/examples/create_update_category.rb +13 -16
  17. data/examples/create_user.rb +12 -11
  18. data/examples/dashboard.rb +5 -5
  19. data/examples/disposable_invite_tokens.rb +9 -10
  20. data/examples/example.rb +5 -5
  21. data/examples/group_set_user_notification_level.rb +18 -19
  22. data/examples/groups.rb +7 -7
  23. data/examples/invite_users.rb +5 -5
  24. data/examples/manage_api_keys.rb +6 -11
  25. data/examples/notifications.rb +6 -6
  26. data/examples/polls.rb +12 -12
  27. data/examples/post_action.rb +5 -5
  28. data/examples/search.rb +5 -5
  29. data/examples/sent_private_messages.rb +6 -6
  30. data/examples/sso.rb +6 -6
  31. data/examples/topic_lists.rb +5 -5
  32. data/examples/update_user.rb +15 -7
  33. data/examples/upload_file.rb +7 -7
  34. data/lib/discourse_api/api/api_key.rb +1 -3
  35. data/lib/discourse_api/api/backups.rb +1 -1
  36. data/lib/discourse_api/api/badges.rb +21 -6
  37. data/lib/discourse_api/api/categories.rb +69 -37
  38. data/lib/discourse_api/api/dashboard.rb +2 -6
  39. data/lib/discourse_api/api/groups.rb +68 -73
  40. data/lib/discourse_api/api/invite.rb +30 -30
  41. data/lib/discourse_api/api/notifications.rb +2 -3
  42. data/lib/discourse_api/api/params.rb +4 -14
  43. data/lib/discourse_api/api/polls.rb +9 -12
  44. data/lib/discourse_api/api/posts.rb +5 -8
  45. data/lib/discourse_api/api/private_messages.rb +9 -8
  46. data/lib/discourse_api/api/search.rb +2 -2
  47. data/lib/discourse_api/api/topics.rb +20 -22
  48. data/lib/discourse_api/api/uploads.rb +7 -5
  49. data/lib/discourse_api/api/user_actions.rb +2 -2
  50. data/lib/discourse_api/api/users.rb +31 -19
  51. data/lib/discourse_api/client.rb +58 -56
  52. data/lib/discourse_api/example_helper.rb +2 -4
  53. data/lib/discourse_api/single_sign_on.rb +56 -57
  54. data/lib/discourse_api/version.rb +1 -1
  55. data/spec/discourse_api/api/api_key_spec.rb +39 -25
  56. data/spec/discourse_api/api/backups_spec.rb +8 -3
  57. data/spec/discourse_api/api/badges_spec.rb +17 -7
  58. data/spec/discourse_api/api/categories_spec.rb +95 -53
  59. data/spec/discourse_api/api/email_spec.rb +17 -7
  60. data/spec/discourse_api/api/groups_spec.rb +71 -52
  61. data/spec/discourse_api/api/invite_spec.rb +41 -21
  62. data/spec/discourse_api/api/notifications_spec.rb +8 -4
  63. data/spec/discourse_api/api/params_spec.rb +5 -3
  64. data/spec/discourse_api/api/polls_spec.rb +53 -44
  65. data/spec/discourse_api/api/posts_spec.rb +33 -16
  66. data/spec/discourse_api/api/private_messages_spec.rb +25 -12
  67. data/spec/discourse_api/api/search_spec.rb +8 -3
  68. data/spec/discourse_api/api/site_settings_spec.rb +2 -3
  69. data/spec/discourse_api/api/sso_spec.rb +29 -25
  70. data/spec/discourse_api/api/topics_spec.rb +100 -31
  71. data/spec/discourse_api/api/uploads_spec.rb +16 -7
  72. data/spec/discourse_api/api/user_actions_spec.rb +13 -3
  73. data/spec/discourse_api/api/users_spec.rb +137 -55
  74. data/spec/discourse_api/client_spec.rb +32 -32
  75. data/spec/discourse_api/single_sign_on_spec.rb +43 -0
  76. data/spec/fixtures/categories.json +1 -1
  77. data/spec/spec_helper.rb +10 -15
  78. metadata +57 -12
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Badges do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#badges" do
8
8
  before do
9
- stub_get("#{host}/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/admin/badges.json").to_return(
10
+ body: fixture("badges.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "requests the correct resource" do
@@ -17,25 +22,30 @@ describe DiscourseApi::API::Badges do
17
22
  it "returns the requested badges" do
18
23
  badges = subject.badges
19
24
  expect(badges).to be_a Hash
20
- expect(badges['badges']).to be_an Array
25
+ expect(badges["badges"]).to be_an Array
21
26
  end
22
27
  end
23
28
 
24
29
  describe "#user-badges" do
25
30
  before do
26
- stub_get("#{host}/user-badges/test_user.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
31
+ stub_get("#{host}/user-badges/test_user.json").to_return(
32
+ body: fixture("user_badges.json"),
33
+ headers: {
34
+ content_type: "application/json",
35
+ },
36
+ )
27
37
  end
28
38
 
29
39
  it "requests the correct resource" do
30
- subject.user_badges('test_user')
40
+ subject.user_badges("test_user")
31
41
  expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
32
42
  end
33
43
 
34
44
  it "returns the requested user badges" do
35
- badges = subject.user_badges('test_user')
45
+ badges = subject.user_badges("test_user")
36
46
  expect(badges).to be_an Array
37
47
  expect(badges.first).to be_a Hash
38
- expect(badges.first).to have_key('badge_type_id')
48
+ expect(badges.first).to have_key("badge_type_id")
39
49
  end
40
50
  end
41
51
  end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Categories do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#categories" do
8
8
  before do
9
- stub_get("#{host}/categories.json")
10
- .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/categories.json").to_return(
10
+ body: fixture("categories.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
11
15
  end
12
16
 
13
17
  it "requests the correct resource" do
@@ -30,8 +34,12 @@ describe DiscourseApi::API::Categories do
30
34
 
31
35
  describe "#categories_full" do
32
36
  before do
33
- stub_get("#{host}/categories.json")
34
- .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
37
+ stub_get("#{host}/categories.json").to_return(
38
+ body: fixture("categories.json"),
39
+ headers: {
40
+ content_type: "application/json",
41
+ },
42
+ )
35
43
  end
36
44
 
37
45
  it "requests the correct resource" do
@@ -42,137 +50,171 @@ describe DiscourseApi::API::Categories do
42
50
  it "returns the entire categories response" do
43
51
  categories = subject.categories_full
44
52
  expect(categories).to be_a Hash
45
- expect(categories).to have_key 'category_list'
46
- expect(categories).to have_key 'featured_users'
53
+ expect(categories).to have_key "category_list"
54
+ expect(categories).to have_key "featured_users"
47
55
  end
48
56
  end
49
57
 
50
- describe '#category_latest_topics' do
58
+ describe "#category_latest_topics" do
51
59
  before do
52
- stub_get("#{host}/c/category-slug/l/latest.json")
53
- .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
60
+ stub_get("#{host}/c/category-slug/l/latest.json").to_return(
61
+ body: fixture("category_latest_topics.json"),
62
+ headers: {
63
+ content_type: "application/json",
64
+ },
65
+ )
54
66
  end
55
67
 
56
68
  it "returns the latest topics in a category" do
57
- latest_topics = subject.category_latest_topics(category_slug: 'category-slug')
69
+ latest_topics = subject.category_latest_topics(category_slug: "category-slug")
58
70
  expect(latest_topics).to be_an Array
59
71
  end
60
72
  end
61
73
 
62
- describe '#category_latest_topics_full' do
74
+ describe "#category_latest_topics_full" do
63
75
  before do
64
- stub_get("#{host}/c/category-slug/l/latest.json")
65
- .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
76
+ stub_get("#{host}/c/category-slug/l/latest.json").to_return(
77
+ body: fixture("category_latest_topics.json"),
78
+ headers: {
79
+ content_type: "application/json",
80
+ },
81
+ )
66
82
  end
67
83
 
68
84
  it "returns the entire latest topics in a category response" do
69
- latest_topics = subject.category_latest_topics_full(category_slug: 'category-slug')
85
+ latest_topics = subject.category_latest_topics_full(category_slug: "category-slug")
70
86
  expect(latest_topics).to be_a Hash
71
- expect(latest_topics).to have_key 'topic_list'
72
- expect(latest_topics).to have_key 'users'
87
+ expect(latest_topics).to have_key "topic_list"
88
+ expect(latest_topics).to have_key "users"
73
89
  end
74
90
  end
75
91
 
76
- describe '#category_top_topics' do
92
+ describe "#category_top_topics" do
77
93
  before do
78
- stub_get("#{host}/c/category-slug/l/top.json")
79
- .to_return(
94
+ stub_get("#{host}/c/category-slug/l/top.json").to_return(
80
95
  body: fixture("category_topics.json"),
81
- headers: { content_type: "application/json" }
96
+ headers: {
97
+ content_type: "application/json",
98
+ },
82
99
  )
83
100
  end
84
101
 
85
102
  it "returns the top topics in a category" do
86
- topics = subject.category_top_topics('category-slug')
103
+ topics = subject.category_top_topics("category-slug")
87
104
  expect(topics).to be_an Array
88
105
  end
89
106
  end
90
107
 
91
- describe '#category_top_topics_full' do
108
+ describe "#category_top_topics_full" do
92
109
  before do
93
- stub_get("#{host}/c/category-slug/l/top.json")
94
- .to_return(
110
+ stub_get("#{host}/c/category-slug/l/top.json").to_return(
95
111
  body: fixture("category_topics.json"),
96
- headers: { content_type: "application/json" }
112
+ headers: {
113
+ content_type: "application/json",
114
+ },
97
115
  )
98
116
  end
99
117
 
100
118
  it "returns the entire top topics in a category response" do
101
- topics = subject.category_top_topics_full('category-slug')
119
+ topics = subject.category_top_topics_full("category-slug")
102
120
  expect(topics).to be_a Hash
103
- expect(topics).to have_key 'topic_list'
104
- expect(topics).to have_key 'users'
121
+ expect(topics).to have_key "topic_list"
122
+ expect(topics).to have_key "users"
105
123
  end
106
124
  end
107
125
 
108
- describe '#category_new_topics' do
126
+ describe "#category_new_topics" do
109
127
  before do
110
- stub_get("#{host}/c/category-slug/l/new.json")
111
- .to_return(
128
+ stub_get("#{host}/c/category-slug/l/new.json").to_return(
112
129
  body: fixture("category_topics.json"),
113
- headers: { content_type: "application/json" }
130
+ headers: {
131
+ content_type: "application/json",
132
+ },
114
133
  )
115
134
  end
116
135
 
117
136
  it "returns the new topics in a category" do
118
- topics = subject.category_new_topics('category-slug')
137
+ topics = subject.category_new_topics("category-slug")
119
138
  expect(topics).to be_an Array
120
139
  end
121
140
  end
122
141
 
123
- describe '#category_new_topics_full' do
142
+ describe "#category_new_topics_full" do
124
143
  before do
125
- stub_get("#{host}/c/category-slug/l/new.json")
126
- .to_return(
144
+ stub_get("#{host}/c/category-slug/l/new.json").to_return(
127
145
  body: fixture("category_topics.json"),
128
- headers: { content_type: "application/json" }
146
+ headers: {
147
+ content_type: "application/json",
148
+ },
129
149
  )
130
150
  end
131
151
 
132
152
  it "returns the new topics in a category" do
133
- topics = subject.category_new_topics_full('category-slug')
153
+ topics = subject.category_new_topics_full("category-slug")
134
154
  expect(topics).to be_a Hash
135
- expect(topics).to have_key 'topic_list'
136
- expect(topics).to have_key 'users'
155
+ expect(topics).to have_key "topic_list"
156
+ expect(topics).to have_key "users"
137
157
  end
138
158
  end
139
159
 
140
- describe '#category_new_category' do
160
+ describe "#category_new_category" do
141
161
  before do
142
162
  stub_post("#{host}/categories")
143
- subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
144
- description: "This is a description",
145
- permissions: { "group_1" => 1, "admins" => 1 })
163
+ subject.create_category(
164
+ name: "test_category",
165
+ color: "283890",
166
+ text_color: "FFFFFF",
167
+ description: "This is a description",
168
+ permissions: {
169
+ "group_1" => 1,
170
+ "admins" => 1,
171
+ },
172
+ )
146
173
  end
147
174
 
148
175
  it "makes a create category request" do
149
- expect(a_post("#{host}/categories").with(body:
150
- "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")
151
- ).to have_been_made
176
+ expect(
177
+ a_post("#{host}/categories").with(
178
+ body:
179
+ "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",
180
+ ),
181
+ ).to have_been_made
152
182
  end
153
183
  end
154
184
 
155
185
  describe "#category_set_user_notification" do
156
186
  before do
157
- stub_post("#{host}/category/1/notifications").to_return(body: fixture("notification_success.json"), headers: { content_type: "application/json" })
187
+ stub_post("#{host}/category/1/notifications").to_return(
188
+ body: fixture("notification_success.json"),
189
+ headers: {
190
+ content_type: "application/json",
191
+ },
192
+ )
158
193
  end
159
194
 
160
195
  it "makes the post request" do
161
196
  response = subject.category_set_user_notification(id: 1, notification_level: 3)
162
197
  expect(a_post("#{host}/category/1/notifications")).to have_been_made
163
- expect(response['success']).to eq('OK')
198
+ expect(response["success"]).to eq("OK")
164
199
  end
165
200
  end
166
201
 
167
202
  describe "#category_set_user_notification_level" do
168
203
  before do
169
- stub_post("#{host}/category/1/notifications").to_return(body: fixture("notification_success.json"), headers: { content_type: "application/json" })
204
+ stub_post("#{host}/category/1/notifications").to_return(
205
+ body: fixture("notification_success.json"),
206
+ headers: {
207
+ content_type: "application/json",
208
+ },
209
+ )
170
210
  end
171
211
 
172
212
  it "makes the post request" do
173
213
  response = subject.category_set_user_notification_level(1, notification_level: 3)
174
- expect(a_post("#{host}/category/1/notifications").with(body: "notification_level=3")).to have_been_made
175
- expect(response['success']).to eq('OK')
214
+ expect(
215
+ a_post("#{host}/category/1/notifications").with(body: "notification_level=3"),
216
+ ).to have_been_made
217
+ expect(response["success"]).to eq("OK")
176
218
  end
177
219
  end
178
220
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Email do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#email_settings" do
8
8
  before do
9
- stub_get("#{host}/admin/email.json").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/admin/email.json").to_return(
10
+ body: fixture("email_settings.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "requests the correct resource" do
@@ -17,23 +22,28 @@ describe DiscourseApi::API::Email do
17
22
  it "returns the requested settings" do
18
23
  settings = subject.email_settings
19
24
  expect(settings).to be_a Hash
20
- expect(settings).to have_key('delivery_method')
21
- expect(settings).to have_key('settings')
25
+ expect(settings).to have_key("delivery_method")
26
+ expect(settings).to have_key("settings")
22
27
  end
23
28
  end
24
29
 
25
30
  describe "#list_email_all" do
26
31
  before do
27
- stub_get("#{host}/admin/email/all.json").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
32
+ stub_get("#{host}/admin/email/all.json").to_return(
33
+ body: fixture("email_list_all.json"),
34
+ headers: {
35
+ content_type: "application/json",
36
+ },
37
+ )
28
38
  end
29
39
 
30
40
  it "requests the correct resource" do
31
- subject.list_email('all')
41
+ subject.list_email("all")
32
42
  expect(a_get("#{host}/admin/email/all.json")).to have_been_made
33
43
  end
34
44
 
35
45
  it "returns all email" do
36
- all_email = subject.list_email('all')
46
+ all_email = subject.list_email("all")
37
47
  expect(all_email).to be_an Array
38
48
  end
39
49
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Groups do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#groups" do
8
8
  before do
9
- stub_get("#{host}/groups.json").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/groups.json").to_return(
10
+ body: fixture("groups.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "requests the correct resource" do
@@ -21,69 +26,74 @@ describe DiscourseApi::API::Groups do
21
26
  end
22
27
 
23
28
  it "returns a single group" do
24
- stub_get("#{host}/groups/some-group.json").to_return(body: fixture("group.json"), headers: { content_type: "application/json" })
25
- group = subject.group('some-group')
26
- expect(group['basic_group']).to be_a Hash
29
+ stub_get("#{host}/groups/some-group.json").to_return(
30
+ body: fixture("group.json"),
31
+ headers: {
32
+ content_type: "application/json",
33
+ },
34
+ )
35
+ group = subject.group("some-group")
36
+ expect(group["basic_group"]).to be_a Hash
27
37
  end
28
38
 
29
39
  it "create new groups" do
30
40
  stub_post("#{host}/admin/groups")
31
41
  subject.create_group(name: "test_group")
32
42
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
33
- expect(a_post("#{host}/admin/groups").
34
- with(body: params)
35
- ).to have_been_made
43
+ expect(a_post("#{host}/admin/groups").with(body: params)).to have_been_made
36
44
  end
37
45
 
38
46
  it "update an existing group" do
39
47
  stub_put("#{host}/groups/42")
40
48
  subject.update_group(42, name: "test_group")
41
49
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
42
- expect(a_put("#{host}/groups/42").
43
- with(body: params)
44
- ).to have_been_made
50
+ expect(a_put("#{host}/groups/42").with(body: params)).to have_been_made
45
51
  end
46
52
 
47
53
  describe "add members" do
48
- before do
49
- stub_request(:put, "#{host}/admin/groups/123/members.json")
50
- end
54
+ before { stub_request(:put, "#{host}/admin/groups/123/members.json") }
51
55
 
52
56
  it "adds a single member by username" do
53
57
  subject.group_add(123, username: "sam")
54
- expect(a_request(:put, "#{host}/admin/groups/123/members.json").
55
- with(body: { usernames: "sam" })
56
- ).to have_been_made
58
+ expect(
59
+ a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { usernames: "sam" }),
60
+ ).to have_been_made
57
61
  end
58
62
 
59
63
  it "adds an array of members by username" do
60
- subject.group_add(123, usernames: ["sam", "jeff"])
61
- expect(a_request(:put, "#{host}/admin/groups/123/members.json").
62
- with(body: { usernames: "sam,jeff" })
63
- ).to have_been_made
64
+ subject.group_add(123, usernames: %w[sam jeff])
65
+ expect(
66
+ a_request(:put, "#{host}/admin/groups/123/members.json").with(
67
+ body: {
68
+ usernames: "sam,jeff",
69
+ },
70
+ ),
71
+ ).to have_been_made
64
72
  end
65
73
 
66
74
  it "adds a single member by user_id" do
67
75
  subject.group_add(123, user_id: 456)
68
- expect(a_request(:put, "#{host}/admin/groups/123/members.json").
69
- with(body: { user_ids: "456" })
70
- ).to have_been_made
76
+ expect(
77
+ a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { user_ids: "456" }),
78
+ ).to have_been_made
71
79
  end
72
80
 
73
81
  it "adds an array of members by user_id" do
74
82
  subject.group_add(123, user_id: [123, 456])
75
- expect(a_request(:put, "#{host}/admin/groups/123/members.json").
76
- with(body: { user_ids: "123,456" })
77
- ).to have_been_made
83
+ expect(
84
+ a_request(:put, "#{host}/admin/groups/123/members.json").with(
85
+ body: {
86
+ user_ids: "123,456",
87
+ },
88
+ ),
89
+ ).to have_been_made
78
90
  end
79
91
  end
80
92
 
81
93
  describe "remove members" do
82
94
  let(:url) { "#{host}/admin/groups/123/members.json?usernames=sam" }
83
95
 
84
- before do
85
- stub_delete(url)
86
- end
96
+ before { stub_delete(url) }
87
97
 
88
98
  it "removes member" do
89
99
  subject.group_remove(123, username: "sam")
@@ -94,25 +104,21 @@ describe DiscourseApi::API::Groups do
94
104
  describe "add owners" do
95
105
  let(:url) { "#{host}/admin/groups/123/owners.json" }
96
106
 
97
- before do
98
- stub_put(url)
99
- end
107
+ before { stub_put(url) }
100
108
 
101
109
  it "makes the member an owner" do
102
110
  subject.group_add_owners(123, usernames: "sam")
103
111
  params = escape_params("group[usernames]" => "sam")
104
- expect(a_request(:put, "#{host}/admin/groups/123/owners.json").
105
- with(body: params)
106
- ).to have_been_made
112
+ expect(
113
+ a_request(:put, "#{host}/admin/groups/123/owners.json").with(body: params),
114
+ ).to have_been_made
107
115
  end
108
116
  end
109
117
 
110
118
  describe "remove owners" do
111
119
  let(:url) { "#{host}/admin/groups/123/owners.json?group%5Busernames%5D=sam" }
112
120
 
113
- before do
114
- stub_delete(url)
115
- end
121
+ before { stub_delete(url) }
116
122
 
117
123
  it "removes the owner role from the group member" do
118
124
  subject.group_remove_owners(123, usernames: "sam")
@@ -122,39 +128,52 @@ describe DiscourseApi::API::Groups do
122
128
 
123
129
  describe "group members" do
124
130
  it "list members" do
125
- stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
126
- stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
127
- members = subject.group_members('mygroup')
131
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
132
+ body: fixture("members_0.json"),
133
+ headers: {
134
+ content_type: "application/json",
135
+ },
136
+ )
137
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=100").to_return(
138
+ body: fixture("members_1.json"),
139
+ headers: {
140
+ content_type: "application/json",
141
+ },
142
+ )
143
+ members = subject.group_members("mygroup")
128
144
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
129
145
  expect(members.length).to eq(100)
130
- members = subject.group_members('mygroup', offset: 100)
146
+ members = subject.group_members("mygroup", offset: 100)
131
147
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
132
148
  expect(members.length).to eq(90)
133
149
  end
134
150
 
135
151
  context "with :all params" do
136
152
  it "lists members and owners" do
137
- stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_2.json"), headers: { content_type: "application/json" })
138
- member_data = subject.group_members('mygroup', all: true)
153
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
154
+ body: fixture("members_2.json"),
155
+ headers: {
156
+ content_type: "application/json",
157
+ },
158
+ )
159
+ member_data = subject.group_members("mygroup", all: true)
139
160
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
140
161
  expect(member_data["members"].length).to eq(100)
141
162
  expect(member_data["owners"].length).to eq(7)
142
- expect(member_data.keys.sort).to eq(["members", "meta", "owners"])
163
+ expect(member_data.keys.sort).to eq(%w[members meta owners])
143
164
  end
144
165
  end
145
166
  end
146
167
 
147
168
  describe "group user notification level" do
148
- before do
149
- stub_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3")
150
- end
169
+ before { stub_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3") }
151
170
 
152
171
  it "updates user's notification level for group" do
153
172
  subject.group_set_user_notification_level("mygroup", 77, 3)
154
- expect(a_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3"))
155
- .to have_been_made
173
+ expect(
174
+ a_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3"),
175
+ ).to have_been_made
156
176
  end
157
177
  end
158
-
159
178
  end
160
179
  end