Skip to content

Commit b8ac295

Browse files
committed
Add an example of documenting file uploads
1 parent f838203 commit b8ac295

5 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ If you are not using Rake:
699699
$ rspec spec/acceptance --format RspecApiDocumentation::ApiFormatter
700700
```
701701

702+
## Uploading a file
703+
704+
For an example on uploading a file see `examples/spec/acceptance/upload_spec.rb`.
705+
702706
## Gotchas
703707

704708
- rspec_api_documentation relies on a variable `client` to be the test client. If you define your own `client` please configure rspec_api_documentation to use another one, see Configuration above.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class UploadsController < ApplicationController
2+
def create
3+
head 201
4+
end
5+
end

example/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Rails.application.routes.draw do
22
resources :orders
33

4+
resources :uploads, :only => :create
5+
46
mount Raddocs::App => "/docs", :anchor => false
57
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'acceptance_helper'
2+
3+
resource "Uploads" do
4+
post "/uploads" do
5+
parameter :file, "New file to upload"
6+
7+
let(:file) { Rack::Test::UploadedFile.new("spec/fixtures/file.png", "image/png") }
8+
9+
example_request "Uploading a new file" do
10+
expect(status).to eq(201)
11+
end
12+
end
13+
end

example/spec/fixtures/file.png

150 Bytes
Loading

0 commit comments

Comments
 (0)