Skip to content

Commit

Permalink
Add test for uploading files in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloBezpalov committed Dec 14, 2016
1 parent 1135b12 commit c9df040
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions features/upload_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ Feature: Uploading a file
[200, {}, [request.params["post"]["file"][:filename]]]
end
end
"""
"""
Given a file named "nested_param_in_array.rb" with:
"""
require 'rack'
class App
def self.call(env)
request = Rack::Request.new(env)
[200, {}, [request.params["post"]["files"][0][:filename]]]
end
end
"""

Scenario: Uploading a text file with nested parameters
Given a file named "file.txt" with:
Expand All @@ -40,7 +51,7 @@ Feature: Uploading a file
resource "FooBars" do
post "/foobar" do
parameter :post, "Post paramter"
parameter :post, "Post parameter"
let(:post) do
{
Expand Down Expand Up @@ -161,6 +172,42 @@ Feature: Uploading a file

When I run `rspec app_spec.rb --require ./nestedparam.rb --format RspecApiDocumentation::ApiFormatter`

Then the output should contain "1 example, 0 failures"
And the exit status should be 0
And the generated documentation should be encoded correctly

Scenario: Uploading an image file in params array
Given I move the sample image into the workspace
And a file named "app_spec.rb" with:
"""
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"
require "rack/test"
RspecApiDocumentation.configure do |config|
config.app = App
end
resource "FooBars" do
post "/foobar" do
parameter :post, "Post parameter"
let(:post) do
{
id: 10,
files: [ Rack::Test::UploadedFile.new("file.png", "image/png") ]
}
end
example_request "Uploading a file" do
expect(response_body).to eq("file.png")
end
end
end
"""

When I run `rspec app_spec.rb --require ./nested_param_in_array.rb --format RspecApiDocumentation::ApiFormatter`

Then the output should contain "1 example, 0 failures"
And the exit status should be 0
And the generated documentation should be encoded correctly

0 comments on commit c9df040

Please sign in to comment.