Permalink
Browse files

Remove Gem.configuration.api_keys= setter

  • Loading branch information...
1 parent 7115d74 commit 44af96b2ba764f461282a17d538a8bb7d757bf1f @joshfrench joshfrench committed Dec 28, 2010
@@ -221,20 +221,6 @@ def rubygems_api_key=(api_key)
@rubygems_api_key = api_key
end
- def api_keys=(keys)
- keys.merge(:rubygems_api_key => @rubygems_api_key) if defined? @rubygems_api_key
- dirname = File.dirname(credentials_path)
- Dir.mkdir(dirname) unless File.exists?(dirname)
-
- require 'yaml'
-
- File.open(credentials_path, 'w') do |f|
- f.write keys.to_yaml
- end
-
- @api_keys = keys
- end
-
def load_file(filename)
return {} unless filename and File.exists?(filename)
begin
@@ -50,7 +50,10 @@ def test_show_owners_denied
def test_show_owners_key
response = "- email: user1@example.com\n"
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']
- Gem.configuration.api_keys = {:other => '701229f217cdf23b1344c7b4b54ca97'}
+ File.open Gem.configuration.credentials_path, 'a' do |f|
+ f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ end
+ Gem.configuration.load_api_keys
@cmd.handle_options %w(-k other)
@cmd.show_owners('freewill')
@@ -89,7 +92,10 @@ def test_add_owners_denied
def test_add_owners_key
response = "Owner added successfully."
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
- Gem.configuration.api_keys = {:other => '701229f217cdf23b1344c7b4b54ca97'}
+ File.open Gem.configuration.credentials_path, 'a' do |f|
+ f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ end
+ Gem.configuration.load_api_keys
@cmd.handle_options %w(-k other)
@cmd.add_owners('freewill', ['user-new1@example.com'])
@@ -128,7 +134,10 @@ def test_remove_owners_denied
def test_remove_owners_key
response = "Owner removed successfully."
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK']
- Gem.configuration.api_keys = {:other => '701229f217cdf23b1344c7b4b54ca97'}
+ File.open Gem.configuration.credentials_path, 'a' do |f|
+ f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ end
+ Gem.configuration.load_api_keys
@cmd.handle_options %w(-k other)
@cmd.remove_owners('freewill', ['user-remove1@example.com'])
@@ -80,7 +80,10 @@ def test_sending_gem_denied
def test_sending_gem_key
@response = "Successfully registered gem: freewill (1.0.0)"
@fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, "OK"]
- Gem.configuration.api_keys = {:other => '701229f217cdf23b1344c7b4b54ca97'}
+ File.open Gem.configuration.credentials_path, 'a' do |f|
+ f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
+ end
+ Gem.configuration.load_api_keys
@cmd.handle_options %w(-k other)
@cmd.send_gem(@path)
@@ -291,22 +291,6 @@ def test_load_api_keys_from_config
:other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}, @cfg.api_keys)
end
- def test_write_api_keys_to_config
- temp_cred = File.join Gem.user_home, '.gem', 'credentials'
- FileUtils.mkdir File.dirname(temp_cred)
-
- api_keys = {:rubygems => '701229f217cdf23b1344c7b4b54ca97',
- :other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}
-
- util_config_file
- @cfg.api_keys = api_keys
-
- @cfg.load_api_keys
- assert_equal '701229f217cdf23b1344c7b4b54ca97', @cfg.api_keys[:rubygems]
- assert_equal 'a5fdbb6ba150cbb83aad2bb2fede64c', @cfg.api_keys[:other]
- end
-
-
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
@@ -100,7 +100,13 @@ def util_sign_in response, host = nil
end
def test_verify_api_key
- Gem.configuration.api_keys = {:other => 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'}
+ keys = {:other => 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'}
+ FileUtils.mkdir_p File.dirname(Gem.configuration.credentials_path)
+ File.open Gem.configuration.credentials_path, 'w' do |f|
+ f.write keys.to_yaml
+ end
+ Gem.configuration.load_api_keys
+
assert_equal 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903', @cmd.verify_api_key(:other)
end

0 comments on commit 44af96b

Please sign in to comment.