remove sinatra and use AC::Metal for the shortener instead #499

Merged
merged 2 commits into from Apr 11, 2012
View
@@ -4,7 +4,6 @@ gem 'travis-core', git: 'git://github.com/travis-ci/travis-core', require: 't
gem 'travis-support', git: 'git://github.com/travis-ci/travis-support'
gem 'rails', '~> 3.2.3'
-gem 'sinatra', '~> 1.3.1'
gem 'rake', '~> 0.9.2.2'
gem 'bunny', '~> 0.7.9'
@@ -25,7 +24,7 @@ gem 'pg', '~> 0.13.2'
# apis + metrics
gem 'backports', '~> 2.3.0'
-gem 'gh', git: 'git://github.com/rkh/gh.git'
+gem 'gh', git: 'git://github.com/rkh/gh'
@henrikhodne

henrikhodne Apr 10, 2012

Contributor

Shouldn't this still be …gh.git? Also, this doesn't really have anything to do with this PR, does it?

gem 'hubble', git: 'git://github.com/mattmatt/hubble'
gem 'metriks', git: 'git://github.com/mattmatt/metriks', ref: 'source'
gem 'newrelic_rpm', '~> 3.3.0'
@@ -43,7 +42,7 @@ group :assets do
gem 'uglifier', '~> 1.2.0'
gem 'compass', '0.12.alpha.4'
gem "i18n-js", '~> 2.1.2'
- gem "localeapp-i18n-js", :git => 'git://github.com/randym/localeapp-i18n-js.git'
+ gem "localeapp-i18n-js", :git => 'git://github.com/randym/localeapp-i18n-js'
@henrikhodne

henrikhodne Apr 10, 2012

Contributor

Same thing applies here and to the rest of the changes (except the sinatra one, of course).

@joshk

joshk Apr 10, 2012

Owner

.git doesn't affect bundling, and I only added this to the PR as I saw it and cleaned it up at the same time.

On 10/04/2012, at 8:22 PM, Henrik Hodne wrote:

@@ -43,7 +42,7 @@ group :assets do
gem 'uglifier', '> 1.2.0'
gem 'compass', '0.12.alpha.4'
gem "i18n-js", '
> 2.1.2'

  • gem "localeapp-i18n-js", :git => 'git://github.com/randym/localeapp-i18n-js.git'
  • gem "localeapp-i18n-js", :git => 'git://github.com/randym/localeapp-i18n-js'

Same thing applies here and to the rest of the changes (except the sinatra one, of course).


Reply to this email directly or view it on GitHub:
https://github.com/travis-ci/travis-ci/pull/499/files#r666996

