diff --git a/app/models/post.rb b/app/models/post.rb index 855f40550..bd7315f35 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -20,6 +20,7 @@ class Post < ActiveRecord::Base before_save :update_tag_post_counts before_save :set_tag_counts before_save :set_pool_category_pseudo_tags + before_create :autoban before_validation :strip_source before_validation :initialize_uploader, :on => :create before_validation :parse_pixiv_id @@ -290,6 +291,12 @@ class Post < ActiveRecord::Base def disapproved_by?(user) PostDisapproval.where(:user_id => user.id, :post_id => id).exists? end + + def autoban + if has_tag?("banned_artist") + self.is_banned = true + end + end end module PresenterMethods @@ -1558,6 +1565,7 @@ class Post < ActiveRecord::Base def reload(options = nil) super reset_tag_array_cache + @pools = nil @tag_categories = nil @typed_tags = nil self diff --git a/test/factories/tag.rb b/test/factories/tag.rb index f0b988acf..24f5dace8 100644 --- a/test/factories/tag.rb +++ b/test/factories/tag.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory(:tag) do - name {Faker::Name.first_name.downcase} + name {"#{Faker::Name.first_name.downcase}#{rand(1000)}"} post_count 0 category {Tag.categories.general} related_tags "" diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 5f73a1c44..bfe80856a 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -33,18 +33,23 @@ class PostTest < ActiveSupport::TestCase end end - should "remove the post from all pools" do - pool = FactoryGirl.create(:pool) - pool.add!(@post) - @post.expunge! - pool.reload - assert_equal("", pool.post_ids) - end + context "that belongs to a pool" do + setup do + @pool = FactoryGirl.create(:pool) + @pool.add!(@post) + @post.reload + @post.expunge! + end - should "destroy the record" do - @post.expunge! - assert_equal([], @post.errors.full_messages) - assert_equal(0, Post.where("id = ?", @post.id).count) + should "remove the post from all pools" do + @pool.reload + assert_equal("", @pool.post_ids) + end + + should "destroy the record" do + assert_equal([], @post.errors.full_messages) + assert_equal(0, Post.where("id = ?", @post.id).count) + end end end @@ -425,6 +430,18 @@ class PostTest < ActiveSupport::TestCase @post = FactoryGirl.create(:post) end + context "with a banned artist" do + setup do + @artist = FactoryGirl.create(:artist) + @artist.ban! + @post = FactoryGirl.create(:post, :tag_string => @artist.name) + end + + should "ban the post" do + assert_equal(true, @post.is_banned?) + end + end + context "with an artist tag that is then changed to copyright" do setup do CurrentUser.user = FactoryGirl.create(:builder_user)