Created
August 18, 2010 23:29
-
-
Save erikh/536523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..034ff4b 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,30 @@ 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_default | |
+ @response = "Successfully registered gem: freewill (1.0.0)" | |
+ @fetcher.data["https://rubygems.org/api/v1/gems"] = [@response, 200, 'OK'] | |
+ | |
+ send_battery | |
+ end | |
+ | |
+ def test_sending_gem_host | |
+ @response = "Successfully registered gem: freewill (1.0.0)" | |
+ @fetcher.data["https://gemcutter.org/api/v1/gems"] = [@response, 200, 'OK'] | |
+ @cmd.options[:host] = "https://gemcutter.org" | |
+ | |
+ send_battery | |
+ end | |
+ | |
+ def test_sending_gem_ENV | |
+ @response = "Successfully registered gem: freewill (1.0.0)" | |
+ @fetcher.data["https://gemcutter.org/api/v1/gems"] = [@response, 200, 'OK'] | |
+ 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