Sha256: 55509997333fe7f440c712cc0630da7390fec5afb798583dbb467548c6ddc796
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
require 'spec_helper' describe 'Redirector middleware' do before do FactoryGirl.create(:redirect_rule, :destination => '/news/5', :source => '/my_custom_url') FactoryGirl.create(:redirect_rule_regex, :destination => '/news/$1', :source => '/my_custom_url/([A-Za-z0-9_]+)') FactoryGirl.create(:redirect_rule_regex, :destination => '/news', :source => 'categoryID=12345') end it 'correctly redirects the visitor for an exact match rule' do visit '/my_custom_url' current_path.should == '/news/5' end it 'correctly redirects the visitor for a regex match rule' do visit '/my_custom_url/20' current_path.should == '/news/20' end it 'should not do the query string match if the Redirector.include_query_in_source is false' do visit '/my_old_url?categoryID=12345' current_path.should == '/my_old_url' end it 'should do the query string match if the Redirector.include_query_in_source is true' do original_option = Redirector.include_query_in_source Redirector.include_query_in_source = true visit '/my_old_url?categoryID=12345' current_path.should == '/news' Redirector.include_query_in_source = original_option end it 'handles requests with or without a port specified' do Capybara.app_host = 'http://example.com' visit '/my_custom_url' current_url.should == 'http://example.com/news/5' Capybara.app_host = 'http://example.com:3000' visit '/my_custom_url' current_url.should == 'http://example.com:3000/news/5' end it 'handles invalid URIs properly' do bad_rule = FactoryGirl.create(:redirect_rule_regex, :destination => 'http://www.example.com$1', :source => '^/custom(.*)$') begin visit '/custom)%e2' rescue Redirector::RuleError => e e.message.should == "RedirectRule #{bad_rule.id} generated the bad destination: http://www.example.com)%e2" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redirector-0.1.5 | spec/features/middleware_spec.rb |