Permalink
Browse files

Adding the hostess so gem downloading can be tracked

  • Loading branch information...
1 parent b5a13e6 commit 94596da43a8f472907f84e3736c9d8df11eb47d5 @qrush qrush committed May 25, 2009
Showing with 112 additions and 12 deletions.
  1. +1 −1 Rakefile
  2. +1 −1 app/cutter.rb
  3. +8 −0 apps/hostess/config.ru
  4. +32 −0 apps/hostess/hostess.rb
  5. +1 −0 apps/hostess/views/index.haml
  6. +5 −0 spec/app_spec.rb
  7. +1 −1 spec/cutter_spec.rb
  8. +60 −0 spec/hostess_spec.rb
  9. +3 −9 spec/spec_helper.rb
View
@@ -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..."
View
@@ -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|
View
@@ -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
View
@@ -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
@@ -0,0 +1 @@
+%h1 gems.gemcutter.org
View
@@ -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 "/"
View
@@ -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')
View
@@ -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
View
@@ -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'
@@ -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

0 comments on commit 94596da

Please sign in to comment.