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
4 changed files
with
65 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,60 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
describe "rack-redirect" do | ||
it 'redirects from http://example.org to http://www.example.org/' do | ||
get '/' | ||
last_response['Location'].should eql('http://www.example.org/') | ||
end | ||
describe "with a value of 'www.'" do | ||
def app | ||
@app ||= Rack::Builder.new do | ||
use EY::Solo::Rack::Redirect do |app| | ||
app.prefix = 'www.' | ||
end | ||
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] } | ||
end | ||
end | ||
it 'redirects from http://example.org to http://www.example.org/' do | ||
get '/' | ||
last_response['Location'].should eql('http://www.example.org/') | ||
end | ||
|
||
it 'redirects from http://alpha.example.com to http://www.example.org/' do | ||
get '/', {}, {'SERVER_NAME' => 'alpha.example.org'} | ||
last_response['Location'].should eql('http://www.example.org/') | ||
end | ||
it 'redirects from http://alpha.example.com to http://www.example.org/' do | ||
get '/', {}, {'SERVER_NAME' => 'alpha.example.org'} | ||
last_response['Location'].should eql('http://www.example.org/') | ||
end | ||
|
||
it 'redirects from http://example.org/nate to http://www.example.org/nate' do | ||
get '/nate' | ||
last_response['Location'].should eql('http://www.example.org/nate') | ||
end | ||
|
||
it 'redirects from http://example.org/nate to http://www.example.org/nate' do | ||
get '/nate' | ||
last_response['Location'].should eql('http://www.example.org/nate') | ||
it 'redirects from http://example.org/nate?trip_id=42 to http://www.example.org/nate?trip_id=42' do | ||
get '/nate', :trip_id => 42 | ||
last_response['Location'].should eql('http://www.example.org/nate?trip_id=42') | ||
end | ||
end | ||
describe "without specifying a prefix" do | ||
def app | ||
@app ||= Rack::Builder.new do | ||
use EY::Solo::Rack::Redirect | ||
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] } | ||
end | ||
end | ||
it 'forwards on requests from http://example.org to the next app' do | ||
pending | ||
last_response.body.should eql("Hello there, gorgeous") | ||
end | ||
|
||
it 'redirects from http://alpha.example.com to http://example.org/' do | ||
get '/', {}, {'SERVER_NAME' => 'alpha.example.org'} | ||
last_response['Location'].should eql('http://example.org/') | ||
end | ||
|
||
it 'redirects from http://alpha.example.org/nate to http://example.org/nate' do | ||
get '/nate', {}, {'SERVER_NAME' => 'alpha.example.org'} | ||
last_response['Location'].should eql('http://example.org/nate') | ||
end | ||
|
||
it 'redirects from http://example.org/nate?trip_id=42 to http://www.example.org/nate?trip_id=42' do | ||
get '/nate', :trip_id => 42 | ||
last_response['Location'].should eql('http://www.example.org/nate?trip_id=42') | ||
it 'redirects from http://alpha.example.org/nate?trip_id=42 to http://example.org/nate?trip_id=42' do | ||
get '/nate', {:trip_id => 42}, {'SERVER_NAME' => 'alpha.example.org'} | ||
last_response['Location'].should eql('http://example.org/nate?trip_id=42') | ||
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