Permalink
Browse files

use confiture validate! method

  • Loading branch information...
1 parent 2991618 commit 12acff4aafaed2c923f8ffceb0fbd669db429a5f @phoet committed Jul 6, 2012
Showing with 4 additions and 24 deletions.
  1. +1 −1 Gemfile.lock
  2. +1 −1 lib/asin/client.rb
  3. +1 −16 lib/asin/configuration.rb
  4. +1 −6 spec/config_spec.rb
View
@@ -12,7 +12,7 @@ GEM
specs:
addressable (2.2.8)
coderay (1.0.7)
- confiture (0.1.0)
+ confiture (0.1.2)
crack (0.3.1)
diff-lcs (1.1.3)
fuubar (0.0.6)
View
@@ -339,7 +339,7 @@ def cart(operation, params={})
end
def call(params)
- Configuration.validate_credentials!
+ Configuration.validate!
log(:debug, "calling with params=#{params}")
signed = create_signed_query_string(params)
View
@@ -41,6 +41,7 @@ module ASIN
class Configuration
include Confiture::Configuration
confiture_allowed_keys(:secret, :key, :host, :version, :associate_tag, :logger, :item_type, :cart_type, :node_type)
+ confiture_mandatory_keys(:secret, :key)
confiture_defaults({
:secret => '',
:key => '',
@@ -52,21 +53,5 @@ class Configuration
:cart_type => SimpleCart,
:node_type => SimpleNode,
})
-
- class << self
- # Checks if given credentials are valid and raises an error if not.
- #
- def validate_credentials!
- raise "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'" if blank?(:secret) || blank?(:key)
- [:host, :item_type, :cart_type, :node_type, :version, :associate_tag].each { |item| raise "nil is not a valid value for #{item}" unless self.send item }
- end
-
- # Check if a key is set
- #
- def blank?(key)
- val = self.send :key
- val.nil? || val.empty?
- end
- end
end
end
View
@@ -4,12 +4,7 @@ module ASIN
describe ASIN do
context "configuration" do
it "should fail without secret and key" do
- lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError, "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'")
- end
-
- it "should fail with configuration key set to nil" do
- @helper.configure :secret => @secret, :key => @key, :associate_tag => nil
- lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError, "nil is not a valid value for associate_tag")
+ expect { @helper.lookup 'bla' }.should raise_error(ArgumentError, "you are missing mandatory configuration options. please set [:secret, :key]")
end
it "should fail with wrong configuration key" do

0 comments on commit 12acff4

Please sign in to comment.