From b19994396d3c9e2752f18f61736dfd8a258ff6e9 Mon Sep 17 00:00:00 2001 From: albert Date: Wed, 3 Apr 2013 17:23:25 -0400 Subject: [PATCH] fix tests, fixes #1173 --- app/models/comment.rb | 16 +++++++++++----- test/factories/user.rb | 2 +- test/unit/comment_test.rb | 2 +- test/unit/user_test.rb | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index a435e537d..05b2134c1 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -7,8 +7,8 @@ class Comment < ActiveRecord::Base has_many :votes, :class_name => "CommentVote", :dependent => :destroy before_validation :initialize_creator, :on => :create before_validation :initialize_updater - after_save :update_last_commented_at - after_destroy :update_last_commented_at + after_save :update_last_commented_at_on_save + after_destroy :update_last_commented_at_on_destroy attr_accessible :body, :post_id, :do_not_bump_post attr_accessor :do_not_bump_post @@ -101,12 +101,18 @@ class Comment < ActiveRecord::Base end end - def update_last_commented_at - if Comment.where("post_id = ?", post_id).count == 0 + def update_last_commented_at_on_destroy + if Comment.where("post_id = ? and id <> ?", post_id, id).count == 0 Post.update_all("last_commented_at = NULL", ["id = ?", post_id]) - elsif Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post? + end + true + end + + def update_last_commented_at_on_save + if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post? Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id]) end + true end def do_not_bump_post? diff --git a/test/factories/user.rb b/test/factories/user.rb index 4cd2e00d4..4a5476d59 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory(:user) do - name {rand(1_000_000).to_s} + name {(rand(1_000_000) + 10).to_s} password "password" password_hash {User.sha1("password")} email {Faker::Internet.email} diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 1f8de75a2..ec2fa5af6 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -23,7 +23,7 @@ class CommentTest < ActiveSupport::TestCase should "fail creation" do comment = FactoryGirl.build(:comment) comment.save - assert_equal(["Creator can not post comments within 1 week of sign up, and can only post 5 comments per hour after that"], comment.errors.full_messages) + assert_equal(["You can not post comments within 1 week of sign up"], comment.errors.full_messages) end end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index dc9da92a7..27a116a45 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -81,10 +81,11 @@ class UserTest < ActiveSupport::TestCase @user.update_column(:level, User::Levels::MEMBER) @user.update_column(:created_at, 1.year.ago) assert(@user.can_comment?) + assert(!@user.is_comment_limited?) (Danbooru.config.member_comment_limit).times do FactoryGirl.create(:comment) end - assert(!@user.can_comment?) + assert(@user.is_comment_limited?) end should "verify" do