Hi! I cleaned up your code for you! #14

Closed
wants to merge 1 commit into
from
View
@@ -1,6 +1,6 @@
module Rakismet
module Model
-
+
def self.included(base)
base.class_eval do
attr_accessor :akismet_response
@@ -10,7 +10,7 @@ class << self; attr_accessor :akismet_attrs; end
self.rakismet_attrs
end
end
-
+
module ClassMethods
def rakismet_attrs(args={})
self.akismet_attrs ||= {}
@@ -27,7 +27,7 @@ def rakismet_attrs(args={})
end
end
end
-
+
module InstanceMethods
def spam?
if instance_variable_defined? :@_spam
@@ -75,6 +75,6 @@ def akismet_data
akismet
end
end
-
+
end
end
View
@@ -9,7 +9,7 @@
Rakismet.url = 'test.localhost'
Rakismet.host = 'endpoint.localhost'
end
-
+
describe "proxy host" do
it "should have proxy host and port as nil by default" do
Rakismet.proxy_host.should be_nil
@@ -33,21 +33,21 @@
lambda { Rakismet.send(:validate_config) }.should raise_error(Rakismet::Undefined)
end
end
-
+
describe ".validate_key" do
before (:each) do
@proxy = mock(Net::HTTP)
Net::HTTP.stub!(:Proxy).and_return(@proxy)
end
-
+
it "should use proxy host and port" do
Rakismet.proxy_host = 'proxy_host'
Rakismet.proxy_port = 'proxy_port'
@proxy.stub!(:start).and_return([nil, 'valid'])
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
Rakismet.validate_key
end
-
+
it "should set @@valid_key = true if key is valid" do
@proxy.stub!(:start).and_return([nil, 'valid'])
Rakismet.validate_key
@@ -67,34 +67,34 @@
Rakismet.validate_key
end
end
-
+
describe ".akismet_call" do
before do
@proxy = mock(Net::HTTP)
Net::HTTP.stub!(:Proxy).and_return(@proxy)
@proxy.stub(:start).and_yield(http)
end
-
+
it "should use proxy host and port" do
Rakismet.proxy_host = 'proxy_host'
Rakismet.proxy_port = 'proxy_port'
@proxy.stub!(:start).and_return([nil, 'valid'])
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
Rakismet.send(:akismet_call, 'bogus-function')
end
-
+
it "should build url with API key for the correct host" do
host = 'api.antispam.typepad.com'
Rakismet.host = host
@proxy.should_receive(:start).with("#{Rakismet.key}.#{host}")
Rakismet.send(:akismet_call, 'bogus-function')
end
-
+
it "should post data to named function" do
http.should_receive(:post).with('/1.1/bogus-function', %r(foo=#{CGI.escape 'escape//this'}), Rakismet.headers)
Rakismet.send(:akismet_call, 'bogus-function', { :foo => 'escape//this' })
end
-
+
it "should return response.body" do
Rakismet.send(:akismet_call, 'bogus-function').should eql('akismet response')
end
@@ -105,5 +105,5 @@
}.should_not raise_error(NoMethodError)
end
end
-
+
end