added post mod details
This commit is contained in:
8
test/unit/job_test.rb
Normal file
8
test/unit/job_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class JobTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
42
test/unit/post_moderation_detail_test.rb
Normal file
42
test/unit/post_moderation_detail_test.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class PostModerationDetailTest < ActiveSupport::TestCase
|
||||
context "A post moderation detail" do
|
||||
should "hide posts" do
|
||||
posts = []
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
posts << Factory.create(:post)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => posts[0])
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(2, results.size)
|
||||
assert(results.all? {|x| x.id != posts[0].id})
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(1, results.size)
|
||||
assert_equal(posts[0].id, results[0].id)
|
||||
user = Factory.create(:user)
|
||||
results = PostModerationDetail.filter(posts, user)
|
||||
assert_equal(3, results.size)
|
||||
results = PostModerationDetail.filter(posts, user, true)
|
||||
assert_equal(0, results.size)
|
||||
end
|
||||
|
||||
should "prune itself" do
|
||||
post = Factory.create(:post, :is_flagged => true)
|
||||
user = Factory.create(:user)
|
||||
detail = PostModerationDetail.create(:user => user, :post => post)
|
||||
assert_difference("PostModerationDetail.count", 0) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
post.is_flagged = false
|
||||
post.updater_id = user.id
|
||||
post.updater_ip_addr = "127.0.0.1"
|
||||
post.save
|
||||
assert(post.errors.empty?)
|
||||
assert_difference("PostModerationDetail.count", -1) do
|
||||
PostModerationDetail.prune!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
41
test/unit/related_tag_calculator_test.rb
Normal file
41
test/unit/related_tag_calculator_test.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class RelatedTagCalculatorTest < ActiveSupport::TestCase
|
||||
context "A related tag calculator" do
|
||||
should "calculate related tags for a tag" do
|
||||
posts = []
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
tag = Tag.find_by_name("aaa")
|
||||
calculator = RelatedTagCalculator.new
|
||||
assert_equal({"bbb" => 3, "ccc" => 2, "ddd" => 1}, calculator.calculate_from_sample("aaa"))
|
||||
end
|
||||
|
||||
should "calculate related tags for a tag" do
|
||||
posts = []
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb art:ccc copy:ddd")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb art:ccc")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
tag = Tag.find_by_name("aaa")
|
||||
calculator = RelatedTagCalculator.new
|
||||
assert_equal({"ccc" => 2}, calculator.calculate_from_sample("aaa", Tag.categories.artist))
|
||||
calculator = RelatedTagCalculator.new
|
||||
assert_equal({"ddd" => 1}, calculator.calculate_from_sample("aaa", Tag.categories.copyright))
|
||||
end
|
||||
|
||||
should "convert a hash into string format" do
|
||||
posts = []
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb ccc ddd")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
posts << Factory.create(:post, :tag_string => "aaa bbb")
|
||||
|
||||
tag = Tag.find_by_name("aaa")
|
||||
calculator = RelatedTagCalculator.new
|
||||
counts = calculator.calculate_from_sample("aaa")
|
||||
assert_equal("bbb 3 ccc 2 ddd 1", calculator.convert_hash_to_string(counts))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user