Permalink
Browse files

added tests, good thing too

  • Loading branch information...
1 parent f7e0b2c commit 1cd4f7da605f3aa7a106671198ab6b75fe31ec0d @gamache gamache committed Sep 13, 2010
Showing with 32 additions and 4 deletions.
  1. +12 −4 lib/clicky-api.rb
  2. +20 −0 test/test-suite.rb
View
16 lib/clicky-api.rb
@@ -27,10 +27,17 @@ class ClickyAPI
## load_config_file! is called from the Rails initializer. This code might
## need to be re-run if you're using the "development" environment, and
## the file gets reloaded. Gross.
- def self.load_config_file!(file="#{Rails.root}/config/clicky-api.yml")
+ def self.load_config_file!(file=nil)
@@set_params = {}
+ if file.nil?
+ if defined?(Rails)
+ file = "#{Rails.root}/config/clicky-api.yml"
+ else
+ return nil ## perhaps this should throw here?
+ end
+ end
config = YAML.load_file(file) || {}
- ClickyAPI.set!(config)
+ ClickyAPI.set_params!(config)
end
## the 'set_params!' method is used to set params persistently, class-wide
@@ -40,8 +47,9 @@ def self.set_params!(param_hash={})
end
## get_params returns the hash of params set by #set_params!
- def get_params
- {}.merge(@@set_params)
+ ## using Hash#merge to prevent shared structure
+ def self.get_params
+ {}.merge(@@set_params||{})
end
## the 'stats' method is used to obtain results. I wanted to call it
View
20 test/test-suite.rb
@@ -0,0 +1,20 @@
+$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
+require 'test/unit'
+
+class TestClickyAPI < Test::Unit::TestCase
+ def setup
+ require 'clicky-api'
+ assert ClickyAPI.set_params!(:foo => 'bar', :baz => 'quux')
+ end
+
+ def test_get_params
+ assert params = ClickyAPI.get_params
+ assert params.instance_of?(Hash)
+ assert params.include?('foo') ## ensure that param keys are stringified
+ end
+
+ def test_request
+ assert response = ClickyAPI.stats
+ assert response.has_key?('status')
+ end
+end

0 comments on commit 1cd4f7d

Please sign in to comment.