Created
February 17, 2010 14:17
-
-
Save scottwater/306645 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'sinatra' | |
require 'consistenturls' | |
#plugin | |
validate_url_requests | |
get '/' do | |
"Hello World" | |
end | |
get %r{(.+)} do |catch_all| | |
"I am the catch all #{catch_all}<br />#{request.url}" | |
end | |
not_found do | |
"The path #{request.url} does not exist" | |
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
require 'demo_app' | |
require 'test/unit' | |
require 'rack/test' | |
set :environment, :test | |
class ConsistentUrlsTests < Test::Unit::TestCase | |
include Rack::Test::Methods | |
def app | |
@app || Sinatra::Application | |
end | |
def test_urls_with_trailing_slashes_will_be_redirected | |
execute_url_test('/some-random-url/', '/some-random-url') | |
execute_url_test('/some-random-url/second-path/', '/some-random-url/second-path') | |
end | |
def test_urls_with_trailing_slashes_and_querystrings_will_be_redirected | |
execute_url_test('/some-random-url/?abc=123', '/some-random-url?abc=123') | |
execute_url_test('/some-random-URL/?abc=123&z=abc', '/some-random-url?abc=123&z=abc') | |
end | |
def test_case_sensitive_url_will_be_redirected | |
execute_url_test('/CAPS-LOCK-ROCKS', '/caps-lock-rocks') | |
end | |
def test_case_sensitive_url_with_trailing_slash_will_be_redirected | |
execute_url_test('/CAPS-LOCK-ROCKS/', '/caps-lock-rocks') | |
end | |
def test_case_sensitive_url_with_query_string_will_be_redirected | |
execute_url_test('/CAPS-LOCK-ROCKS?abc=123&def=HIJ', '/caps-lock-rocks?abc=123&def=HIJ') | |
execute_url_test('/CAPS-LOCK-ROCKS/ROCKS/It/ROCKs/?abc=123&def=HIJ', '/caps-lock-rocks/rocks/it/rocks?abc=123&def=HIJ') | |
end | |
def execute_url_test(url_to_test, expected_redirect) | |
get url_to_test | |
follow_redirect! | |
assert_equal last_request.url, 'http://example.org' + expected_redirect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment