Commit a7da4b68820755481240bb367ba879ba2fc96458
Committed by
Marcos Pereira
1 parent
cd3edc92
Exists in
master
and in
15 other branches
Updates anti_spam plugin
- Updates rakismet version; - Fixes akismet_data being nil; - Creates test for rakismet gem behaviour in anti_spam plugin; - Adds teardown to isolate tests; Signed-off-by: Antonio Terceiro <terceiro@colivre.coop.br> Signed-off-by: Francisco Marcelo de Araújo Lima Júnior <francisco.lima-junior@serpro.gov.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
7 changed files
with
27 additions
and
6 deletions
Show diff stats
plugins/anti_spam/Gemfile
plugins/anti_spam/dependencies.rb
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -require 'rakismet' |
plugins/anti_spam/lib/anti_spam_plugin.rb
@@ -9,7 +9,7 @@ class AntiSpamPlugin < Noosfero::Plugin | @@ -9,7 +9,7 @@ class AntiSpamPlugin < Noosfero::Plugin | ||
9 | end | 9 | end |
10 | 10 | ||
11 | def self.host_default_setting | 11 | def self.host_default_setting |
12 | - 'api.antispam.typepad.com' | 12 | + 'rest.akismet.com' |
13 | end | 13 | end |
14 | 14 | ||
15 | def check_for_spam(object) | 15 | def check_for_spam(object) |
plugins/anti_spam/lib/anti_spam_plugin/suggest_article_wrapper.rb
1 | class AntiSpamPlugin::SuggestArticleWrapper < AntiSpamPlugin::Wrapper | 1 | class AntiSpamPlugin::SuggestArticleWrapper < AntiSpamPlugin::Wrapper |
2 | + | ||
2 | alias_attribute :author, :name | 3 | alias_attribute :author, :name |
3 | alias_attribute :author_email, :email | 4 | alias_attribute :author_email, :email |
4 | alias_attribute :user_ip, :ip_address | 5 | alias_attribute :user_ip, :ip_address |
5 | - alias_attribute :content, :article_body | 6 | + |
7 | + def content | ||
8 | + article && article[:body] | ||
9 | + end | ||
10 | + | ||
6 | 11 | ||
7 | def self.wraps?(object) | 12 | def self.wraps?(object) |
8 | object.kind_of?(SuggestArticle) | 13 | object.kind_of?(SuggestArticle) |
plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb
@@ -14,6 +14,7 @@ class AntiSpamPlugin::Wrapper < SimpleDelegator | @@ -14,6 +14,7 @@ class AntiSpamPlugin::Wrapper < SimpleDelegator | ||
14 | end | 14 | end |
15 | 15 | ||
16 | def self.inherited(child) | 16 | def self.inherited(child) |
17 | + child.rakismet_attrs | ||
17 | wrappers << child | 18 | wrappers << child |
18 | end | 19 | end |
19 | end | 20 | end |
plugins/anti_spam/test/unit/anti_spam_plugin/suggest_article_wrapper_test.rb
@@ -4,7 +4,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest < ActiveSupport::TestCase | @@ -4,7 +4,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @suggest_article = SuggestArticle.new( | 6 | @suggest_article = SuggestArticle.new( |
7 | - :article_body => 'comment body', | 7 | + :article => {:body=> 'comment body'}, |
8 | :name => 'author', | 8 | :name => 'author', |
9 | :email => 'foo@example.com', | 9 | :email => 'foo@example.com', |
10 | :ip_address => '1.2.3.4', | 10 | :ip_address => '1.2.3.4', |
@@ -15,7 +15,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest < ActiveSupport::TestCase | @@ -15,7 +15,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest < ActiveSupport::TestCase | ||
15 | end | 15 | end |
16 | 16 | ||
17 | should 'get contents' do | 17 | should 'get contents' do |
18 | - assert_equal @suggest_article.article_body, @wrapper.content | 18 | + assert_equal @suggest_article.article[:body], @wrapper.content |
19 | end | 19 | end |
20 | 20 | ||
21 | should 'get author name' do | 21 | should 'get author name' do |
plugins/anti_spam/test/unit/anti_spam_plugin/wrapper_test.rb
@@ -2,6 +2,11 @@ require 'test_helper' | @@ -2,6 +2,11 @@ require 'test_helper' | ||
2 | require 'anti_spam_plugin/wrapper' | 2 | require 'anti_spam_plugin/wrapper' |
3 | 3 | ||
4 | class AntiSpamPluginWrapperTest < ActiveSupport::TestCase | 4 | class AntiSpamPluginWrapperTest < ActiveSupport::TestCase |
5 | + | ||
6 | + def teardown | ||
7 | + AntiSpamPlugin::Wrapper.wrappers = [] | ||
8 | + end | ||
9 | + | ||
5 | should 'use Rakismet::Model' do | 10 | should 'use Rakismet::Model' do |
6 | wrapped = AntiSpamPlugin::Wrapper.new(mock) | 11 | wrapped = AntiSpamPlugin::Wrapper.new(mock) |
7 | assert_includes wrapped.class.included_modules, Rakismet::Model | 12 | assert_includes wrapped.class.included_modules, Rakismet::Model |
@@ -22,4 +27,15 @@ class AntiSpamPluginWrapperTest < ActiveSupport::TestCase | @@ -22,4 +27,15 @@ class AntiSpamPluginWrapperTest < ActiveSupport::TestCase | ||
22 | assert AntiSpamPlugin::Wrapper.wrap(5).kind_of?(OddWrapper) | 27 | assert AntiSpamPlugin::Wrapper.wrap(5).kind_of?(OddWrapper) |
23 | assert AntiSpamPlugin::Wrapper.wrap(6).kind_of?(EvenWrapper) | 28 | assert AntiSpamPlugin::Wrapper.wrap(6).kind_of?(EvenWrapper) |
24 | end | 29 | end |
30 | + | ||
31 | + should 'define rakismet_attrs' do | ||
32 | + class AnyWrapper < AntiSpamPlugin::Wrapper | ||
33 | + def self.wraps?(object) | ||
34 | + true | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
38 | + assert_not_nil AnyWrapper.new(Object.new).send :akismet_data | ||
39 | + end | ||
40 | + | ||
25 | end | 41 | end |