diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-22 02:52:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-22 02:52:35 +0000 |
commit | b551e8c8b36766651be4e782e09e3b02e7d14a10 (patch) | |
tree | e164a1ef908bd4451568abf05b688f1593915b81 /test/rubygems/test_gem_commands_owner_command.rb | |
parent | 65544f575b25b18dc27f9364f973556ddb48538f (diff) | |
download | ruby-b551e8c8b36766651be4e782e09e3b02e7d14a10.tar.gz |
* lib/rubygems: update to 1.3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_commands_owner_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_owner_command.rb | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb new file mode 100644 index 0000000000..fa4281c6a7 --- /dev/null +++ b/test/rubygems/test_gem_commands_owner_command.rb @@ -0,0 +1,105 @@ +require_relative 'gemutilities' +require 'rubygems/commands/owner_command' + +class TestGemCommandsOwnerCommand < RubyGemTestCase + + def setup + super + + @fetcher = Gem::FakeFetcher.new + Gem::RemoteFetcher.fetcher = @fetcher + Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250" + + @cmd = Gem::Commands::OwnerCommand.new + end + + def test_show_owners + response = <<EOF +--- +- email: user1@example.com +- email: user2@example.com +EOF + + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK'] + + use_ui @ui do + @cmd.show_owners("freewill") + end + + assert_equal Net::HTTP::Get, @fetcher.last_request.class + assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"] + + assert_match %r{Owners for gem: freewill}, @ui.output + assert_match %r{- user1@example.com}, @ui.output + assert_match %r{- user2@example.com}, @ui.output + end + + def test_show_owners_denied + response = "You don't have permission to push to this gem" + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden'] + + assert_raises MockGemUi::TermError do + use_ui @ui do + @cmd.show_owners("freewill") + end + end + + assert_match response, @ui.output + end + + def test_add_owners + response = "Owner added successfully." + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] + + use_ui @ui do + @cmd.add_owners("freewill", ["user-new1@example.com"]) + end + + assert_equal Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"] + assert_equal "email=user-new1%40example.com", @fetcher.last_request.body + + assert_match response, @ui.output + end + + def test_add_owners_denied + response = "You don't have permission to push to this gem" + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden'] + + assert_raises MockGemUi::TermError do + use_ui @ui do + @cmd.add_owners("freewill", ["user-new1@example.com"]) + end + end + + assert_match response, @ui.output + end + + def test_remove_owners + response = "Owner removed successfully." + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] + + use_ui @ui do + @cmd.remove_owners("freewill", ["user-remove1@example.com"]) + end + + assert_equal Net::HTTP::Delete, @fetcher.last_request.class + assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"] + assert_equal "email=user-remove1%40example.com", @fetcher.last_request.body + + assert_match response, @ui.output + end + + def test_remove_owners_denied + response = "You don't have permission to push to this gem" + @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden'] + + assert_raises MockGemUi::TermError do + use_ui @ui do + @cmd.remove_owners("freewill", ["user-remove1@example.com"]) + end + end + + assert_match response, @ui.output + end +end |