Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permalink sending #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rakismet/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class << self; attr_accessor :akismet_attrs; end
module ClassMethods
def rakismet_attrs(args={})
self.akismet_attrs ||= {}
[:comment_type, :author, :author_url, :author_email, :content, :user_role, :permalink].each do |field|
[:comment_type, :author, :author_url, :author_email, :content, :user_role].each do |field|
# clunky, but throwing around +type+ will break your heart
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
self.akismet_attrs[fieldname] = args.delete(field) || field
end
[:user_ip, :user_agent, :referrer].each do |field|
[:user_ip, :user_agent, :referrer, :permalink].each do |field|
self.akismet_attrs[field] = args.delete(field) || field
end
args.each_pair do |f,v|
Expand Down
22 changes: 11 additions & 11 deletions spec/models/rakismet_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

before do
@model = AkismetModel.new
comment_attrs.each_pair { |k,v| @model.stub!(k).and_return(v) }
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, :permalink].each do |field|
[: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|
[:user_ip, :user_agent, :referrer, :permalink].each do |field|
AkismetModel.akismet_attrs[field].should eql(field)
end
end
Expand All @@ -30,7 +30,7 @@
[:user_ip, :user_agent, :referrer].each do |field|
@model.should_not respond_to(:field)
end
Rakismet.stub!(:request).and_return(request)
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',
Expand All @@ -39,7 +39,7 @@
end

it "should send http_headers from Rakismet.request if present" do
Rakismet.stub!(:request).and_return(request_with_headers)
Rakismet.stub(:request).and_return(request_with_headers)
Rakismet.should_receive(:akismet_call).
with('comment-check', akismet_attrs.merge(:user_ip => '127.0.0.1',
:user_agent => 'RSpec',
Expand All @@ -56,23 +56,23 @@
end

it "should be true if comment is spam" do
Rakismet.stub!(:akismet_call).and_return('true')
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')
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')
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)
Rakismet.stub(:request).and_return(empty_request)
lambda { @model.spam? }.should_not raise_error(NoMethodError)
end
end
Expand All @@ -85,7 +85,7 @@
end

it "should mutate #spam?" do
Rakismet.stub!(:akismet_call)
Rakismet.stub(:akismet_call)
@model.instance_variable_set(:@_spam, false)
@model.spam!
@model.should be_spam
Expand All @@ -99,7 +99,7 @@
end

it "should mutate #spam?" do
Rakismet.stub!(:akismet_call)
Rakismet.stub(:akismet_call)
@model.instance_variable_set(:@_spam, true)
@model.ham!
@model.should_not be_spam
Expand Down