Skip to content

Commit 7b5652f

Browse files
committed
Translate #channel in file upload.
1 parent aa4d1e4 commit 7b5652f

File tree

5 files changed

+251
-4
lines changed

5 files changed

+251
-4
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 2 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-05 16:58:54 UTC using RuboCop version 1.26.1.
3+
# on 2025-02-08 14:45:33 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: 34
50+
Max: 38
5151

5252
# Offense count: 5
5353
# Configuration parameters: IgnoredMethods.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def files_upload_v2(params = {})
3232
raise ArgumentError, "Required argument :#{param} missing" if params[param].nil?
3333
end
3434

35+
channel = conversations_id(channel: params[:channels])['channel']['id']
3536
content = params[:content]
3637
title = params[:title] || params[:filename]
3738

@@ -55,7 +56,8 @@ def files_upload_v2(params = {})
5556
end
5657

5758
# Complete the upload.
58-
complete_upload_request_params = params.slice(:channels, :initial_comment, :thread_ts)
59+
complete_upload_request_params = params.slice(:initial_comment, :thread_ts)
60+
complete_upload_request_params[:channels] = channel
5961
complete_upload_request_params[:files] = [{ id: file_id, title: title }].to_json
6062

6163
files_completeUploadExternal(complete_upload_request_params)

spec/fixtures/slack/web/files_upload_v2_with_channel_name.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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@
3636
end
3737
end
3838

39+
context 'when a channel is referenced by name', vcr: { cassette_name: 'web/files_upload_v2_with_channel_name' } do
40+
before do
41+
allow(client).to receive(:conversations_list).and_yield(
42+
Slack::Messages::Message.new(
43+
'channels' => [{
44+
'id' => 'C08AZ76CA4V',
45+
'name' => 'general'
46+
}]
47+
)
48+
)
49+
end
50+
51+
it 'translates the channel name to an ID and completes the upload' do
52+
expect(client.files_upload_v2(
53+
filename: 'test.txt',
54+
content: 'Test File Contents',
55+
channels: '#general'
56+
).files.size).to eq 1
57+
end
58+
end
59+
3960
context 'when using a list for channels', vcr: { cassette_name: 'web/files_upload_v2_with_channels_list' } do
4061
it 'completes the upload' do
4162
expect(client.files_upload_v2(

spec/slack/web/api/mixins/users_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
expect(users.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
3030
end
3131

32-
it 'translates a user that starts with a #' do
32+
it 'translates a user that starts with a @' do
3333
expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
3434
end
3535

0 commit comments

Comments
 (0)