public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
decrement article comments counter if a comment is unapproved [evilchelu]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1310 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Jul 03 15:54:33 -0700 2006
commit  b5017e05214b345cd1498778a57f2d0eb48e1d3a
tree    3c715fff60f905045a7ceca40a01b34b479a337d
parent  d10bea105a8239ae82e41adbe91bdd89b4148f34
...
2
3
4
5
 
6
7
8
...
30
31
32
33
 
34
35
 
36
37
38
39
40
41
42
 
...
2
3
4
 
5
6
7
8
...
30
31
32
 
33
34
 
35
36
37
38
39
40
 
41
42
0
@@ -2,7 +2,7 @@ class Comment < Content
0
   validates_presence_of :author, :author_ip, :article_id
0
   before_create { |comment| comment.site_id = comment.article.site_id }
0
   before_create :check_comment_expiration
0
- before_save :increment_counter_cache
0
+ before_save :update_counter_cache
0
   before_destroy :decrement_counter_cache
0
   belongs_to :article
0
   attr_protected :approved
0
@@ -30,12 +30,12 @@ class Comment < Content
0
       raise Article::CommentNotAllowed unless article.comments_allowed?
0
     end
0
 
0
- def increment_counter_cache
0
+ def update_counter_cache
0
       Article.increment_counter 'comments_count', article_id if approved? && @old_approved == :false
0
- decrement_counter_cache if !approved? && @old_approved == :true
0
+ Article.decrement_counter 'comments_count', article_id if !approved? && @old_approved == :true
0
     end
0
     
0
     def decrement_counter_cache
0
       Article.decrement_counter 'comments_count', article_id if approved?
0
     end
0
-end
0
\ No newline at end of file
0
+end
...
52
53
54
 
 
 
 
 
 
 
 
55
56
57
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -52,6 +52,14 @@ class CommentTest < Test::Unit::TestCase
0
     end
0
   end
0
   
0
+ def test_should_decrement_comment_count_upon_unapproval
0
+ assert_difference contents(:welcome), :comments_count, -1 do
0
+ contents(:welcome_comment).approved = false
0
+ assert contents(:welcome_comment).save
0
+ contents(:welcome).reload
0
+ end
0
+ end
0
+
0
   def test_should_not_decrement_unapproved_comment_count
0
     assert_no_difference contents(:welcome), :comments_count do
0
       contents(:unwelcome_comment).destroy

Comments

    No one has commented yet.