Skip to content

Commit 3472c48

Browse files
committed
Do not require channel.
1 parent cf9dea4 commit 3472c48

File tree

5 files changed

+248
-15
lines changed

5 files changed

+248
-15
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 4 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:42:00 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.
@@ -100,7 +100,7 @@ RSpec/ContextMethod:
100100
RSpec/ContextWording:
101101
Enabled: false
102102

103-
# Offense count: 67
103+
# Offense count: 69
104104
# Configuration parameters: CountAsOne.
105105
RSpec/ExampleLength:
106106
Max: 18

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: 19 additions & 8 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

3538
it 'requires only one of :channel or :channels' do
3639
expect do
37-
client.files_upload_v2(filename: 'test.txt', content: 'Test File Contents', channels: 'C08AZ76CA4V',
38-
channel_id: 'C08AZ76CA4V')
40+
client.files_upload_v2(
41+
filename: 'test.txt',
42+
content: 'Test File Contents',
43+
channels: 'C08AZ76CA4V',
44+
channel_id: 'C08AZ76CA4V'
45+
)
3946
end.to raise_error ArgumentError, 'Only one of :channel, :channels, or :channel_id is required'
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)