Skip to content

Instantly share code, notes, and snippets.

@r38y
Created November 18, 2009 19:38
Show Gist options
  • Save r38y/238175 to your computer and use it in GitHub Desktop.
Save r38y/238175 to your computer and use it in GitHub Desktop.
# http://github.com/pivotal/refraction
Refraction.configure do |req|
winit_hosts = {
'itw' => {
'production' => 'winit.intouchweekly.com',
'staging' => 'winit-stage.intouchweekly.com',
'development' => 'winit.intouchweekly.local',
'test' => 'winit.intouchweekly.test'
},
'las' => {
'production' => 'winit.lifeandstylemag.com',
'staging' => 'winit-stage.lifeandstylemag.com',
'development' => 'winit.lifeandstylemag.local',
'test' => 'winit.lifeandstylemag.test'
},
'mmm' => {
'production' => 'winit.mmm-mag.com',
'staging' => 'winit-stage.mmm-mag.com',
'development' => 'winit.mmm-mag.local',
'test' => 'winit.mmm-mag.test'
},
'ww' => {
'production' => 'winit.womansworld.com',
'staging' => 'winit-stage.womansworld.com',
'development' => 'winit.womansworld.local',
'test' => 'winit.womansworld.test'
},
'twist' => {
'production' => 'winit.twistmagazine.com',
'staging' => 'winit-stage.twistmagazine.com',
'development' => 'winit.twistmagazine.local',
'test' => 'winit.twistmagazine.test'
},
'qf' => {
'production' => 'winit.quizfest.com',
'staging' => 'winit-stage.quizfest.com',
'development' => 'winit.quizfest.local',
'test' => 'winit.quizfest.test'
},
'j14' => {
'production' => 'winit.j-14.com',
'staging' => 'winit-stage.j-14.com',
'development' => 'winit.j-14.local',
'test' => 'winit.j-14.test'
},
'ag' => {
'production' => 'winit.astrogirlfreebies.com',
'staging' => 'winit-stage.astrogirlfreebies.com',
'development' => 'winit.astrogirlfreebies.local',
'test' => 'winit.astrogirlfreebies.test'
}
}
winit_codes = winit_hosts.keys.join('|')
case req.path
when %r{^/mb.*$}; req.permanent! "http://#{winit_hosts['itw'][RAILS_ENV]}/?origin=madberries"
when %r{^/(#{winit_codes})(.*)$}; req.permanent! "http://#{winit_hosts[$1][RAILS_ENV]}#{$2}"
end
case req.host
when %r{sweepon}; req.permanent! "http://#{winit_hosts['itw'][RAILS_ENV]}#{req.path}"
when %r{madberries}; req.permanent! "http://#{winit_hosts['itw'][RAILS_ENV]}/?origin=madberries"
when %r{quizfestwinit}; req.permanent! "http://#{winit_hosts['qf'][RAILS_ENV]}#{req.path}"
when %r{twistfreebies}; req.permanent! "http://#{winit_hosts['twist'][RAILS_ENV]}#{req.path}"
end
end
require 'spec_helper'
describe Refraction do
include RewriteMacro
# in touch weekly
it_should_permanently_redirect('http://winit.intouchweekly.test/itw/something', 'http://winit.intouchweekly.test/something')
it_should_permanently_redirect('http://winit.lifeandstylemag.test/itw/something', 'http://winit.intouchweekly.test/something')
# life and style
it_should_permanently_redirect('http://winit.lifeandstylemag.test/las/something', 'http://winit.lifeandstylemag.test/something')
it_should_permanently_redirect('http://winit.intouchweekly.test/las/something', 'http://winit.lifeandstylemag.test/something')
# m magazine
it_should_permanently_redirect('http://winit.mmm-mag.test/mmm/something', 'http://winit.mmm-mag.test/something')
it_should_permanently_redirect('http://winit.j-14.test/mmm/something', 'http://winit.mmm-mag.test/something')
# woman's world
it_should_permanently_redirect('http://winit.womansworld.test/ww/something', 'http://winit.womansworld.test/something')
it_should_permanently_redirect('http://winit.j-14.test/ww/something', 'http://winit.womansworld.test/something')
# twist magazine
it_should_permanently_redirect('http://winit.twistmagazine.test/twist/something', 'http://winit.twistmagazine.test/something')
it_should_permanently_redirect('http://winit.j-14.test/twist/something', 'http://winit.twistmagazine.test/something')
# quizfest
it_should_permanently_redirect('http://winit.quizfest.test/qf/something', 'http://winit.quizfest.test/something')
it_should_permanently_redirect('http://winit.j-14.test/qf/something', 'http://winit.quizfest.test/something')
# j-14
it_should_permanently_redirect('http://winit.j-14.test/j14/something', 'http://winit.j-14.test/something')
it_should_permanently_redirect('http://winit.intouchweekly.test/j14/something', 'http://winit.j-14.test/something')
# astrogirl
it_should_permanently_redirect('http://winit.astrogirlfreebies.test/ag/something', 'http://winit.astrogirlfreebies.test/something')
it_should_permanently_redirect('http://winit.intouchweekly.test/ag/something', 'http://winit.astrogirlfreebies.test/something')
# madberries
it_should_permanently_redirect('http://winit.j-14.test/mb/something', 'http://winit.intouchweekly.test/?origin=madberries')
it_should_permanently_redirect('http://madberries.test/something', 'http://winit.intouchweekly.test/?origin=madberries')
# misc redirects
it_should_permanently_redirect('http://sweepon.test/something', 'http://winit.intouchweekly.test/something')
it_should_permanently_redirect('http://quizfestwinit.test/something', 'http://winit.quizfest.test/something')
it_should_permanently_redirect('http://twistfreebies.test/something', 'http://winit.twistmagazine.test/something')
end
# there is other stuff above this, but only this is applicable
module RewriteMacro
module ExampleGroupMethods
def it_should_permanently_redirect(start_point, end_point)
it "should permanently redirect #{start_point} to #{end_point}" do
env = Rack::MockRequest.env_for(start_point, :method => 'get')
app = mock('app')
response = Refraction.new(app).call(env)
response[0].should == 301
response[1]['Location'].should == end_point
end
end
def it_should_temporarily_redirect(start_point, end_point)
it "should temporarily redirect #{start_point} to #{end_point}" do
env = Rack::MockRequest.env_for(start_point, :method => 'get')
app = mock('app')
response = Refraction.new(app).call(env)
response[0].should == 302
response[1]['Location'].should == end_point
end
end
end
def self.included(receiver)
receiver.extend ExampleGroupMethods
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment