Skip to content

Commit

Permalink
Rewind request body for rack-test
Browse files Browse the repository at this point in the history
close #20
  • Loading branch information
k0kubun committed Feb 20, 2021
1 parent 7a291b5 commit 76d3ba9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
def build(context, example:)
if rack_test?(context)
request = ActionDispatch::Request.new(context.last_request.env)
request.body.rewind if request.body.respond_to?(:rewind)
response = ActionDispatch::TestResponse.new(*context.last_response.to_a)
else
request = context.request
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/roda_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../roda/app'
require_relative '../roda/roda_app'
require 'json'
require 'rack/test'
RSpec::OpenAPI.path = File.expand_path('../roda/doc/openapi.yaml', __dir__)
Expand All @@ -13,7 +13,7 @@
include Rack::Test::Methods

let(:app) do
App
RodaApp
end

describe '/roda' do
Expand Down
8 changes: 3 additions & 5 deletions spec/roda/app.rb → spec/roda/roda_app.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require 'roda'

class App < Roda
class RodaApp < Roda
plugin :json, classes: [Array, Hash]

route do |r|
r.on 'roda' do
# POST /roda
r.post do
{
id: 1,
name: 'hello',
}
params = JSON.parse(request.body.read, symbolize_names: true)
params.merge({ name: 'hello' })
end
end
end
Expand Down

0 comments on commit 76d3ba9

Please sign in to comment.