Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 3.3.0 (Next)

* [#602](https://github.com/slack-ruby/slack-ruby-client/pull/602): Make gli an optional dependency; only the `slack` command-line client needs it - [@corsonknowles](https://github.com/corsonknowles).
* [#599](https://github.com/slack-ruby/slack-ruby-client/pull/599): Set a default filename in `files_upload` so Slack displays image previews correctly when none is specified - [@ts-3156](https://github.com/ts-3156), [@dblock](https://github.com/dblock).
* [#591](https://github.com/slack-ruby/slack-ruby-client/pull/591): Generate AI CHANGELOG entries and PR summaries for automated API update PRs, lock simplecov below 1.1.0 to avoid breaking Coveralls - [@dblock](https://github.com/dblock).
* [#590](https://github.com/slack-ruby/slack-ruby-client/pull/590): Add entity.acknowledgeCommentAction and entity.presentComments methods - [@slack-ruby-ci-bot](https://github.com/apps/slack-ruby-ci-bot).
* [#590](https://github.com/slack-ruby/slack-ruby-client/pull/590): Add admin.apps.mcpServers, admin.apps.mcpServers.permissions, and admin.apps.permissions endpoints - [@slack-ruby-ci-bot](https://github.com/apps/slack-ruby-ci-bot).
Expand Down
1 change: 1 addition & 0 deletions lib/slack/web/api/endpoints/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def files_sharedPublicURL(options = {})
# @see https://api.slack.com/methods/files.upload
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/files/files.upload.json
def files_upload(options = {})
options = options.merge(filename: 'file') if options[:file] && !options[:filename]
post('files.upload', options)
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/slack/web/api/patches/files.default-filename.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/lib/slack/web/api/endpoints/files.rb b/lib/slack/web/api/endpoints/files.rb
index 13a1889..9ce4894 100644
--- a/lib/slack/web/api/endpoints/files.rb
+++ b/lib/slack/web/api/endpoints/files.rb
@@ -192,6 +192,7 @@ module Slack
# @see https://api.slack.com/methods/files.upload
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/files/files.upload.json
def files_upload(options = {})
+ options = options.merge(filename: 'file') if options[:file] && !options[:filename]
post('files.upload', options)
end
end
19 changes: 19 additions & 0 deletions spec/slack/web/api/endpoints/custom/files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
RSpec.describe Slack::Web::Api::Endpoints::Files do
let(:client) { Slack::Web::Client.new }

describe '#files_upload' do
it 'defaults the filename when a file is supplied' do
options = { file: 'file contents' }
expect(client).to receive(:post).with('files.upload', { file: 'file contents', filename: 'file' })
client.files_upload(options)
expect(options).to eq(file: 'file contents')
end

it 'preserves an explicit filename' do
expect(client).to receive(:post).with('files.upload', { file: 'file contents', filename: 'image.png' })
client.files_upload(file: 'file contents', filename: 'image.png')
end

it 'does not add a filename when no file is supplied' do
expect(client).to receive(:post).with('files.upload', { content: 'text' })
client.files_upload(content: 'text')
end
end

%w[filename content].each do |arg|
context "when #{arg} is missing from options" do
let(:params) do
Expand Down
Loading