diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 1864b4b09578..79570cad94a5 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -48,8 +48,16 @@ def initialize end def execute - gem_name = get_one_gem_name - default_gem_server, push_host = get_hosts_for(gem_name) + gem_names = get_all_gem_names + + hosts_from_gems = gem_names.map do |gem_name| + get_hosts_for(gem_name) + end + too_many_hosts = hosts_from_gems.uniq.count > 1 + + raise "All gems must have the same host" if too_many_hosts + + default_gem_server, push_host = hosts_from_gems.first @host = if @user_defined_host options[:host] @@ -63,7 +71,9 @@ def execute sign_in @host, scope: get_push_scope - send_gem(gem_name) + 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..b8fbc9f5d745 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -175,6 +175,51 @@ def test_sending_gem send_battery end + def test_sending_multiple_gems_to_same_host + @first_response = "Successfully registered gem: freebird (1.0.0)" + @second_response = "Successfully registered gem: cagedbird (1.0.0)" + @fetcher.data["#{@host}/api/v1/gems"] = [[@first_response, 200, 'OK'], [@second_response, 200, 'OK']] + + spec_1, path_1 = util_gem "freebird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = @host + end + + spec_2, 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{Successfully registered gem: freebird}, @ui.output + assert_match %r{Successfully registered gem: cagedbird}, @ui.output + end + + def test_sending_multiple_gems_to_different_hosts + @host = "http://privategemserver.example" + + @first_response = "Successfully registered gem: freebird (1.0.0)" + @second_response = "Successfully registered gem: cagedbird (1.0.0)" + @fetcher.data["#{@host}/api/v1/gems"] = [[@first_response, 200, 'OK'], [@second_response, 200, 'OK']] + + spec_1, path_1 = util_gem "freebird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = @host + end + + spec_2, path_2 = util_gem "cagedbird", "1.0.1" do |spec| + spec.metadata['allowed_push_host'] = "https://rubygems.example" + end + @cmd.options[:args] = [path_1, path_2] + assert_raises "All gems must have the same host" do + use_ui @ui do + @cmd.instance_variable_set :@host, @host + @cmd.execute + end + end + end + def test_sending_gem_to_allowed_push_host @host = "http://privategemserver.example"