end
group :development, :test do
@@ -52,7 +51,7 @@ group :development, :test do
gem 'forgery', '~> 0.5.0'
gem 'rspec-rails', '~> 2.8.0'
gem 'thin', '~> 1.3.1'
- gem "localeapp-i18n-js", git: 'git://github.com/randym/localeapp-i18n-js.git'
+ gem "localeapp-i18n-js", git: 'git://github.com/randym/localeapp-i18n-js'
end
group :development do
@@ -66,7 +65,7 @@ group :development do
end
group :test do
- gem 'jasmine', git: 'git://github.com/pivotal/jasmine-gem.git', submodules: true
+ gem 'jasmine', git: 'git://github.com/pivotal/jasmine-gem', submodules: true
gem 'capybara', '~> 1.1.2'
gem 'database_cleaner', '~> 0.7.0'
gem 'mocha', '~> 0.10.0'
View
@@ -15,7 +15,7 @@ GIT
hitimes (~> 1.1)
GIT
- remote: git://github.com/pivotal/jasmine-gem.git
+ remote: git://github.com/pivotal/jasmine-gem
revision: c72e8d248d49a1ebe53f31a09ac511194ad4edf1
submodules: true
specs:
@@ -33,7 +33,7 @@ GIT
rack (>= 0.9.1)
GIT
- remote: git://github.com/randym/localeapp-i18n-js.git
+ remote: git://github.com/randym/localeapp-i18n-js
revision: 521a0e289a3bfc6fff51f2f37d34d45a726e43c5
specs:
localeapp-i18n-js (0.0.1a)
@@ -42,7 +42,7 @@ GIT
rails (~> 3.2.1)
GIT
- remote: git://github.com/rkh/gh.git
+ remote: git://github.com/rkh/gh
revision: d6d31683c13d93c26358ef842421d70623ded34f
specs:
gh (0.2.2)
@@ -236,8 +236,6 @@ GEM
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
- rack-protection (1.2.0)
- rack
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
@@ -306,10 +304,6 @@ GEM
simple_states (0.1.0.pre2)
activesupport
hashr (~> 0.0.10)
- sinatra (1.3.2)
- rack (~> 1.3, >= 1.3.6)
- rack-protection (~> 1.2)
- tilt (~> 1.3, >= 1.3.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -378,7 +372,6 @@ DEPENDENCIES
rspec-rails (~> 2.8.0)
ruby-debug19
sass-rails (~> 3.2.4)
- sinatra (~> 1.3.1)
thin (~> 1.3.1)
travis-core!
travis-support!
@@ -17,15 +17,15 @@ $.extend Sponsors,
PACKAGES: ['platinum', 'gold', 'silver']
SPEED: 15000
load: (callback) ->
- $.get '/sponsors.json', (packages) =>
- callback(Sponsors.decksFrom(packages))
- decksFrom: (packages) ->
+ $.get '/sponsors.json', (bundles) =>
+ callback(Sponsors.decksFrom(bundles))
+ decksFrom: (bundles) ->
decks = { banner: [], text: [] }
- for package of packages
- sponsors = packages[package].shuffle()
- count = Deck.COUNTS[package]
- type = if package == 'silver' then 'text' else 'banner'
- decks[type].push(new Deck(type, package, sponsors.slice(i, i + count))) for i in [0..sponsors.length - 1] by count
+ for bundle of bundles
+ sponsors = bundles[bundle].shuffle()
+ count = Deck.COUNTS[bundle]
+ type = if bundle == 'silver' then 'text' else 'banner'
+ decks[type].push(new Deck(type, bundle, sponsors.slice(i, i + count))) for i in [0..sponsors.length - 1] by count
decks
$.extend Sponsors.prototype,
clear: ->
@@ -40,9 +40,9 @@ $.extend Sponsors.prototype,
@run()
setTimeout(doRun.bind(@), @speed || Sponsors.SPEED)
-Deck = (type, package, sponsors) ->
+Deck = (type, bundle, sponsors) ->
@type = type
- @package = package
+ @bundle = bundle
@sponsors = if type == 'banner' then @fill(sponsors) else sponsors
@
$.extend Deck,
@@ -52,12 +52,12 @@ $.extend Deck,
silver: 6
$.extend Deck.prototype,
fill: (sponsors)->
- sponsors.push({ image: @placeholder() }) while sponsors.length < Deck.COUNTS[@package]
+ sponsors.push({ image: @placeholder() }) while sponsors.length < Deck.COUNTS[@bundle]
sponsors
placeholder: ->
- '/images/placeholder-' + @package + '.png'
+ '/images/placeholder-' + @bundle + '.png'
render: ->
- node = $('<ul class="' + @package + '"></ul>')
+ node = $('<ul class="' + @bundle + '"></ul>')
node.append(new Sponsor(@type, sponsor).render()) for sponsor in @sponsors
node
@@ -0,0 +1,19 @@
+class ShortenerController < ActionController::Metal
+ include ActionController::Redirecting
+ include ActionController::Rendering
+
+ def index
+ redirect_to "http://#{Travis.config.host}"
+ end
+
+ def show
+ url = Url.where(:code => params[:id]).first
+
+ if url
+ redirect_to url.url
+ else
+ render :file => "#{Rails.root}/public/404.html", :status => 404
+ end
+ end
+
+end
View
@@ -1,9 +1,8 @@
-require 'shortener'
-
TravisCi::Application.routes.draw do
constraints :host => Travis.config.shorten_host do
- mount Travis::Shortener => '/'
+ get '/', :to => 'shortener#index'
+ get '/:id', :to => 'shortener#show'
end
root :to => 'home#index'
View
@@ -1,19 +0,0 @@
-module Travis
- class Shortener < Sinatra::Base
-
- get '/' do
- redirect "http://#{Travis.config.host}"
- end
-
- get '/:id' do
- url = Url.where(:code => params[:id]).first
-
- if url
- redirect url.url
- else
- raise Sinatra::NotFound
- end
- end
-
- end
-end
View
@@ -1,31 +0,0 @@
-require 'spec_helper'
-
-describe Travis::Shortener do
- include Rack::Test::Methods
- let(:app) { subject }
-
- describe "GET /" do
- it "should redirect to travis-ci.org" do
- get '/'
- last_response.should be_redirect
- follow_redirect!
- last_request.url.should == 'http://travis-ci.org/'
- end
- end
-
- describe "GET /:id" do
- it "should redirect to the found url" do
- url = Url.create! :url => 'http://example.com'
-
- get "/#{url.code}"
- last_response.should be_redirect
- follow_redirect!
- last_request.url.should == 'http://example.com/'
- end
-
- it "should raise a 404 if the url couldn't be found" do
- get '/foobar'
- last_response.status.should == 404
- end
- end
-end
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe ShortenerController do
+
+ describe "GET /" do
+ it "should redirect to travis-ci.org" do
+ get '/', nil, { 'HTTP_HOST' => 'trvs.io' }
+ response.should be_redirect
+ response.should redirect_to 'http://travis-ci.org'
+ end
+ end
+
+ describe "GET /:id" do
+ it "should redirect to the found url" do
+ url = Url.create!(:url => 'http://example.com')
+
+ get "/#{url.code}", nil, { 'HTTP_HOST' => 'trvs.io' }
+ response.should be_redirect
+ response.should redirect_to 'http://example.com'
+ end
+
+ it "should raise a 404 if the url couldn't be found" do
+ get '/foobar', nil, { 'HTTP_HOST' => 'trvs.io' }
+ response.status.should == 404
+ end
+ end
+
+end