-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Session in favor of private cookies. New testing API.
Sessions -------- This commit removes the `Session` type in favor of methods on the `Cookies` types that allow for adding, removing, and getting private (signed and encrypted) cookies. These methods provide a superset of the functionality of `Session` while also being a minimal addition to the existing API. They can be used to implement the previous `Session` type as well as other forms of session storage. The new methods are: * Cookie::add_private(&mut self, Cookie) * Cookie::remove_private(&mut self, Cookie) * Cookie::get_private(&self, &str) Resolves #20 Testing ------- This commit removes the `rocket::testing` module. It adds the `rocket::local` module which provides a `Client` type for local dispatching of requests against a `Rocket` instance. This `local` package subsumes the previous `testing` package. Rocket Examples --------------- The `forms`, `optional_result`, and `hello_alt_methods` examples have been removed. The following example have been renamed: * extended_validation -> form_validation * hello_ranks -> ranking * from_request -> request_guard * hello_tls -> tls Other Changes ------------- This commit also includes the following smaller changes: * Config::{development, staging, production} constructors have been added for easier creation of default `Config` structures. * The `Config` type is exported from the root. * `Request` implements `Clone` and `Debug`. * `Request::new` is no longer exported. * A `Response::body_bytes` method was added to easily retrieve a response's body as a `Vec<u8>`.
- Loading branch information
1 parent
504a7fe
commit b8ba7b8
Showing
89 changed files
with
1,241 additions
and
1,452 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
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,46 +1,38 @@ | ||
use super::rocket; | ||
use rocket::testing::MockRequest; | ||
use rocket::http::Method::*; | ||
use rocket::local::Client; | ||
|
||
#[test] | ||
fn rewrite_get_put() { | ||
let rocket = rocket(); | ||
let mut req = MockRequest::new(Get, "/"); | ||
let mut response = req.dispatch_with(&rocket); | ||
let client = Client::new(rocket()).unwrap(); | ||
let mut response = client.get("/").dispatch(); | ||
assert_eq!(response.body_string(), Some("Hello, fairings!".into())); | ||
} | ||
|
||
#[test] | ||
fn counts() { | ||
let rocket = rocket(); | ||
let client = Client::new(rocket()).unwrap(); | ||
|
||
// Issue 1 GET request. | ||
let mut req = MockRequest::new(Get, "/"); | ||
req.dispatch_with(&rocket); | ||
client.get("/").dispatch(); | ||
|
||
// Check the GET count, taking into account _this_ GET request. | ||
let mut req = MockRequest::new(Get, "/counts"); | ||
let mut response = req.dispatch_with(&rocket); | ||
let mut response = client.get("/counts").dispatch(); | ||
assert_eq!(response.body_string(), Some("Get: 2\nPost: 0".into())); | ||
|
||
// Issue 1 more GET request and a POST. | ||
let mut req = MockRequest::new(Get, "/"); | ||
req.dispatch_with(&rocket); | ||
let mut req = MockRequest::new(Post, "/"); | ||
req.dispatch_with(&rocket); | ||
client.get("/").dispatch(); | ||
client.post("/").dispatch(); | ||
|
||
// Check the counts. | ||
let mut req = MockRequest::new(Get, "/counts"); | ||
let mut response = req.dispatch_with(&rocket); | ||
let mut response = client.get("/counts").dispatch(); | ||
assert_eq!(response.body_string(), Some("Get: 4\nPost: 1".into())); | ||
} | ||
|
||
#[test] | ||
fn token() { | ||
let rocket = rocket(); | ||
let client = Client::new(rocket()).unwrap(); | ||
|
||
// Ensure the token is '123', which is what we have in `Rocket.toml`. | ||
let mut req = MockRequest::new(Get, "/token"); | ||
let mut res = req.dispatch_with(&rocket); | ||
let mut res = client.get("/token").dispatch(); | ||
assert_eq!(res.body_string(), Some("123".into())); | ||
} |
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
Oops, something went wrong.