Skip to content

Commit

Permalink
Remove mime-types dependency in specs (#2406)
Browse files Browse the repository at this point in the history
* Remove mime-types dependency in specs

* Add CHANGELOG.md entry
  • Loading branch information
ericproulx authored Jan 5, 2024
1 parent 3d85058 commit 10944de
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#2397](https://github.com/ruby-grape/grape/pull/2397): Add support for ruby 3.3 - [@ericproulx](https://github.com/ericproulx).
* [#2399](https://github.com/ruby-grape/grape/pull/2399): Update `rubocop` to 1.59.0, `rubocop-performance` to 1.20.1 and `rubocop-rspec` to 2.25.0 - [@ericproulx](https://github.com/ericproulx).
* [#2402](https://github.com/ruby-grape/grape/pull/2402): Grape::Deprecations will be raised when running specs - [@ericproulx](https://github.com/ericproulx).
* [#2406](https://github.com/ruby-grape/grape/pull/2406): Remove mime-types dependency in specs - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/multi_json.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/multi_xml.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rack_1_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rack_2_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rack_3_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rack_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end

group :test do
gem 'grape-entity', '~> 0.6', require: false
gem 'mime-types'
gem 'rack-jsonp', require: 'rack/jsonp'
gem 'rack-test', '< 2.1'
gem 'rspec', '< 4'
Expand Down
45 changes: 27 additions & 18 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1324,36 +1324,45 @@ class DummyFormatClass

context 'env["api.format"]' do
before do
ct = content_type
subject.post 'attachment' do
filename = params[:file][:filename]
content_type MIME::Types.type_for(filename)[0].to_s
content_type ct
env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
header 'Content-Disposition', "attachment; filename*=UTF-8''#{CGI.escape(filename)}"
params[:file][:tempfile].read
end
end

['/attachment.png', 'attachment'].each do |url|
it "uploads and downloads a PNG file via #{url}" do
image_filename = 'grape.png'
post url, file: Rack::Test::UploadedFile.new(image_filename, 'image/png', true)
expect(last_response.status).to eq(201)
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq('image/png')
expect(last_response.headers['Content-Disposition']).to eq("attachment; filename*=UTF-8''grape.png")
File.open(image_filename, 'rb') do |io|
expect(last_response.body).to eq io.read
context 'when image/png' do
let(:content_type) { 'image/png' }

%w[/attachment.png attachment].each do |url|
it "uploads and downloads a PNG file via #{url}" do
image_filename = 'grape.png'
post url, file: Rack::Test::UploadedFile.new(image_filename, content_type, true)
expect(last_response.status).to eq(201)
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq(content_type)
expect(last_response.headers['Content-Disposition']).to eq("attachment; filename*=UTF-8''grape.png")
File.open(image_filename, 'rb') do |io|
expect(last_response.body).to eq io.read
end
end
end
end

it 'uploads and downloads a Ruby file' do
filename = __FILE__
post '/attachment.rb', file: Rack::Test::UploadedFile.new(filename, 'application/x-ruby', true)
expect(last_response.status).to eq(201)
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq('application/x-ruby')
expect(last_response.headers['Content-Disposition']).to eq("attachment; filename*=UTF-8''api_spec.rb")
File.open(filename, 'rb') do |io|
expect(last_response.body).to eq io.read
context 'when ruby file' do
let(:content_type) { 'application/x-ruby' }

it 'uploads and downloads a Ruby file' do
filename = __FILE__
post '/attachment.rb', file: Rack::Test::UploadedFile.new(filename, content_type, true)
expect(last_response.status).to eq(201)
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq(content_type)
expect(last_response.headers['Content-Disposition']).to eq("attachment; filename*=UTF-8''api_spec.rb")
File.open(filename, 'rb') do |io|
expect(last_response.body).to eq io.read
end
end
end
end
Expand Down

0 comments on commit 10944de

Please sign in to comment.