Permalink
Browse files

Cucumber was trying to execute steps on dnsimple.com main website ins…

…tead of given site.
  • Loading branch information...
1 parent 027d6d8 commit dbcf8642a261d9114f228f86c23a0164865ec40b @weppos weppos committed Sep 20, 2012
View
@@ -0,0 +1,7 @@
+# Changelog
+
+## master
+
+- CHANGED: Deprecated Dnsimple::Client.base_uri= in favor of Dnsimple::Client.host=.
+
+- FIXED: Cucumber was trying to execute steps on dnsimple.com main website instead of given site.
View
@@ -97,7 +97,7 @@ def usage
global = OptionParser.new do |opts|
opts.on("-s", "--site [ARG]") do |site|
- DNSimple::Client.base_uri = site
+ DNSimple::Client.site_uri = site
end
opts.on("-u", "--username [ARG]") do |username|
DNSimple::Client.username = username
@@ -4,5 +4,5 @@
credentials = YAML.load(File.new(File.expand_path(path)))
credentials['username'].should_not be_nil, "You must specify a username in your #{path} file"
credentials['password'].should_not be_nil, "You must specify a password in your #{path} file"
- credentials['site'].should_not be_nil, "For cucumber to run, you must specify a site in your #{path} file"
+ (credentials['host'] || credentials['site']).should_not be_nil, "For cucumber to run, you must specify a host or site in your #{path} file"
end
View
@@ -2,7 +2,21 @@
require 'httparty'
module DNSimple
+
BLANK_REGEX = /\S+/
+
+ # Echoes a deprecation warning message.
+ #
+ # @param [String] message The message to display.
+ # @return [void]
+ #
+ # @api internal
+ # @private
+ def self.deprecate(message = nil)
+ message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
+ warn("DEPRECATION WARNING: #{message}")
+ end
+
end
require 'dnsimple/base'
View
@@ -1,7 +1,7 @@
require 'yaml'
module DNSimple
-
+
class CommandNotFound < RuntimeError
end
@@ -36,7 +36,7 @@ def commands
'delete' => DNSimple::Commands::DeleteDomain,
'clear' => DNSimple::Commands::ClearDomain,
'apply' => DNSimple::Commands::ApplyTemplate,
-
+
'record:describe' => DNSimple::Commands::DescribeRecord,
'record:create' => DNSimple::Commands::CreateRecord,
'record:list' => DNSimple::Commands::ListRecords,
@@ -1,4 +1,5 @@
class DNSimple::Client
+
def self.debug?
@debug
end
@@ -31,13 +32,30 @@ def self.api_token=(api_token)
@api_token = api_token
end
+ # Sets the @host value.
+ #
+ # @returns [String] The host value.
+ def self.host
+ @host
+ end
+
+ # Gets the @host value.
+ #
+ # @param [String] value The host value.
+ def self.host=(value)
+ @host = value
+ end
+
+ # Gets the qualified API base uri.
+ #
+ # @return [String] The qualified API base uri.
def self.base_uri
- @base_uri ||= "https://dnsimple.com/"
+ "https://#{(host || "dnsimple.com")}/"
end
- def self.base_uri=(base_uri)
- base_uri += '/' if base_uri && base_uri[/\/$/].nil?
- @base_uri = base_uri
+ def self.base_uri=(value)
+ DNSimple.deprecate("Dnsimple::Client.base_uri is deprecated. Please use Dnsimple::Client.host and provide a simple host.")
+ self.host = URI.parse(value).host
end
def self.http_proxy
@@ -59,10 +77,11 @@ def self.config_path
def self.load_credentials(path = config_path)
begin
credentials = YAML.load(File.new(File.expand_path(path)))
- self.username ||= credentials['username']
- self.password ||= credentials['password']
- self.api_token ||= credentials['api_token']
- self.base_uri ||= credentials['site']
+ self.username ||= credentials['username']
+ self.password ||= credentials['password']
+ self.api_token ||= credentials['api_token']
+ self.base_uri = credentials['site'] if credentials['site']
+ self.host = credentials['host'] if credentials['host']
self.http_proxy = { :addr => credentials['proxy_addr'], :port => credentials['proxy_port'] }
@credentials_loaded = true
puts "Credentials loaded from #{path}"
@@ -1,15 +1,21 @@
require 'spec_helper'
describe DNSimple::Client do
+
+ let(:klass) { described_class }
+
before :each do
- @username, @password, @api_token = DNSimple::Client.username,
- DNSimple::Client.password, DNSimple::Client.api_token
+ @_username = DNSimple::Client.username
+ @_password = DNSimple::Client.password
+ @_api_token = DNSimple::Client.api_token
+ @_host = DNSimple::Client.host
end
- after :each do
- DNSimple::Client.username = @username
- DNSimple::Client.password = @password
- DNSimple::Client.api_token = @api_token
+ after do
+ DNSimple::Client.username = @_username
+ DNSimple::Client.password = @_password
+ DNSimple::Client.api_token = @_api_token
+ DNSimple::Client.host = @_host
end
[:get, :post, :put, :delete].each do |method|
@@ -55,4 +61,22 @@
end
end
end
+
+
+ describe ".base_uri" do
+ it "returns the qualified API uri" do
+ klass.host = "api.dnsimple.com"
+ klass.base_uri = "https://api.dnsimple.com/"
+ end
+ end
+
+ describe ".base_uri=" do
+ it "sets the host" do
+ klass.base_uri = "http://api1.dnsimple.com/"
+ klass.host.should == "api1.dnsimple.com"
+ klass.base_uri = "http://api2.dnsimple.com"
+ klass.host.should == "api2.dnsimple.com"
+ end
+ end
+
end
View
@@ -20,6 +20,7 @@
config = YAML.load_file(File.expand_path(ENV['DNSIMPLE_TEST_CONFIG'] || '~/.dnsimple.test'))
-DNSimple::Client.base_uri = config['site'] # Example: https://test.dnsimple.com/
-DNSimple::Client.username = config['username'] # Example: testusername
-DNSimple::Client.password = config['password'] # Example: testpassword
+DNSimple::Client.base_uri = config['site'] if config['site'] # Example: https://test.dnsimple.com/
+DNSimple::Client.host = config['host'] if config['host'] # Example: test.dnsimple.com
+DNSimple::Client.username = config['username'] # Example: testusername
+DNSimple::Client.password = config['password'] # Example: testpassword

0 comments on commit dbcf864

Please sign in to comment.