Skip to content

Commit

Permalink
Allow for custom hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
nbibler committed May 13, 2010
1 parent c6b6cb1 commit 394a7c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
17 changes: 16 additions & 1 deletion lib/geo_certs.rb
Expand Up @@ -49,8 +49,23 @@ def self.sandbox?
@sandbox
end

def self.sandbox
@sandbox
end

def self.host=(value) #:nodoc:
@_host = value
end

def self.host
sandbox? ? 'sandbox.geocerts.com' : 'www.geocerts.com'
case
when @_host
@_host
when sandbox?
'sandbox.geocerts.com'
else
'www.geocerts.com'
end
end

end
Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Expand Up @@ -65,4 +65,12 @@ def assert_responds_without_exception(exception, *error_codes, &block)
end
end

def setting(object, method, options = {})
original_value = object.send(method)
object.send("#{method}=", options[:to])
yield if block_given?
ensure
object.send("#{method}=", options.has_key?(:back) ? options[:back] : original_value)
end

end
20 changes: 16 additions & 4 deletions test/units/geo_certs_test.rb
Expand Up @@ -5,13 +5,25 @@ class GeoCertsTest < Test::Unit::TestCase
context 'GeoCerts' do

should 'use the sandbox host' do
GeoCerts.sandbox = true
assert_equal('sandbox.geocerts.com', GeoCerts.host)
setting(GeoCerts, :sandbox, :to => true) do
assert_equal('sandbox.geocerts.com', GeoCerts.host)
end
end

should 'use the production host' do
GeoCerts.sandbox = false
assert_equal('www.geocerts.com', GeoCerts.host)
setting(GeoCerts, :sandbox, :to => false) do
assert_equal('www.geocerts.com', GeoCerts.host)
end
end

should 'use the given host' do
setting(GeoCerts, :host, :to => 'test.com', :back => nil) do
assert_equal('test.com', GeoCerts.host)
end

setting(GeoCerts, :host, :to => 'test.com:8000', :back => nil) do
assert_equal('test.com:8000', GeoCerts.host)
end
end

end
Expand Down

0 comments on commit 394a7c6

Please sign in to comment.