forked from lostisland/faraday
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rough ActionDispatch adapter for testing Rails 3 APIs with Faraday
- Loading branch information
1 parent
71248de
commit b0941f3
Showing
2 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Faraday | ||
module Adapter | ||
class ActionDispatch < Middleware | ||
attr_reader :session | ||
|
||
# Initializes a new middleware instance for each request. Instead of | ||
# initiating an HTTP request with a web server, this adapter calls | ||
# a Rails 3 app using integration tests. | ||
# | ||
# app - The current Faraday request. | ||
# session - An ActionDispatch::Integration::Session instance. | ||
# | ||
# Returns nothing. | ||
def initialize(app, session) | ||
super(app) | ||
@session = session | ||
end | ||
|
||
def call(env) | ||
process_body_for_request(env) | ||
full_path = full_path_for(env[:url].path, env[:url].query, env[:url].fragment) | ||
@session.__send__(env[:method], full_path, env[:body], env[:request_headers]) | ||
resp = @session.response | ||
env.update \ | ||
:status => resp.status, | ||
:response_headers => resp.headers, | ||
:body => resp.body | ||
@app.call env | ||
end | ||
end | ||
end | ||
end |