From 1da9e24bd0b9ba1caa1dfa18a06e38d21508b76f Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 9 Mar 2013 01:56:59 -0500 Subject: [PATCH] fixes #804 --- app/models/tag.rb | 7 +++++++ test/unit/comment_test.rb | 2 +- test/unit/post_test.rb | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index d3e1e170e..76085a377 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -87,6 +87,7 @@ class Tag < ActiveRecord::Base def update_category_cache_for_all(force = false) if category_changed? || force update_category_cache + update_category_post_counts if category_changed? Danbooru.config.other_server_hosts.each do |host| delay(:queue => host).update_category_cache @@ -94,6 +95,12 @@ class Tag < ActiveRecord::Base end end + def update_category_post_counts + old_field = "tag_count_#{Danbooru.config.reverse_tag_category_mapping[category_was]}".downcase + new_field = "tag_count_#{category_name}".downcase + Post.raw_tag_match(name).update_all("#{old_field} = #{old_field} - 1, #{new_field} = #{new_field} + 1") + end + def update_category_cache Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour) end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 048d6a885..bf14f67ae 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -80,7 +80,7 @@ class CommentTest < ActiveSupport::TestCase comment_vote = c1.vote!("up") assert_equal([], comment_vote.errors.full_messages) comment_vote = c1.vote!("up") - assert_equal(["User has already voted for this comment"], comment_vote.errors.full_messages) + assert_equal(["You have already voted for this comment"], comment_vote.errors.full_messages) assert_equal(1, CommentVote.count) assert_equal(1, CommentVote.last.score) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index bd5758f2b..6a713aa3e 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -373,6 +373,12 @@ class PostTest < ActiveSupport::TestCase should "update the category cache of the tag" do assert_equal(Tag.categories.copyright, Cache.get("tc:abc")) end + + should "update the tag counts of the posts" do + assert_equal(0, @post.tag_count_artist) + assert_equal(1, @post.tag_count_copyright) + assert_equal(0, @post.tag_count_general) + end end context "tagged with a metatag" do