Skip to content

Instantly share code, notes, and snippets.

@erikh
Created August 18, 2010 23:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save erikh/536509 to your computer and use it in GitHub Desktop.
diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb
index cabcd3d..0c1ec10 100644
--- a/lib/rubygems/commands/push_command.rb
+++ b/lib/rubygems/commands/push_command.rb
@@ -21,6 +21,13 @@ class Gem::Commands::PushCommand < Gem::Command
def initialize
super 'push', description
add_proxy_option
+
+ add_option(
+ '--host HOST',
+ 'Push to another gemcutter-compatible host'
+ ) do |value, options|
+ options[:host] = value
+ end
end
def execute
@@ -31,7 +38,11 @@ class Gem::Commands::PushCommand < Gem::Command
def send_gem name
say "Pushing gem to RubyGems.org..."
- response = rubygems_api_request :post, "api/v1/gems" do |request|
+ args = [:post, "api/v1/gems"]
+
+ args << options[:host] if options[:host]
+
+ response = rubygems_api_request(*args) do |request|
request.body = Gem.read_binary name
request.add_field "Content-Length", request.body.size
request.add_field "Content-Type", "application/octet-stream"
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 225bd70..e7ccf17 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -23,8 +23,8 @@ module Gem::GemcutterUtilities
end
end
- def rubygems_api_request(method, path, &block)
- host = ENV['RUBYGEMS_HOST'] || 'https://rubygems.org'
+ def rubygems_api_request(method, path, host='https://rubygems.org', &block)
+ host = ENV['RUBYGEMS_HOST'] if ENV.has_key?('RUBYGEMS_HOST')
uri = URI.parse "#{host}/#{path}"
request_method = Net::HTTP.const_get method.to_s.capitalize
diff --git a/test/test_gem_commands_push_command.rb b/test/test_gem_commands_push_command.rb
index bbe64e3..d5d4844 100644
--- a/test/test_gem_commands_push_command.rb
+++ b/test/test_gem_commands_push_command.rb
@@ -18,10 +18,7 @@ class TestGemCommandsPushCommand < RubyGemTestCase
@cmd = Gem::Commands::PushCommand.new
end
- def test_sending_gem
- response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["https://rubygems.org/api/v1/gems"] = [response, 200, 'OK']
-
+ def send_battery
use_ui @ui do
@cmd.send_gem(@path)
end
@@ -34,7 +31,24 @@ class TestGemCommandsPushCommand < RubyGemTestCase
assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"]
assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
- assert_match response, @ui.output
+ assert_match @response, @ui.output
+ end
+
+ def test_sending_gem
+ @response = "Successfully registered gem: freewill (1.0.0)"
+ @fetcher.data["https://rubygems.org/api/v1/gems"] = [@response, 200, 'OK']
+ @fetcher.data["https://gemcutter.org/api/v1/gems"] = [@response, 200, 'OK']
+
+ send_battery
+
+ @cmd.options[:host] = "https://gemcutter.org"
+
+ send_battery
+
+ @cmd.options.delete(:host)
+ ENV["RUBYGEMS_HOST"] = "https://gemcutter.org"
+
+ send_battery
end
def test_raises_error_with_no_arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment