-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sven Fuchs
committed
Jul 12, 2008
1 parent
b97e60b
commit 537e183
Showing
29 changed files
with
281 additions
and
160 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
an_anonymous: | ||
name: anonymous | ||
email: anonymous@email.org | ||
homepage: http://www.example.org | ||
agent: the-agent | ||
ip: 1.1.1.1 | ||
referer: the-referer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
a_comment: | ||
body: comment body | ||
site: site_1 | ||
section: home | ||
author: an_anonymous, | ||
author_type: Anonymous, | ||
commentable: an_article | ||
commentable_type: Article, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,70 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe 'Spam engines' do | ||
fixtures :sites, :sections, :contents | ||
fixtures :sites, :sections, :contents, :comments, :anonymouses | ||
|
||
before :each do | ||
@site = sites(:site_1) | ||
@section = sections(:home) | ||
@comment = comments(:a_comment) | ||
@comment.author = anonymouses(:an_anonymous) # wtf | ||
@comment.commentable = contents(:an_article) | ||
|
||
@article = contents(:an_article) | ||
@anonymous = Anonymous.new :name => 'anonymous', | ||
:email => 'anonymous@email.org', | ||
:homepage => 'http://www.example.org', | ||
:agent => 'the-agent', | ||
:ip => '1.1.1.1', | ||
:referer => 'the-referer' | ||
|
||
@comment = Comment.new :body => 'comment body', | ||
:site_id => @site.id, | ||
:section_id => @section.id, | ||
:section => @section, | ||
:author => @anonymous, | ||
:commentable_type => 'Article', | ||
:commentable_id => @article.id | ||
http = Net::HTTP.new("url") | ||
Net::HTTP.stub!(:new).and_return(http) | ||
|
||
@akismet_options = { :permalink => "http://www.example.org/an-article", | ||
:user_ip => '1.1.1.1', | ||
:user_agent => 'the-agent', | ||
:referrer => 'the-referer', | ||
:comment_author => "anonymous", | ||
:comment_author_email => "anonymous@email.org", | ||
:comment_author_url => "http://www.example.org", | ||
:comment_content => "comment body" } | ||
|
||
@defensio_options = { :permalink => "http://www.example.org/an-article", | ||
:user_ip => '1.1.1.1', | ||
:referrer => 'the-referer', | ||
:comment_author => "anonymous", | ||
:comment_author_email => "anonymous@email.org", | ||
:comment_author_url => "http://www.example.org", | ||
:comment_content => "comment body", | ||
:article_date => @comment.commentable.published_at, | ||
:comment_type => "comment", | ||
:user_logged_in => nil, | ||
:trusted_user => nil } | ||
end | ||
|
||
it "#check_comment on a Section ends up calling #check_comment on the Akismet Viking engine" do | ||
@site.update_attributes :spam_options => {:engine => 'Akismet', 'Akismet' => {:akismet_key => 'key', :akismet_url => 'http://domain.com'}} | ||
options = { :permalink => "http://www.example.org/an-article", | ||
:user_ip => '1.1.1.1', | ||
:user_agent => 'the-agent', | ||
:referrer => 'the-referer', | ||
:comment_author => "anonymous", | ||
:comment_author_email => "anonymous@email.org", | ||
:comment_author_url => "http://www.example.org", | ||
:comment_content => "comment body" } | ||
|
||
@comment.section.site.spam_engine.send(:akismet).should_receive(:check_comment).with(options).and_return true | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.spam_info.should == {:spam => false} | ||
end | ||
describe '#check_comment' do | ||
it "approves the comment when the site's spam_option :engine is 'None' and approve_comments is true" do | ||
sites(:site_1).update_attributes :spam_options => {:engine => 'None', :approve_comments => true} | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.approved?.should be_true | ||
end | ||
|
||
it "does not approve the comment when the site's spam_option :engine is 'None' and approve_comments is not true" do | ||
sites(:site_1).update_attributes :spam_options => {:engine => 'None', :approve_comments => false} | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.approved?.should be_false | ||
end | ||
|
||
it "calls #check_comment on the None SpamEngine when the site's spam_option :engine is 'None'" do | ||
sites(:site_1).update_attributes :spam_options => {:engine => 'None', :approve_comments => false} | ||
@comment.section.site.spam_engine.should be_instance_of(SpamEngine::None) | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.spam_info.should == {} | ||
end | ||
|
||
it "calls #check_comment on the Akismet Viking engine when the site's spam_option :engine is 'Akismet'" do | ||
sites(:site_1).update_attributes :spam_options => {:engine => 'Akismet', 'Akismet' => {:akismet_key => 'key', :akismet_url => 'http://domain.com'}} | ||
@comment.section.site.spam_engine.send(:akismet).should_receive(:check_comment).with(@akismet_options).and_return true | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.spam_info.should == {:spam => false} | ||
end | ||
|
||
it "#check_comment on a Section ends up calling #check_comment on the Defensio Viking engine" do | ||
@site.update_attributes :spam_options => {:engine => 'Defensio', 'Defensio' => {:defensio_key => 'key', :defensio_url => 'http://domain.com'}} | ||
options = { :permalink => "http://www.example.org/an-article", | ||
:user_ip => '1.1.1.1', | ||
:referrer => 'the-referer', | ||
:comment_author => "anonymous", | ||
:comment_author_email => "anonymous@email.org", | ||
:comment_author_url => "http://www.example.org", | ||
:comment_content => "comment body", | ||
:article_date => @comment.commentable.published_at, | ||
:comment_type => "comment", | ||
:user_logged_in => nil, | ||
:trusted_user => nil } | ||
|
||
@comment.section.site.spam_engine.send(:defensio).should_receive(:check_comment).with(options).and_return :spam => false, :spaminess => 0.0, :signature => 'signature' | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.spam_info.should == {:spam => false, :spaminess => 0.0, :signature => 'signature'} | ||
it "calls #check_comment on the Defensio Viking engine when the site's spam_option :engine is 'Defensio'" do | ||
sites(:site_1).update_attributes :spam_options => {:engine => 'Defensio', 'Defensio' => {:defensio_key => 'key', :defensio_url => 'http://domain.com'}} | ||
@comment.section.site.spam_engine.send(:defensio).should_receive(:check_comment).with(@defensio_options).and_return :spam => false, :spaminess => 0.0, :signature => 'signature' | ||
@comment.check_spam('http://www.example.org/an-article', @comment) | ||
@comment.spam_info.should == {:spam => false, :spaminess => 0.0, :signature => 'signature'} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
vendor/engines/adva_cms/app/views/admin/spam/_akismet_settings.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div id="site_spam_settings_akismet" class="site_spam_settings <%= 'active' if active %>"> | ||
<h4>Settings</h4> | ||
<p> | ||
<label for="site_spam_options_akismet_key">Akismet API Key</label> | ||
<%= text_field_tag "site[spam_options][akismet_key]", @site.spam_options[:akismet_key], :id => 'site_spam_options_akismet_key' %> | ||
</p> | ||
<p> | ||
<label for="site_spam_options_akismet_url">Blog url</label> | ||
<%= text_field_tag "site[spam_options][akismet_url]", @site.spam_options[:akismet_url], :id => 'site_spam_options_akismet_url' %> | ||
</p> | ||
</div> |
11 changes: 11 additions & 0 deletions
11
vendor/engines/adva_cms/app/views/admin/spam/_defensio_settings.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div id="site_spam_settings_defensio" class="site_spam_settings <%= 'active' if active %>"> | ||
<h4>Settings</h4> | ||
<p> | ||
<label for="site_spam_options_defensio_key">Defensio API Key</label> | ||
<%= text_field_tag "site[spam_options][defensio_key]", @site.spam_options[:defensio_key], :id => 'site_spam_options_defensio_key' %> | ||
</p> | ||
<p> | ||
<label for="site_spam_options_defensio_url">Blog url</label> | ||
<%= text_field_tag "site[spam_options][defensio_url]", @site.spam_options[:defensio_url], :id => 'site_spam_options_defensio_url' %> | ||
</p> | ||
</div> |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
vendor/engines/adva_cms/app/views/admin/spam/_none_settings.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div id="site_spam_settings_none" class="site_spam_settings <%= 'active' if active %>"> | ||
<h4>Settings</h4> | ||
<p> | ||
<%= check_box_tag 'site[spam_options][approve_comments]', "1", @site.approve_comments?, :id => 'site_spam_options_approve_comments' %> | ||
<label class="inline light" for="site_spam_options_approve_comments"> | ||
Approve and publish all comments automatically. | ||
</label> | ||
</p> | ||
</div> |
6 changes: 0 additions & 6 deletions
6
vendor/engines/adva_cms/app/views/admin/spam/akismet_settings.erb
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
vendor/engines/adva_cms/app/views/admin/spam/defensio.html.erb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
module SpamEngine | ||
mattr_accessor :adapters | ||
@@adapters = [] | ||
|
||
class << self | ||
def adapter(site, options = {}) | ||
def adapter(options) | ||
name = options[:engine] || 'None' | ||
"SpamEngine::#{name}".constantize.new(site, options[name]) | ||
options = (options[name] || {}).merge :approve => options[:approve_comments] | ||
"SpamEngine::#{name}".constantize.new options | ||
end | ||
|
||
def register(klass) | ||
@@adapters << klass.name | ||
end | ||
|
||
def names | ||
adapters.map &:demodulize | ||
end | ||
end | ||
end |
Oops, something went wrong.