diff --git a/app/models/comment.rb b/app/models/comment.rb index 9f4589f3e..8e5141f3b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -84,10 +84,10 @@ class Comment < ActiveRecord::Base end def update_last_commented_at - if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post - execute_sql("UPDATE posts SET last_commented_at = ? WHERE id = ?", created_at, post_id) - elsif Comment.where("post_id = ?", post_id).empty? + if Comment.where("post_id = ?", post_id).empty? execute_sql("UPDATE posts SET last_commented_at = null WHERE id = ?", post_id) + elsif Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post + execute_sql("UPDATE posts SET last_commented_at = ? WHERE id = ?", created_at, post_id) end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 80e3d70ca..048d6a885 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -32,6 +32,19 @@ class CommentTest < ActiveSupport::TestCase Danbooru.config.stubs(:member_comment_limit).returns(100) Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now) end + + context "that is then deleted" do + setup do + @post = FactoryGirl.create(:post) + @comment = FactoryGirl.create(:comment, :post_id => @post.id) + @comment.destroy + @post.reload + end + + should "nullify the last_commented_at field" do + assert_nil(@post.last_commented_at) + end + end should "be created" do comment = FactoryGirl.build(:comment)