Skip to content

Commit

Permalink
WIP: Pushing multiple gems
Browse files Browse the repository at this point in the history
This is working when trying locally but the tests are still wip
  • Loading branch information
aellispierce committed Jan 12, 2022
1 parent 793ad95 commit 3fcdd8e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lib/rubygems/commands/push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions test/rubygems/test_gem_commands_push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3fcdd8e

Please sign in to comment.