From 3fcdd8e80e2593f2e27a57d307c4b88bf1f0ed97 Mon Sep 17 00:00:00 2001 From: Ashley Ellis Pierce Date: Wed, 12 Jan 2022 13:01:01 -0500 Subject: [PATCH] WIP: Pushing multiple gems This is working when trying locally but the tests are still wip --- lib/rubygems/commands/push_command.rb | 35 ++++++++++--------- .../test_gem_commands_push_command.rb | 32 +++++++++++++++++ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 1864b4b09578..43eccd0e4f41 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -48,22 +48,25 @@ def initialize end def execute - gem_name = get_one_gem_name - default_gem_server, push_host = get_hosts_for(gem_name) - - @host = if @user_defined_host - options[:host] - elsif default_gem_server - default_gem_server - elsif push_host - push_host - else - options[:host] - end - - sign_in @host, scope: get_push_scope - - send_gem(gem_name) + gem_names = get_all_gem_names + + default_gem_server, push_host = get_hosts_for(gem_names.first) + + @host = if @user_defined_host + options[:host] + elsif default_gem_server + default_gem_server + elsif push_host + push_host + else + options[:host] + end + + sign_in @host, scope: get_push_scope + + gem_names.each do |gem_name| + send_gem(gem_name) + end end def send_gem(name) diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index fa3968ffcec3..f69e325b3212 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -175,6 +175,38 @@ def test_sending_gem send_battery end + def test_sending_multiple_gems + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + + spec_1, path_1 = util_gem "freebird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = @host + end + + spec_1, path_2 = util_gem "cagedbird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = @host + end + + @cmd.options[:args] = [path_1, path_2] + use_ui @ui do + @cmd.instance_variable_set :@host, @host + @cmd.execute + end + + assert_match %r{Pushing gem to #{@host}...}, @ui.output + assert_equal Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.read_binary(path_1), @fetcher.last_request.body + assert_equal File.size(path_1), @fetcher.last_request["Content-Length"].to_i + + assert_equal Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.read_binary(path_2), @fetcher.last_request.body + assert_equal File.size(path_2), @fetcher.last_request["Content-Length"].to_i + assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"] + assert_equal @api_key, @fetcher.last_request["Authorization"] + + assert_match @response, @ui.output + end + def test_sending_gem_to_allowed_push_host @host = "http://privategemserver.example"