fixes #2386, fix tests
This commit is contained in:
@@ -20,6 +20,7 @@ class Post < ActiveRecord::Base
|
|||||||
before_save :update_tag_post_counts
|
before_save :update_tag_post_counts
|
||||||
before_save :set_tag_counts
|
before_save :set_tag_counts
|
||||||
before_save :set_pool_category_pseudo_tags
|
before_save :set_pool_category_pseudo_tags
|
||||||
|
before_create :autoban
|
||||||
before_validation :strip_source
|
before_validation :strip_source
|
||||||
before_validation :initialize_uploader, :on => :create
|
before_validation :initialize_uploader, :on => :create
|
||||||
before_validation :parse_pixiv_id
|
before_validation :parse_pixiv_id
|
||||||
@@ -290,6 +291,12 @@ class Post < ActiveRecord::Base
|
|||||||
def disapproved_by?(user)
|
def disapproved_by?(user)
|
||||||
PostDisapproval.where(:user_id => user.id, :post_id => id).exists?
|
PostDisapproval.where(:user_id => user.id, :post_id => id).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autoban
|
||||||
|
if has_tag?("banned_artist")
|
||||||
|
self.is_banned = true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module PresenterMethods
|
module PresenterMethods
|
||||||
@@ -1558,6 +1565,7 @@ class Post < ActiveRecord::Base
|
|||||||
def reload(options = nil)
|
def reload(options = nil)
|
||||||
super
|
super
|
||||||
reset_tag_array_cache
|
reset_tag_array_cache
|
||||||
|
@pools = nil
|
||||||
@tag_categories = nil
|
@tag_categories = nil
|
||||||
@typed_tags = nil
|
@typed_tags = nil
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory(:tag) do
|
factory(:tag) do
|
||||||
name {Faker::Name.first_name.downcase}
|
name {"#{Faker::Name.first_name.downcase}#{rand(1000)}"}
|
||||||
post_count 0
|
post_count 0
|
||||||
category {Tag.categories.general}
|
category {Tag.categories.general}
|
||||||
related_tags ""
|
related_tags ""
|
||||||
|
|||||||
@@ -33,18 +33,23 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "remove the post from all pools" do
|
context "that belongs to a pool" do
|
||||||
pool = FactoryGirl.create(:pool)
|
setup do
|
||||||
pool.add!(@post)
|
@pool = FactoryGirl.create(:pool)
|
||||||
@post.expunge!
|
@pool.add!(@post)
|
||||||
pool.reload
|
@post.reload
|
||||||
assert_equal("", pool.post_ids)
|
@post.expunge!
|
||||||
end
|
end
|
||||||
|
|
||||||
should "destroy the record" do
|
should "remove the post from all pools" do
|
||||||
@post.expunge!
|
@pool.reload
|
||||||
assert_equal([], @post.errors.full_messages)
|
assert_equal("", @pool.post_ids)
|
||||||
assert_equal(0, Post.where("id = ?", @post.id).count)
|
end
|
||||||
|
|
||||||
|
should "destroy the record" do
|
||||||
|
assert_equal([], @post.errors.full_messages)
|
||||||
|
assert_equal(0, Post.where("id = ?", @post.id).count)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -425,6 +430,18 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
@post = FactoryGirl.create(:post)
|
@post = FactoryGirl.create(:post)
|
||||||
end
|
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
|
context "with an artist tag that is then changed to copyright" do
|
||||||
setup do
|
setup do
|
||||||
CurrentUser.user = FactoryGirl.create(:builder_user)
|
CurrentUser.user = FactoryGirl.create(:builder_user)
|
||||||
|
|||||||
Reference in New Issue
Block a user