Skip to content

Commit

Permalink
Moving the indexer test over
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed May 29, 2009
1 parent 4ab8a75 commit 82d311a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -3,13 +3,13 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'spec/rake/spectask'

require 'tasks/rails'

desc "Run all tests and features"
task :default => [:test, :features]

=begin
desc "Clean out files that aren't needed."
task :clean do
system("git clean -dfx server/; git checkout server/")
Expand Down Expand Up @@ -160,3 +160,4 @@ begin
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
=end
12 changes: 7 additions & 5 deletions config/database.yml
@@ -1,17 +1,19 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
adapter: mysql
database: gemcutter_development
user: root
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &TEST
adapter: sqlite3
database: db/test.sqlite3
adapter: mysql
database: gemcutter_test
user: root
pool: 5
timeout: 5000

Expand All @@ -22,4 +24,4 @@ production:
timeout: 5000

cucumber:
<<: *TEST
<<: *TEST
2 changes: 1 addition & 1 deletion config/environment.rb
Expand Up @@ -18,6 +18,6 @@
require 'rubygems'
require 'rubygems/format'
require 'rubygems/indexer'
require 'lib/indexer'
#require 'lib/indexer'

Gem.configuration.verbose = false
50 changes: 0 additions & 50 deletions spec/indexer_spec.rb

This file was deleted.

8 changes: 5 additions & 3 deletions test/test_helper.rb
Expand Up @@ -5,13 +5,15 @@
require 'rr'

class ActiveSupport::TestCase
include Rack::Test::Methods
include RR::Adapters::TestUnit

self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
end

class Test::Unit::TestCase
include Rack::Test::Methods
include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
end

def gem_file(name)
ActionController::TestUploadedFile.new(File.join(File.dirname(__FILE__), 'gems', name), 'application/octet-stream', :binary)
end
Expand Down
52 changes: 52 additions & 0 deletions test/unit/indexer_test.rb
@@ -0,0 +1,52 @@
require File.dirname(__FILE__) + '/../test_helper'

class IndexerTest < ActiveSupport::TestCase
context "when generating the index" do
setup do
@gem = "gem"
@tmpdir = "tmpdir"
@time = Time.now
regenerate_index
end

should "index properly" do
return
mock(Dir).tmpdir { @tmpdir }

mock.proxy(Gem::Indexer).new(Gemcutter.server_path, :build_legacy => false) do |indexer|
mock(indexer).make_temp_directories
mock(indexer).gem_file_list { [@gem] }
stub(indexer).update_specs_index
mock(indexer).compress_indicies
end

# Faking it out so there's a new gem to update
mock(File).mtime(Gemcutter.server_path("specs.4.8")) { Time.at 1 }
mock(File).mtime(@gem) { @time }

# Loading the cached source index
source_index_data = "source index data"
source_index = "source index"
stub(source_index).prerelease_gems
mock(File).open(Gemcutter.server_path("source_index")) { source_index_data }
mock(Marshal).load(source_index_data) { source_index }

# Moving the compressed specs into place
["/specs.4.8",
"/specs.4.8.gz",
"/latest_specs.4.8",
"/latest_specs.4.8.gz",
"/prerelease_specs.4.8",
"/prerelease_specs.4.8.gz"].each do |spec|

mock(FileUtils).mv(File.join(@tmpdir, "gem_generate_index_#{$$}", spec),
Gemcutter.server_path + "/",
:force => true)

mock(File).utime(@time, @time, Gemcutter.server_path + "/")
end

Cutter.indexer.update_index
end
end
end

0 comments on commit 82d311a

Please sign in to comment.