Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use `present?` when checking config and params #4

Merged
merged 1 commit into from

1 participant

@balexand
Owner

No description provided.

@balexand balexand merged commit ae6a276 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 6 deletions.
  1. +5 −3 lib/spamster.rb
  2. +1 −0  spamster.gemspec
  3. +3 −3 spec/spamster_spec.rb
View
8 lib/spamster.rb
@@ -1,3 +1,5 @@
+require 'active_support'
+require 'active_support/core_ext'
require 'net/http'
require 'spamster/version'
require 'uri'
@@ -32,8 +34,8 @@ def ham!(params)
private
def perform_post(url, params)
- raise "'Spamster.blog' must be set" unless blog
- raise "'Spamster.key' must be set" unless key
+ raise "'Spamster.blog' must be set" unless blog.present?
+ raise "'Spamster.key' must be set" unless key.present?
uri = URI(url)
@@ -54,7 +56,7 @@ def perform_post(url, params)
def perform_spam_post(method, params = {})
params = params.merge(:blog => blog)
[:blog, :user_agent, :user_ip].each do |param|
- raise "required param #{param.inspect} is missing" unless params[param]
+ raise "required param #{param.inspect} is missing" unless params[param].present?
end
response = perform_post("http://#{key}.rest.akismet.com/1.1/#{method}", params)
View
1  spamster.gemspec
@@ -19,5 +19,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "rspec"
gem.add_development_dependency "webmock"
+ gem.add_runtime_dependency "activesupport"
gem.add_runtime_dependency "jruby-openssl" if RUBY_PLATFORM == "java"
end
View
6 spec/spamster_spec.rb
@@ -12,14 +12,14 @@
end
it "should raise exception if :blog is not configured" do
- Spamster.blog = nil
+ Spamster.blog = ""
expect do
Spamster.send(:perform_post, "http://123abc.rest.akismet.com/1.1/comment-check", {})
end.to raise_exception{ |e| e.message.should == "'Spamster.blog' must be set" }
end
it "should raise exception if :key is not configured" do
- Spamster.key = nil
+ Spamster.key = " \n"
expect do
Spamster.send(:perform_post, "http://123abc.rest.akismet.com/1.1/comment-check", {})
end.to raise_exception{ |e| e.message.should == "'Spamster.key' must be set" }
@@ -82,7 +82,7 @@ def self.version
it "should raise exception if required param missing" do
expect do
- Spamster.spam?(:user_ip => "222.222.222.222")
+ Spamster.spam?(:user_agent => " ", :user_ip => "222.222.222.222")
end.to raise_exception{ |e| e.message.should == "required param :user_agent is missing" }
expect do
Something went wrong with that request. Please try again.