Commit a7da4b68820755481240bb367ba879ba2fc96458

Authored by Francisco Marcelo de Araújo Lima Júnior
Committed by Marcos Pereira
1 parent cd3edc92

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>
plugins/anti_spam/Gemfile
1   -gem 'rakismet'
  1 +gem 'rakismet', '~> 1.5.0'
... ...
plugins/anti_spam/dependencies.rb
... ... @@ -1 +0,0 @@
1   -require 'rakismet'
plugins/anti_spam/lib/anti_spam_plugin.rb
... ... @@ -9,7 +9,7 @@ class AntiSpamPlugin &lt; Noosfero::Plugin
9 9 end
10 10  
11 11 def self.host_default_setting
12   - 'api.antispam.typepad.com'
  12 + 'rest.akismet.com'
13 13 end
14 14  
15 15 def check_for_spam(object)
... ...
plugins/anti_spam/lib/anti_spam_plugin/suggest_article_wrapper.rb
1 1 class AntiSpamPlugin::SuggestArticleWrapper < AntiSpamPlugin::Wrapper
  2 +
2 3 alias_attribute :author, :name
3 4 alias_attribute :author_email, :email
4 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 12 def self.wraps?(object)
8 13 object.kind_of?(SuggestArticle)
... ...
plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb
... ... @@ -14,6 +14,7 @@ class AntiSpamPlugin::Wrapper &lt; SimpleDelegator
14 14 end
15 15  
16 16 def self.inherited(child)
  17 + child.rakismet_attrs
17 18 wrappers << child
18 19 end
19 20 end
... ...
plugins/anti_spam/test/unit/anti_spam_plugin/suggest_article_wrapper_test.rb
... ... @@ -4,7 +4,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest &lt; ActiveSupport::TestCase
4 4  
5 5 def setup
6 6 @suggest_article = SuggestArticle.new(
7   - :article_body => 'comment body',
  7 + :article => {:body=> 'comment body'},
8 8 :name => 'author',
9 9 :email => 'foo@example.com',
10 10 :ip_address => '1.2.3.4',
... ... @@ -15,7 +15,7 @@ class AntiSpamPlugin::SuggestArticleWrapperTest &lt; ActiveSupport::TestCase
15 15 end
16 16  
17 17 should 'get contents' do
18   - assert_equal @suggest_article.article_body, @wrapper.content
  18 + assert_equal @suggest_article.article[:body], @wrapper.content
19 19 end
20 20  
21 21 should 'get author name' do
... ...
plugins/anti_spam/test/unit/anti_spam_plugin/wrapper_test.rb
... ... @@ -2,6 +2,11 @@ require &#39;test_helper&#39;
2 2 require 'anti_spam_plugin/wrapper'
3 3  
4 4 class AntiSpamPluginWrapperTest < ActiveSupport::TestCase
  5 +
  6 + def teardown
  7 + AntiSpamPlugin::Wrapper.wrappers = []
  8 + end
  9 +
5 10 should 'use Rakismet::Model' do
6 11 wrapped = AntiSpamPlugin::Wrapper.new(mock)
7 12 assert_includes wrapped.class.included_modules, Rakismet::Model
... ... @@ -22,4 +27,15 @@ class AntiSpamPluginWrapperTest &lt; ActiveSupport::TestCase
22 27 assert AntiSpamPlugin::Wrapper.wrap(5).kind_of?(OddWrapper)
23 28 assert AntiSpamPlugin::Wrapper.wrap(6).kind_of?(EvenWrapper)
24 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 41 end
... ...