anti_spam_plugin_test.rb
1.95 KB
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
require 'test_helper'
class AntiSpamPluginTest < ActiveSupport::TestCase
def setup
profile = fast_create(Profile)
article = fast_create(TextileArticle, :profile_id => profile.id)
@comment = fast_create(Comment, :source_id => article.id, :source_type => 'Article')
@suggest_article = SuggestArticle.new(:target_id => profile.id, :target_type => 'Profile', :article_name => 'article', :article_body => 'lorem ipsum', :email => 'invalid@example.com', :name => 'article')
@suggest_article.save!
@settings = Noosfero::Plugin::Settings.new(@comment.environment, AntiSpamPlugin)
@settings.api_key = 'b8b80ddb8084062d0c9119c945ce3bc3'
@settings.save!
@plugin = AntiSpamPlugin.new
@plugin.context = @comment
end
should 'check for spam and mark comment as spam if server says it is spam' do
AntiSpamPlugin::CommentWrapper.any_instance.expects(:spam?).returns(true)
@comment.expects(:save!)
@plugin.check_comment_for_spam(@comment)
assert @comment.spam
end
should 'report comment spam' do
AntiSpamPlugin::CommentWrapper.any_instance.expects(:spam!)
@plugin.comment_marked_as_spam(@comment)
end
should 'report comment ham' do
AntiSpamPlugin::CommentWrapper.any_instance.expects(:ham!)
@plugin.comment_marked_as_ham(@comment)
end
should 'check for spam and mark suggest_article as spam if server says it is spam' do
AntiSpamPlugin::SuggestArticleWrapper.any_instance.expects(:spam?).returns(true)
@suggest_article.expects(:save!)
@plugin.check_suggest_article_for_spam(@suggest_article)
assert @suggest_article.spam
end
should 'report suggest_article spam' do
AntiSpamPlugin::SuggestArticleWrapper.any_instance.expects(:spam!)
@plugin.suggest_article_marked_as_spam(@suggest_article)
end
should 'report suggest_article ham' do
AntiSpamPlugin::SuggestArticleWrapper.any_instance.expects(:ham!)
@plugin.suggest_article_marked_as_ham(@suggest_article)
end
end