Skip to content

Commit 98e515a

Browse files
committed
Do not require channel.
1 parent cf9dea4 commit 98e515a

File tree

5 files changed

+263
-23
lines changed

5 files changed

+263
-23
lines changed

.rubocop_todo.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-02-08 15:30:56 UTC using RuboCop version 1.26.1.
3+
# on 2025-02-08 15:48:35 UTC using RuboCop version 1.26.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -47,7 +47,7 @@ Lint/RedundantCopDisableDirective:
4747
# Offense count: 13
4848
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
4949
Metrics/AbcSize:
50-
Max: 62
50+
Max: 61
5151

5252
# Offense count: 6
5353
# Configuration parameters: IgnoredMethods.
@@ -57,7 +57,7 @@ Metrics/CyclomaticComplexity:
5757
# Offense count: 15
5858
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
5959
Metrics/MethodLength:
60-
Max: 39
60+
Max: 37
6161

6262
# Offense count: 1
6363
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
@@ -69,6 +69,12 @@ Metrics/ParameterLists:
6969
Metrics/PerceivedComplexity:
7070
Max: 12
7171

72+
# Offense count: 1
73+
# Configuration parameters: MinSize.
74+
Performance/CollectionLiteralInLoop:
75+
Exclude:
76+
- 'spec/slack/web/api/endpoints/custom_specs/files_spec.rb'
77+
7278
# Offense count: 1
7379
# This cop supports safe auto-correction (--auto-correct).
7480
Performance/MapCompact:
@@ -100,7 +106,7 @@ RSpec/ContextMethod:
100106
RSpec/ContextWording:
101107
Enabled: false
102108

103-
# Offense count: 67
109+
# Offense count: 69
104110
# Configuration parameters: CountAsOne.
105111
RSpec/ExampleLength:
106112
Max: 18
@@ -136,11 +142,6 @@ RSpec/NamedSubject:
136142
RSpec/NestedGroups:
137143
Max: 6
138144

139-
# Offense count: 2
140-
RSpec/RepeatedExample:
141-
Exclude:
142-
- 'spec/slack/web/api/endpoints/custom_specs/files_spec.rb'
143-
144145
# Offense count: 5
145146
RSpec/StubbedMock:
146147
Exclude:
@@ -199,6 +200,12 @@ Style/GlobalStdStream:
199200
- 'spec/integration/integration_spec.rb'
200201
- 'spec/slack/web/client_spec.rb'
201202

203+
# Offense count: 1
204+
# This cop supports unsafe auto-correction (--auto-correct-all).
205+
Style/MapToHash:
206+
Exclude:
207+
- 'spec/slack/web/api/endpoints/custom_specs/files_spec.rb'
208+
202209
# Offense count: 1
203210
Style/MultilineBlockChain:
204211
Exclude:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ This library provides a helper method `files_upload_v2` that wraps the three sep
178178
```ruby
179179
client.files_upload_v2(
180180
# required options
181-
channels: ['C000000', 'C000001'], # channel IDs, one is required (:channel_id, :channel, or :channels are all supported)
182181
filename: 'results.pdf', # this is used for the file title, unless a :title option is provided
183182
contents: File.read('/users/me/results.pdf'), # the string contents of the file
184183

185184
# optional options
185+
channels: ['C000000', 'C000001'], # channel IDs to share the file in (:channel_id, :channel, or :channels are all supported)
186186
initial_comment: 'Sharing the Q1 results :tada:', # the message that is included with the file share thread
187187
snippet_type: 'text', # the type of snippet
188188
title: 'Q1 Results', # sets the title of the file, overriding the filename

lib/slack/web/api/helpers/files.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def files_upload_v2(params = {})
5353
complete_upload_request_params[:channel] = conversations_id(
5454
channel: params[:channel]
5555
)['channel']['id']
56-
else
57-
raise ArgumentError, 'At least one of :channel, :channels, or :channel_id is required'
5856
end
5957

6058
content = params[:content]

spec/fixtures/slack/web/files_upload_v2.yml

Lines changed: 224 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/slack/web/api/endpoints/custom_specs/files_spec.rb

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,34 @@
2626
end
2727
end
2828

29-
it 'requires at least one of :channel, :channels, or :channel_id' do
30-
expect do
31-
client.files_upload_v2(filename: 'test.txt', content: 'Test File Contents')
32-
end.to raise_error ArgumentError, 'At least one of :channel, :channels, or :channel_id is required'
29+
context 'without a channel', vcr: { cassette_name: 'web/files_upload_v2' } do
30+
it 'completes the upload' do
31+
expect(client.files_upload_v2(
32+
filename: 'test.txt',
33+
content: 'Test File Contents'
34+
).files.size).to eq 1
35+
end
3336
end
3437

35-
it 'requires only one of :channel or :channels' do
36-
expect do
37-
client.files_upload_v2(filename: 'test.txt', content: 'Test File Contents', channels: 'C08AZ76CA4V',
38-
channel_id: 'C08AZ76CA4V')
39-
end.to raise_error ArgumentError, 'Only one of :channel, :channels, or :channel_id is required'
38+
%i[channel channels channel_id].permutation(2).map(&:sort).uniq.each do |permutation|
39+
it "requires only one of #{permutation.join(' or ')}" do
40+
expect do
41+
client.files_upload_v2({
42+
filename: 'test.txt',
43+
content: 'Test File Contents'
44+
}.merge(permutation.map { |arg| [arg, 'C08AZ76CA4V'] }.to_h))
45+
end.to raise_error ArgumentError, 'Only one of :channel, :channels, or :channel_id is required'
46+
end
4047
end
4148

4249
it 'requires only one of :channels, or :channel_id' do
4350
expect do
44-
client.files_upload_v2(filename: 'test.txt', content: 'Test File Contents', channels: 'C08AZ76CA4V',
45-
channel_id: 'C08AZ76CA4V')
51+
client.files_upload_v2(
52+
filename: 'test.txt',
53+
content: 'Test File Contents',
54+
channels: 'C08AZ76CA4V',
55+
channel_id: 'C08AZ76CA4V'
56+
)
4657
end.to raise_error ArgumentError, 'Only one of :channel, :channels, or :channel_id is required'
4758
end
4859

0 commit comments

Comments
 (0)