1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'spec_helper'
describe AkismetModel do
before do
@model = AkismetModel.new
comment_attrs.each_pair { |k,v| @model.stub!(k).and_return(v) }
end
it "should have default mappings" do
[:comment_type, :author, :author_email, :author_url, :content, :user_role].each do |field|
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
AkismetModel.akismet_attrs[fieldname].should eql(field)
end
end
it "should have request mappings" do
[:user_ip, :user_agent, :referrer].each do |field|
AkismetModel.akismet_attrs[field].should eql(field)
end
end
it "should populate comment type" do
@model.send(:akismet_data)[:comment_type].should == comment_attrs[:comment_type]
end
describe ".spam?" do
it "should use request variables from Rakismet.request if absent in model" do
[:user_ip, :user_agent, :referrer].each do |field|
@model.should_not respond_to(:field)
end
Rakismet.stub!(:request).and_return(request)
Rakismet.should_receive(:akismet_call).
with('comment-check', akismet_attrs.merge(:user_ip => '127.0.0.1',
:user_agent => 'RSpec',
:referrer => 'http://test.host/referrer'))
@model.spam?
end
it "should cache result of #spam?" do
Rakismet.should_receive(:akismet_call).once
@model.spam?
@model.spam?
end
it "should be true if comment is spam" do
Rakismet.stub!(:akismet_call).and_return('true')
@model.should be_spam
end
it "should be false if comment is not spam" do
Rakismet.stub!(:akismet_call).and_return('false')
@model.should_not be_spam
end
it "should set akismet_response" do
Rakismet.stub!(:akismet_call).and_return('response')
@model.spam?
@model.akismet_response.should eql('response')
end
it "should not throw an error if request vars are missing" do
Rakismet.stub!(:request).and_return(empty_request)
lambda { @model.spam? }.should_not raise_error(NoMethodError)
end
end
describe ".spam!" do
it "should call Base.akismet_call with submit-spam" do
Rakismet.should_receive(:akismet_call).with('submit-spam', akismet_attrs)
@model.spam!
end
it "should mutate #spam?" do
Rakismet.stub!(:akismet_call)
@model.instance_variable_set(:@_spam, false)
@model.spam!
@model.should be_spam
end
end
describe ".ham!" do
it "should call Base.akismet_call with submit-ham" do
Rakismet.should_receive(:akismet_call).with('submit-ham', akismet_attrs)
@model.ham!
end
it "should mutate #spam?" do
Rakismet.stub!(:akismet_call)
@model.instance_variable_set(:@_spam, true)
@model.ham!
@model.should_not be_spam
end
end
end