diff --git a/Rakefile b/Rakefile index 9d5d327ae87..1f1fe057644 100644 --- a/Rakefile +++ b/Rakefile @@ -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..." diff --git a/app/cutter.rb b/app/cutter.rb index 76f92fab69d..107eb767b75 100644 --- a/app/cutter.rb +++ b/app/cutter.rb @@ -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| diff --git a/apps/hostess/config.ru b/apps/hostess/config.ru new file mode 100644 index 00000000000..8bd0356472c --- /dev/null +++ b/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 diff --git a/apps/hostess/hostess.rb b/apps/hostess/hostess.rb new file mode 100644 index 00000000000..552eca8771f --- /dev/null +++ b/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 diff --git a/apps/hostess/views/index.haml b/apps/hostess/views/index.haml new file mode 100644 index 00000000000..3825225e5fb --- /dev/null +++ b/apps/hostess/views/index.haml @@ -0,0 +1 @@ +%h1 gems.gemcutter.org diff --git a/spec/app_spec.rb b/spec/app_spec.rb index 8f6f857aa44..758f93e863b 100644 --- a/spec/app_spec.rb +++ b/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 "/" diff --git a/spec/cutter_spec.rb b/spec/cutter_spec.rb index 8f8222d7ae7..16595534460 100644 --- a/spec/cutter_spec.rb +++ b/spec/cutter_spec.rb @@ -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') diff --git a/spec/hostess_spec.rb b/spec/hostess_spec.rb new file mode 100644 index 00000000000..301592053ac --- /dev/null +++ b/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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bd1fd321e49..12520f067a3 100644 --- a/spec/spec_helper.rb +++ b/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' @@ -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