Skip to content
Browse files

added tests for comment spam

  • Loading branch information...
1 parent a1852e2 commit fc44ee2efed5e635d13648023d3f1fddd507b038 @aross aross committed Feb 26, 2012
Showing with 54 additions and 5 deletions.
  1. +2 −2 app/models/bill.rb
  2. +3 −3 spec/models/bill_spec.rb
  3. +49 −0 spec/models/comment_spec.rb
View
4 app/models/bill.rb
@@ -758,11 +758,11 @@ def unique_referrers(since = 2.days)
end
def related_articles
- Article.tagged_with(subject_terms, :order => 'created_at DESC', :limit => 5)
+ Article.tagged_with(subject_terms, :any => true).order('created_at DESC').limit(5)
end
def subject_terms
- subjects.collect{|s| s.term}.join(',')
+ subjects.collect{|s| s.term }
end
def subject
View
6 spec/models/bill_spec.rb
@@ -30,9 +30,9 @@
bill.related_articles.should == [@article]
end
- it "must match all of a bill's subjects" do
- bill.stub(:subject_terms).and_return("foo,bar,other")
- bill.related_articles.should be_empty
+ it "can match any of a bill's subjects" do
+ bill.stub(:subject_terms).and_return("foo,bar,other,another,yet another")
+ bill.related_articles.should == [@article]
end
it "won't match if there are no matching tags" do
View
49 spec/models/comment_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+describe Comment do
+ describe "spam detection" do
+ let(:comment) { Comment.new }
+
+ before(:each) do
+ @article = Article.create!
+
+ @user = User.new(
+ :login => 'commenttest',
+ :password => 'generic',
+ :password_confirmation => 'generic',
+ :email => "commenttest@opencongress.org",
+ :zipcode => '90039',
+ :enabled => true,
+ :is_banned => false,
+ :accept_tos => true
+ )
+ @user.accepted_tos = true
+ @user.accepted_tos_at = Time.now
+
+ @user.save
+
+ @user.activate
+
+ comment.commentable = @article
+ comment.user = @user
+
+ # this api key is not the same as the one used in production
+ Defender.api_key = '7381e638d4d9163d409266b313dee312'
+ end
+
+ it "does not identify good comments as spam" do
+ comment.comment = "But behind the public pronouncements, American officials described a growing concern, even at the highest levels of the Obama administration and Pentagon, about the challenges of pulling off a troop withdrawal in Afghanistan that hinges on the close mentoring and training of army and police forces."
+ comment.save
+
+ comment.is_spam?.should == false
+ comment.defensio_sig.blank?.should == false
+ end
+
+ it "does identify spammy comments as spam" do
+ comment.comment = '<a href="http://www.kigtropin-shop.com/Wholesale-hgh_c6">HGH</a> <a href="http://www.kigtropin-shop.com/Wholesale-jintropin_c1">Jintropin</a> <a href="http://www.kigtropin-shop.com/Wholesale-hygetropin_c3">Hygetropin</a> <a href="http://www.kigtropin-shop.com/Wholesale-kigtropin_c4">Kigtropin</a> <a href="http://www.kigtropin-shop.com/Wholesale-jintropin-aq_c2">Jintropin AQ</a> <a href="http://www.kigtropin-shop.com/Wholesale-hcg_c7">HCG</a>'
+ comment.save
+
+ comment.is_spam?.should == true
+ end
+ end
+end

0 comments on commit fc44ee2

Please sign in to comment.
Something went wrong with that request. Please try again.