rakismet 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Gemfile +0 -5
- data/README.md +36 -2
- data/lib/rakismet.rb +6 -2
- data/lib/rakismet/model.rb +7 -6
- data/lib/rakismet/railtie.rb +1 -0
- data/lib/rakismet/version.rb +1 -1
- data/rakismet.gemspec +4 -3
- data/spec/models/block_params_spec.rb +1 -1
- data/spec/models/custom_params_spec.rb +4 -3
- data/spec/models/extended_params_spec.rb +1 -1
- data/spec/models/rakismet_model_spec.rb +2 -2
- data/spec/models/request_params_spec.rb +2 -2
- data/spec/models/subclass_spec.rb +2 -2
- data/spec/rakismet_middleware_spec.rb +1 -1
- data/spec/rakismet_spec.rb +23 -12
- metadata +35 -3
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,13 +20,20 @@ you'll need an API key. Head on over to http://akismet.com/signup/ and sign up
|
|
20
20
|
for a new username.
|
21
21
|
|
22
22
|
Configure the Rakismet key and the URL of your application by setting the following
|
23
|
-
in
|
23
|
+
in application.rb:
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
config.rakismet.key = 'your wordpress key'
|
27
27
|
config.rakismet.url = 'http://yourdomain.com/'
|
28
28
|
```
|
29
|
-
|
29
|
+
|
30
|
+
or an initializer, for example `config/initializers/rakismet.rb`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
YourApp::Application.config.rakismet.key = 'your wordpress key'
|
34
|
+
YourApp::Application.config.rakismet.url = 'http://yourdomain.com/'
|
35
|
+
```
|
36
|
+
|
30
37
|
If you wish to use another Akismet-compatible API provider such as TypePad's
|
31
38
|
antispam service, you'll also need to set `config.rakismet.host` to your service
|
32
39
|
provider's endpoint.
|
@@ -137,6 +144,33 @@ your app initialization:
|
|
137
144
|
config.rakismet.use_middleware = false
|
138
145
|
```
|
139
146
|
|
147
|
+
Testing
|
148
|
+
-------
|
149
|
+
|
150
|
+
Rakismet can be configued to tell Akismet that it should operate in test mode -
|
151
|
+
so Akismet will not change its behavior based on any test API calls, meaning
|
152
|
+
they will have no training effect. That means your tests can be somewhat
|
153
|
+
repeatable in the sense that one test won't influence subsequent calls.
|
154
|
+
|
155
|
+
You can configure Rakismet for test mode via application.rb:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
config.rakismet.test = false # <- default
|
159
|
+
config.rakismet.test = true
|
160
|
+
```
|
161
|
+
|
162
|
+
Or via an initializer:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
YourApp::Application.config.rakismet.test = false # <- default
|
166
|
+
YourApp::Application.config.rakismet.test = true
|
167
|
+
```
|
168
|
+
|
169
|
+
**NOTE**: When running in Rails, Rakismet will run in test mode when your Rails
|
170
|
+
environment is `test` or `development`, unless explictly configured otherwise.
|
171
|
+
Outside of Rails Rakismet defaults to test mode turned **off**.
|
172
|
+
|
173
|
+
|
140
174
|
Verifying Responses
|
141
175
|
-------------------
|
142
176
|
|
data/lib/rakismet.rb
CHANGED
@@ -13,7 +13,7 @@ module Rakismet
|
|
13
13
|
Undefined = Class.new(NameError)
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_accessor :key, :url, :host, :proxy_host, :proxy_port
|
16
|
+
attr_accessor :key, :url, :host, :proxy_host, :proxy_port, :test
|
17
17
|
|
18
18
|
def request
|
19
19
|
@request ||= Request.new
|
@@ -52,7 +52,7 @@ module Rakismet
|
|
52
52
|
|
53
53
|
def akismet_call(function, args={})
|
54
54
|
validate_config
|
55
|
-
args.merge!(:blog => Rakismet.url)
|
55
|
+
args.merge!(:blog => Rakismet.url, :is_test => Rakismet.test_mode)
|
56
56
|
akismet = URI.parse(call_url(function))
|
57
57
|
response = Net::HTTP::Proxy(proxy_host, proxy_port).start(akismet.host) do |http|
|
58
58
|
params = args.map do |k,v|
|
@@ -79,6 +79,10 @@ module Rakismet
|
|
79
79
|
raise Undefined, "Rakismet.url is not defined" if Rakismet.url.nil? || Rakismet.url.empty?
|
80
80
|
raise Undefined, "Rakismet.host is not defined" if Rakismet.host.nil? || Rakismet.host.empty?
|
81
81
|
end
|
82
|
+
|
83
|
+
def test_mode
|
84
|
+
test ? 1 : 0
|
85
|
+
end
|
82
86
|
end
|
83
87
|
|
84
88
|
end
|
data/lib/rakismet/model.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Rakismet
|
2
2
|
module Model
|
3
|
-
|
3
|
+
|
4
4
|
def self.included(base)
|
5
5
|
base.class_eval do
|
6
6
|
attr_accessor :akismet_response
|
@@ -10,11 +10,11 @@ module Rakismet
|
|
10
10
|
self.rakismet_attrs
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
module ClassMethods
|
15
15
|
def rakismet_attrs(args={})
|
16
16
|
self.akismet_attrs ||= {}
|
17
|
-
[:comment_type, :author, :author_url, :author_email, :content].each do |field|
|
17
|
+
[:comment_type, :author, :author_url, :author_email, :content, :user_role].each do |field|
|
18
18
|
# clunky, but throwing around +type+ will break your heart
|
19
19
|
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
|
20
20
|
self.akismet_attrs[fieldname] = args.delete(field) || field
|
@@ -32,7 +32,7 @@ module Rakismet
|
|
32
32
|
subclass.rakismet_attrs akismet_attrs.dup
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
module InstanceMethods
|
37
37
|
def spam?
|
38
38
|
if instance_variable_defined? :@_spam
|
@@ -64,7 +64,8 @@ module Rakismet
|
|
64
64
|
elsif !mapped_field.nil? && respond_to?(mapped_field)
|
65
65
|
send(mapped_field)
|
66
66
|
elsif not [:comment_type, :author, :author_email,
|
67
|
-
:author_url, :content, :
|
67
|
+
:author_url, :content, :user_role,
|
68
|
+
:user_ip, :referrer,
|
68
69
|
:user_agent].include?(mapped_field)
|
69
70
|
# we've excluded any fields that appear to
|
70
71
|
# have their default unmapped values
|
@@ -80,6 +81,6 @@ module Rakismet
|
|
80
81
|
akismet
|
81
82
|
end
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
end
|
85
86
|
end
|
data/lib/rakismet/railtie.rb
CHANGED
@@ -14,6 +14,7 @@ module Rakismet
|
|
14
14
|
Rakismet.host = app.config.rakismet[:host]
|
15
15
|
Rakismet.proxy_host = app.config.rakismet[:proxy_host]
|
16
16
|
Rakismet.proxy_port = app.config.rakismet[:proxy_port]
|
17
|
+
Rakismet.test = app.config.rakismet.fetch(:test) { Rails.env.test? || Rails.env.development? }
|
17
18
|
app.middleware.use Rakismet::Middleware if app.config.rakismet.use_middleware
|
18
19
|
end
|
19
20
|
|
data/lib/rakismet/version.rb
CHANGED
data/rakismet.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "rakismet/version"
|
2
|
+
require File.expand_path('../lib/rakismet/version', __FILE__)
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = "rakismet"
|
@@ -11,9 +10,11 @@ Gem::Specification.new do |s|
|
|
11
10
|
s.homepage = "http://github.com/joshfrench/rakismet"
|
12
11
|
s.summary = "Akismet and TypePad AntiSpam integration for Rails."
|
13
12
|
s.description = "Rakismet is the easiest way to integrate Akismet or TypePad's AntiSpam into your Rails app."
|
14
|
-
s.date = "2012-04
|
13
|
+
s.date = "2012-08-04"
|
15
14
|
|
16
15
|
s.rubyforge_project = "rakismet"
|
16
|
+
s.add_development_dependency "rake"
|
17
|
+
s.add_development_dependency "rspec", "~> 2.11"
|
17
18
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
MAPPED_PARAMS = { :comment_type => :type2, :author => :author2, :content => :content2,
|
4
|
-
:author_email => :author_email2, :author_url => :author_url2
|
4
|
+
:author_email => :author_email2, :author_url => :author_url2,
|
5
|
+
:user_role => :user_role2 }
|
5
6
|
|
6
7
|
class CustomAkismetModel
|
7
8
|
include Rakismet::Model
|
@@ -11,7 +12,7 @@ end
|
|
11
12
|
|
12
13
|
describe CustomAkismetModel do
|
13
14
|
it "should override default mappings" do
|
14
|
-
[:comment_type, :author, :author_url, :author_email, :content].each do |field|
|
15
|
+
[:comment_type, :author, :author_url, :author_email, :content, :user_role].each do |field|
|
15
16
|
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
|
16
17
|
CustomAkismetModel.akismet_attrs[fieldname].should eql(MAPPED_PARAMS[field])
|
17
18
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AkismetModel do
|
4
4
|
|
@@ -8,7 +8,7 @@ describe AkismetModel do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should have default mappings" do
|
11
|
-
[:comment_type, :author, :author_email, :author_url, :content].each do |field|
|
11
|
+
[:comment_type, :author, :author_email, :author_url, :content, :user_role].each do |field|
|
12
12
|
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
|
13
13
|
AkismetModel.akismet_attrs[fieldname].should eql(field)
|
14
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class Subclass < AkismetModel
|
4
4
|
end
|
@@ -11,4 +11,4 @@ describe Subclass do
|
|
11
11
|
it "should get a new copy of parent's rakismet attrs" do
|
12
12
|
Subclass.akismet_attrs.should_not equal AkismetModel.akismet_attrs # object equality
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
data/spec/rakismet_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rakismet do
|
4
4
|
|
@@ -7,12 +7,12 @@ describe Rakismet do
|
|
7
7
|
end
|
8
8
|
let(:http) { double(:http, :post => mock_response('akismet response')) }
|
9
9
|
|
10
|
-
|
10
|
+
before do
|
11
11
|
Rakismet.key = 'dummy-key'
|
12
12
|
Rakismet.url = 'test.localhost'
|
13
13
|
Rakismet.host = 'endpoint.localhost'
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
describe "proxy host" do
|
17
17
|
it "should have proxy host and port as nil by default" do
|
18
18
|
Rakismet.proxy_host.should be_nil
|
@@ -36,13 +36,13 @@ describe Rakismet do
|
|
36
36
|
lambda { Rakismet.send(:validate_config) }.should raise_error(Rakismet::Undefined)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
describe ".validate_key" do
|
41
41
|
before (:each) do
|
42
42
|
@proxy = mock(Net::HTTP)
|
43
43
|
Net::HTTP.stub!(:Proxy).and_return(@proxy)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should use proxy host and port" do
|
47
47
|
Rakismet.proxy_host = 'proxy_host'
|
48
48
|
Rakismet.proxy_port = 'proxy_port'
|
@@ -50,7 +50,7 @@ describe Rakismet do
|
|
50
50
|
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
|
51
51
|
Rakismet.validate_key
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should set @@valid_key = true if key is valid" do
|
55
55
|
@proxy.stub!(:start).and_return(mock_response('valid'))
|
56
56
|
Rakismet.validate_key
|
@@ -70,14 +70,14 @@ describe Rakismet do
|
|
70
70
|
Rakismet.validate_key
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
describe ".akismet_call" do
|
75
75
|
before do
|
76
76
|
@proxy = mock(Net::HTTP)
|
77
77
|
Net::HTTP.stub!(:Proxy).and_return(@proxy)
|
78
78
|
@proxy.stub(:start).and_yield(http)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should use proxy host and port" do
|
82
82
|
Rakismet.proxy_host = 'proxy_host'
|
83
83
|
Rakismet.proxy_port = 'proxy_port'
|
@@ -85,19 +85,30 @@ describe Rakismet do
|
|
85
85
|
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
|
86
86
|
Rakismet.send(:akismet_call, 'bogus-function')
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should build url with API key for the correct host" do
|
90
90
|
host = 'api.antispam.typepad.com'
|
91
91
|
Rakismet.host = host
|
92
92
|
@proxy.should_receive(:start).with("#{Rakismet.key}.#{host}")
|
93
93
|
Rakismet.send(:akismet_call, 'bogus-function')
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it "should post data to named function" do
|
97
97
|
http.should_receive(:post).with('/1.1/bogus-function', %r(foo=#{CGI.escape 'escape//this'}), Rakismet.headers)
|
98
98
|
Rakismet.send(:akismet_call, 'bogus-function', { :foo => 'escape//this' })
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
|
+
it "should default to not being in test mode" do
|
102
|
+
http.should_receive(:post).with(anything, %r(is_test=0), anything)
|
103
|
+
Rakismet.send(:akismet_call, 'bogus-function')
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be in test mode when configured" do
|
107
|
+
Rakismet.test = true
|
108
|
+
http.should_receive(:post).with(anything, %r(is_test=1), anything)
|
109
|
+
Rakismet.send(:akismet_call, 'bogus-function')
|
110
|
+
end
|
111
|
+
|
101
112
|
it "should return response.body" do
|
102
113
|
Rakismet.send(:akismet_call, 'bogus-function').should eql('akismet response')
|
103
114
|
end
|
@@ -108,5 +119,5 @@ describe Rakismet do
|
|
108
119
|
}.should_not raise_error(NoMethodError)
|
109
120
|
end
|
110
121
|
end
|
111
|
-
|
122
|
+
|
112
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rakismet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04
|
13
|
-
dependencies:
|
12
|
+
date: 2012-08-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.11'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.11'
|
14
46
|
description: Rakismet is the easiest way to integrate Akismet or TypePad's AntiSpam
|
15
47
|
into your Rails app.
|
16
48
|
email: josh@vitamin-j.com
|