Skip to content

Commit

Permalink
Fix #461: Add --host option to owner command
Browse files Browse the repository at this point in the history
  • Loading branch information
hltbra committed Feb 23, 2013
1 parent c6ac998 commit 0e3ec7c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rubygems/commands/owner_command.rb
Expand Up @@ -31,9 +31,15 @@ def initialize
add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
options[:remove] << value
end

add_option '-h', '--host HOST', 'Use another gemcutter-compatible host' do |value, options|
options[:host] = value
end
end

def execute
@host = options[:host]

sign_in
name = get_one_gem_name

Expand Down
49 changes: 49 additions & 0 deletions test/rubygems/test_gem_commands_owner_command.rb
Expand Up @@ -6,6 +6,7 @@ class TestGemCommandsOwnerCommand < Gem::TestCase
def setup
super

ENV["RUBYGEMS_HOST"] = nil
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250"
Expand Down Expand Up @@ -34,6 +35,36 @@ def test_show_owners
assert_match %r{- user2@example.com}, @ui.output
end

def test_show_owners_setting_up_host_through_env_var
response = "- email: user1@example.com\n"
host = "http://rubygems.example"
ENV["RUBYGEMS_HOST"] = host

@fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']

use_ui @ui do
@cmd.show_owners("freewill")
end

assert_match %r{Owners for gem: freewill}, @ui.output
assert_match %r{- user1@example.com}, @ui.output
end

def test_show_owners_setting_up_host
response = "- email: user1@example.com\n"
host = "http://rubygems.example"
@cmd.host = host

@fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']

use_ui @ui do
@cmd.show_owners("freewill")
end

assert_match %r{Owners for gem: freewill}, @ui.output
assert_match %r{- user1@example.com}, @ui.output
end

def test_show_owners_denied
response = "You don't have permission to push to this gem"
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden']
Expand Down Expand Up @@ -87,6 +118,24 @@ def test_add_owners_denied
assert_match response, @ui.output
end

def test_add_owner_with_host_option_through_execute
host = "http://rubygems.example"
add_owner_response = "Owner added successfully."
show_owners_response = "- email: user1@example.com\n"
@fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, 'OK']
@fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, 'OK']

@cmd.handle_options %W[--host #{host} --add user-new1@example.com freewill]

use_ui @ui do
@cmd.execute
end

assert_match add_owner_response, @ui.output
assert_match %r{Owners for gem: freewill}, @ui.output
assert_match %r{- user1@example.com}, @ui.output
end

def test_add_owners_key
response = "Owner added successfully."
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
Expand Down

0 comments on commit 0e3ec7c

Please sign in to comment.