Skip to content

Commit

Permalink
Adding the hostess so gem downloading can be tracked
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed May 25, 2009
1 parent b5a13e6 commit 94596da
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -132,7 +132,7 @@ namespace :import do
desc 'Bring the gems through the gemcutter process'
task :process do
require 'rubygems/indexer'
require 'app/cutter'
require 'app/app'

gems = Dir[File.join(ARGV[1], "*.gem")]
puts "Processing #{gems.size} gems..."
Expand Down
2 changes: 1 addition & 1 deletion app/cutter.rb
Expand Up @@ -102,7 +102,7 @@ def index
Cutter.indexer.abbreviate self.spec
Cutter.indexer.sanitize self.spec

quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.name}-#{self.spec.version}.gemspec.rz")
quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.original_name}.gemspec.rz")

zipped = Gem.deflate(Marshal.dump(self.spec))
File.open(quick_path, "wb") do |f|
Expand Down
8 changes: 8 additions & 0 deletions apps/hostess/config.ru
@@ -0,0 +1,8 @@
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))

require 'rubygems'
require 'sinatra'
require 'hostess'

set :environment, :production
run Gem::Hostess
32 changes: 32 additions & 0 deletions apps/hostess/hostess.rb
@@ -0,0 +1,32 @@
require 'rubygems'
require 'sinatra'
require 'haml'
require 'gemcutter'

module Gem
class Hostess < Sinatra::Default
set :app_file, __FILE__

get '/' do
haml :index
end

get "/latest_specs.#{Gem.marshal_version}.gz" do
send_file(current_path)
end

get "/quick/Marshal.#{Gem.marshal_version}/*.gemspec.rz" do
content_type 'application/x-deflate'
send_file(current_path)
end

get "/gems/*.gem" do
content_type 'application/octet-stream'
send_file(current_path)
end

def current_path
Gemcutter.server_path(request.env["PATH_INFO"])
end
end
end
1 change: 1 addition & 0 deletions apps/hostess/views/index.haml
@@ -0,0 +1 @@
%h1 gems.gemcutter.org
5 changes: 5 additions & 0 deletions spec/app_spec.rb
@@ -1,6 +1,11 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
require 'app/app'

describe Gem::App do
def app
Gem::App.new
end

it "should have a homepage" do
mock(Gem::Cutter).count { 24_000 }
get "/"
Expand Down
2 changes: 1 addition & 1 deletion spec/cutter_spec.rb
Expand Up @@ -28,7 +28,7 @@ def mock_save_and_index
mock(Gem::Cutter).indexer.stub!.sanitize(@spec)

marshal = "marshal"
quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{@spec.name}-#{@spec.version}.gemspec.rz")
quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{@spec.original_name}.gemspec.rz")

mock(Marshal).dump(@spec) { mock(Gem).deflate(stub!) }
mock(File).open(quick_path, 'wb')
Expand Down
60 changes: 60 additions & 0 deletions spec/hostess_spec.rb
@@ -0,0 +1,60 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
require 'apps/hostess/hostess'

describe Gem::Hostess do
def app
Gem::Hostess.new
end

def touch(path)
path = Gemcutter.server_path(path)
FileUtils.touch(path)
end

def remove(path)
path = Gemcutter.server_path(path)
FileUtils.rm(path) if File.exists?(path)
end

it "should have a homepage" do
get "/"
last_response.status.should == 200
last_response.body.should =~ /gemcutter/
end

it "should return latest specs" do
file = "/latest_specs.4.8.gz"
touch file
get file
last_response.status.should == 200
end

it "should return quick gemspec" do
file = "/quick/Marshal.4.8/test-0.0.0.gemspec.rz"
touch file
get file
last_response.status.should == 200
last_response.content_type.should == "application/x-deflate"
end

it "should return gem" do
file = "/gems/test-0.0.0.gem"
touch file
get file
last_response.status.should == 200
end

it "should not be able to find non existant gemspec" do
file = "/quick/Marshal.4.8/test-0.0.0.gemspec.rz"
remove file
get file
last_response.status.should == 404
end

it "should not be able to find non existant gem" do
file = "/gems/test-0.0.0.gem"
remove file
get file
last_response.status.should == 404
end
end
12 changes: 3 additions & 9 deletions spec/spec_helper.rb
@@ -1,11 +1,9 @@
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

app_file = File.join(File.dirname(__FILE__), *%w[.. app app.rb])
require app_file
Sinatra::Application.app_file = app_file
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))

require 'rubygems'
require 'spec'
require 'spec/interop/test'
require 'sinatra'
require 'sinatra/test'
require 'rack/test'
require 'fakeweb'
Expand All @@ -25,10 +23,6 @@ def gem_file(name)
Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__), 'gems', name), 'application/octet-stream', :binary)
end

def app
Gem::App.new
end

def regenerate_index
FileUtils.rm_rf Dir["server/cache/*", "server/*specs*", "server/quick", "server/specifications/*"]
Gem::Cutter.indexer.generate_index
Expand Down

0 comments on commit 94596da

Please sign in to comment.