Skip to content

Commit

Permalink
Remove mime-types dependency in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Jan 5, 2024
1 parent 3d85058 commit 2f67f06
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 30 deletions.
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 2f67f06

Please sign in to comment.