Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Add tests to ensure URLs with query parameters are maintained
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Feb 9, 2015
1 parent e054e84 commit e7b5cd2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.8 (2014-02-09)

* Add tests to ensure URLs with query parameters are maintained

## 0.1.7 (2014-02-02)

* Refactor and simplify `revalidate_response()` method
Expand Down
2 changes: 1 addition & 1 deletion cache_rules.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'date'

Gem::Specification.new do |s|
s.name = 'cache_rules'
s.version = '0.1.7'
s.version = '0.1.8'

s.date = Date.today.to_s

Expand Down
19 changes: 15 additions & 4 deletions test/test_cache_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ def test_get_money
assert_equal got_money, "Dolla Dolla Bill Y'all"
end

def test_validate_column0_query_params_fail
request = {"Host"=>"test.url"}

result = CacheRules.validate('http://test.url/test1?test=string', request)

assert_equal result[:code], 307
assert_nil result[:body]
assert_equal result[:headers]['Cache-Lookup'], 'MISS'
refute_equal result[:headers]['Location'], "http://test.url/test1"
end

def test_validate_column0
request = {"Host"=>"test.url"}

result = CacheRules.validate('http://test.url/test1', request)
result = CacheRules.validate('http://test.url/test1?test=string', request)

assert_equal result[:code], 307
assert_nil result[:body]
assert_equal result[:headers]['Cache-Lookup'], 'MISS'
assert_equal result[:headers]['Location'], "http://test.url/test1"
assert_equal result[:headers]['Location'], "http://test.url/test1?test=string"
end

def test_validate_column1
Expand Down Expand Up @@ -128,8 +139,8 @@ def test_revalidate_response_column0
request = {"Host"=>"test.url", "If-None-Match"=>["*"], "Cache-Control"=>{"max-age"=>{"token"=>"100000000", "quoted_string"=>nil}}}
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Cache-Control"=>{"s-maxage"=>{"token"=>"100000000", "quoted_string"=>nil}}, "X-Cache-Req-Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Last-Modified" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}

FakeWeb.register_uri(:head, "http://test.url/test1", :status => ["304", "Not Modified"], :date => "Sat, 03 Jan 2015 07:15:45 GMT", :Warning => "299 - \"Hello World\"")
result = CacheRules.revalidate_response('http://test.url/test1', request, cached)
FakeWeb.register_uri(:head, "http://test.url/test1?test=string", :status => ["304", "Not Modified"], :date => "Sat, 03 Jan 2015 07:15:45 GMT", :Warning => "299 - \"Hello World\"")
result = CacheRules.revalidate_response('http://test.url/test1?test=string', request, cached)

assert_equal result[:code], 200
assert_equal result[:body], 'cached'
Expand Down
4 changes: 2 additions & 2 deletions test/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_run_validate
end

def test_response_request
url = 'http://test.url'
url = 'http://test.url?test=string'
act = CacheRules::REQUEST_TABLE[:actions]

column0 = CacheRules.helper_response url, act, 0, @cached_headers
Expand All @@ -78,7 +78,7 @@ def test_response_request
column7 = CacheRules.helper_response url, act, 7, @cached_headers
column8 = CacheRules.helper_response url, act, 8, @cached_headers

assert_equal column0, {:body=>nil, :code=>307, :headers=>{"Cache-Lookup"=>"MISS", "Location"=>"http://test.url"}}
assert_equal column0, {:body=>nil, :code=>307, :headers=>{"Cache-Lookup"=>"MISS", "Location"=>"http://test.url?test=string"}}
assert_equal column1, {:body=>"Gateway Timeout", :code=>504, :headers=>{"Cache-Lookup"=>"MISS"}}

assert_equal column2[:body], 'cached'
Expand Down

0 comments on commit e7b5cd2

Please sign in to comment.