forked from paul/resourceful
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
260 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'resourceful' | ||
|
||
describe Resourceful do | ||
|
||
describe "basic auth" do | ||
|
||
end | ||
|
||
describe "digest auth" do | ||
|
||
end | ||
|
||
end | ||
|
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,145 @@ | ||
|
||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'resourceful' | ||
|
||
describe Resourceful do | ||
|
||
describe "caching" do | ||
|
||
before do | ||
@http = Resourceful::HttpAccessor.new(:cache_manager => Resourceful::InMemoryCacheManager.new) | ||
if ENV['SPEC_LOGGING'] | ||
@http.logger = Resourceful::StdOutLogger.new | ||
end | ||
end | ||
|
||
def get_with_errors(resource) | ||
begin | ||
resp = resource.get | ||
rescue Resourceful::UnsuccessfulHttpRequestError => e | ||
resp = e.http_response | ||
end | ||
resp | ||
end | ||
|
||
def uri_plus_params(uri, params = {}) | ||
uri = uri.is_a?(Addressable::URI) ? uri : Addressable::URI.parse(uri) | ||
uri.query_values = params | ||
uri | ||
end | ||
|
||
def uri_for_code(code, params = {}) | ||
uri = Addressable::URI.expand_template("http://localhost:3000/code/{code}", | ||
"code" => code.to_s) | ||
|
||
uri_plus_params(uri, params) | ||
end | ||
|
||
describe "response cacheability" do | ||
Resourceful::Response::NORMALLY_CACHEABLE_RESPONSE_CODES.each do |code| | ||
describe "response code #{code}" do | ||
it "should normally be cached" do | ||
resource = @http.resource(uri_for_code(code)) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should be_cacheable | ||
end | ||
|
||
it "should not be cached if Vary: *" do | ||
resource = @http.resource(uri_for_code(200, "Vary" => "*")) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should_not be_cacheable | ||
end | ||
|
||
it "should not be cached if Cache-Control: no-cache'" do | ||
resource = @http.resource(uri_for_code(200, "Cache-Control" => "no-cache")) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should_not be_cacheable | ||
end | ||
end | ||
end | ||
|
||
# I would prefer to do all other codes, but some of them do some magic stuff (100), | ||
# so I'll just spot check. | ||
[201, 206, 302, 307, 404, 500].each do |code| | ||
describe "response code #{code}" do | ||
it "should not normally be cached" do | ||
resource = @http.resource(uri_for_code(code)) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should_not be_cacheable | ||
end | ||
|
||
it "should be cached if Cache-Control: public" do | ||
resource = @http.resource(uri_for_code(code, "Cache-Control" => "public")) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should be_cacheable | ||
end | ||
|
||
it "should be cached if Cache-Control: private" do | ||
resource = @http.resource(uri_for_code(code, "Cache-Control" => "private")) | ||
|
||
resp = get_with_errors(resource) | ||
resp.should be_cacheable | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
describe "expiration" do | ||
it 'should use the cached response if Expire: is in the future' do | ||
in_the_future = (Time.now + 60).httpdate | ||
resource = @http.resource(uri_for_code(200, "Expire" => in_the_future)) | ||
|
||
resp = resource.get | ||
resp.should_not be_expired | ||
|
||
resp = resource.get | ||
resp.should be_ok | ||
resp.should_not be_authoritative | ||
end | ||
|
||
it 'should revalidate the cached response if the response is expired' do | ||
in_the_past = (Time.now - 60).httpdate | ||
resource = @http.resource(uri_for_code(200, "Expire" => in_the_past)) | ||
|
||
resp = resource.get | ||
resp.should be_expired | ||
|
||
resp = resource.get | ||
resp.should be_ok | ||
resp.should be_authoritative | ||
end | ||
end | ||
|
||
describe "Not Modified responses" do | ||
it "should replace the 304 with whats in the cache" do | ||
now = Time.now.httpdate | ||
|
||
resource = @http.resource(uri_plus_params('http://localhost:3000/cached', | ||
"modified" => now)) | ||
|
||
resp = resource.get | ||
resp.should be_authoritative | ||
body = resp.body | ||
|
||
resp = resource.get("Cache-Control" => "max-age=0") | ||
resp.should be_authoritative | ||
resp.body.should == body | ||
end | ||
|
||
it "should merge the headers" | ||
end | ||
|
||
describe "cache invalidation" do | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
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,12 @@ | ||
|
||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'resourceful' | ||
|
||
describe Resourceful do | ||
|
||
describe "manipulating headers" do | ||
|
||
end | ||
|
||
end | ||
|
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,12 @@ | ||
|
||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'resourceful' | ||
|
||
describe Resourceful do | ||
|
||
describe "redirects" do | ||
|
||
end | ||
|
||
end | ||
|
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
Oops, something went wrong.