added post mod details

This commit is contained in:
albert
2010-02-24 12:18:32 -05:00
parent 9f05154a5a
commit 96c6afd482
14 changed files with 533 additions and 1 deletions

11
test/fixtures/hidden_posts.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
test/fixtures/jobs.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

8
test/unit/job_test.rb Normal file
View 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

View 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

View 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