add formData support

This commit is contained in:
ali.q
2017-04-15 01:34:05 +04:30
committed by ali
parent 25d8adaf8b
commit 182ee093f4
12 changed files with 154 additions and 18 deletions

BIN
test-app/spec/fixtures/thumbnail.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -8,11 +8,13 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
tags 'Blogs'
description 'Creates a new blog from provided data'
operationId 'createBlog'
consumes 'application/json'
parameter name: :blog, :in => :body, schema: { '$ref' => '#/definitions/blog' }
consumes 'application/x-www-form-urlencoded'
parameter name: 'blog[title]', :in => :formData, type: 'string'
parameter name: 'blog[content]', :in => :formData, type: 'string'
parameter name: 'blog[thumbnail]', :in => :formData, type: 'file'
response '201', 'blog created' do
let(:blog) { { title: 'foo', content: 'bar' } }
let(:blog) { { title: 'foo', content: 'bar', thumbnail: Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/thumbnail.png")) } }
run_test!
end
@@ -34,7 +36,7 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
response '200', 'success' do
schema type: 'array', items: { '$ref' => '#/definitions/blog' }
let(:keywords) { 'foo bar' }
let(:keywords) { 'foo+bar' }
run_test!
end
end
@@ -59,10 +61,11 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
examples 'application/json' => {
id: 1,
title: 'Hello world!',
content: 'Hello world and hello universe. Thank you all very much!!!'
content: 'Hello world and hello universe. Thank you all very much!!!',
thumbnail: "thumbnail.png"
}
let(:blog) { Blog.create(title: 'foo', content: 'bar') }
let(:blog) { Blog.create(title: 'foo', content: 'bar', thumbnail: 'thumbnail.png') }
let(:id) { blog.id }
run_test!
end
@@ -73,4 +76,29 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
end
end
end
path '/blogs/{id}/upload' do
parameter name: :id, :in => :path, :type => :string
put 'upload a blog thumbnail' do
tags 'Blogs'
description 'Upload a thumbnail for specific blog by id'
operationId 'uploadThumbnailBlog'
consumes 'application/x-www-form-urlencoded'
parameter name: :file, :in => :formData, :type => 'file', required: true
response '200', 'blog updated' do
let(:blog) { Blog.create(title: 'foo', content: 'bar') }
let(:id) { blog.id }
let(:file) { Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/thumbnail.png")) }
run_test!
end
response '404', 'blog not found' do
let(:id) { 'invalid' }
let(:file) { Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/thumbnail.png")) }
run_test!
end
end
end
end

View File

@@ -47,6 +47,10 @@ RSpec.configure do |config|
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
config.after(:suite) do
File.delete("#{Rails.root}/tmp/thumbnail.png") if File.file?("#{Rails.root}/tmp/thumbnail.png")
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin

View File

@@ -39,9 +39,10 @@ RSpec.configure do |config|
properties: {
id: { type: 'integer' },
title: { type: 'string' },
content: { type: 'string' }
content: { type: 'string' },
thumbnail: { type: 'string'}
},
required: [ 'id', 'title', 'content' ]
required: [ 'id', 'title', 'content', 'thumbnail' ]
}
},
securityDefinitions: {