fixed tag and pending post tests, added category multiget helper to tag, post/unapproval/post version in progress still

This commit is contained in:
albert
2010-02-10 16:12:30 -05:00
parent ef8be1a500
commit e6888ea1dd
19 changed files with 1077 additions and 319 deletions

12
test/factories/post.rb Normal file
View File

@@ -0,0 +1,12 @@
Factory.define(:post) do |f|
f.md5 "abcd"
f.uploader {|x| x.association(:user)}
f.uploader_ip_addr "127.0.0.1"
f.tag_string "tag1 tag2"
f.tag_count 2
f.tag_count_general 2
f.file_ext "jpg"
f.image_width 100
f.image_height 200
f.file_size 2000
end

View File

@@ -8,3 +8,11 @@ end
Factory.define(:artist_tag, :parent => :tag) do |f|
f.category Tag.categories.artist
end
Factory.define(:copyright_tag, :parent => :tag) do |f|
f.category Tag.categories.copyright
end
Factory.define(:character_tag, :parent => :tag) do |f|
f.category Tag.categories.character
end

View File

@@ -2,6 +2,7 @@ Factory.define(:user) do |f|
f.name {Faker::Name.first_name}
f.password_hash {User.sha1("password")}
f.email {Faker::Internet.email}
f.default_image_size "medium"
end
Factory.define(:banned_user, :parent => :user) do |f|

View File

@@ -1,6 +1,31 @@
require File.dirname(__FILE__) + '/../test_helper'
class TagTest < ActiveSupport::TestCase
context "A tag category fetcher" do
setup do
MEMCACHE.flush_all
end
should "fetch for a single tag" do
Factory.create(:artist_tag, :name => "test")
assert_equal(Tag.categories.artist, Tag.category_for("test"))
end
should "fetch for a single tag with strange markup" do
Factory.create(:artist_tag, :name => "!@$%")
assert_equal(Tag.categories.artist, Tag.category_for("!@$%"))
end
should "fetch for multiple tags" do
Factory.create(:artist_tag, :name => "aaa")
Factory.create(:copyright_tag, :name => "bbb")
categories = Tag.categories_for(%w(aaa bbb ccc))
assert_equal(Tag.categories.artist, categories["aaa"])
assert_equal(Tag.categories.copyright, categories["bbb"])
assert_equal(0, categories["ccc"])
end
end
context "A tag category mapping" do
setup do
MEMCACHE.flush_all
@@ -51,17 +76,12 @@ class TagTest < ActiveSupport::TestCase
assert_equal("Artist", @tag.category_name)
end
should "know its cache safe name" do
tag = Tag.new
tag.name = "tag"
assert_equal("tag", tag.cache_safe_name)
tag.name = "tag%"
assert_equal("tag_", tag.cache_safe_name)
tag.name = "tag%%"
assert_equal("tag__", tag.cache_safe_name)
should "reset its category after updating" do
tag = Factory.create(:artist_tag)
assert_equal(Tag.categories.artist, MEMCACHE.get("tc:#{tag.name}"))
tag.update_attribute(:category, Tag.categories.copyright)
assert_equal(Tag.categories.copyright, MEMCACHE.get("tc:#{tag.name}"))
end
end

View File

@@ -0,0 +1,8 @@
require 'test_helper'
class PostUnapprovalTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end