tag unit test

This commit is contained in:
Albert Yi
2010-02-06 23:11:26 -05:00
parent 305f4d4607
commit 341a24e22e
8 changed files with 403 additions and 11 deletions

10
test/factories/tag.rb Normal file
View File

@@ -0,0 +1,10 @@
Factory.define(:tag) do |f|
f.name {Faker::Name.first_name}
f.post_count 0
f.category Tag.categories.general
f.related_tags ""
end
Factory.define(:artist_tag, :parent => :tag) do |f|
f.category Tag.categories.artist
end

View File

@@ -4,26 +4,26 @@ Factory.define(:user) do |f|
f.email {Faker::Internet.email}
end
Factory.define(:banned_user) do |f|
Factory.define(:banned_user, :parent => :user) do |f|
f.is_banned true
end
Factory.define(:privileged_user) do |f|
Factory.define(:privileged_user, :parent => :user) do |f|
f.is_privileged true
end
Factory.define(:contributor_user) do |f|
Factory.define(:contributor_user, :parent => :user) do |f|
f.is_contributor true
end
Factory.define(:janitor_user) do |f|
Factory.define(:janitor_user, :parent => :user) do |f|
f.is_janitor true
end
Factory.define(:moderator_user) do |f|
Factory.define(:moderator_user, :parent => :user) do |f|
f.is_moderator true
end
Factory.define(:admin_user) do |f|
Factory.define(:admin_user, :parent => :user) do |f|
f.is_admin true
end

View File

@@ -1,8 +1,54 @@
require 'test_helper'
require File.dirname(__FILE__) + '/../test_helper'
class TagTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "A tag category mapping" do
setup do
MEMCACHE.flush_all
end
should "exist" do
assert_nothing_raised {Tag.categories}
end
should "have convenience methods for the four main categories" do
assert_equal(0, Tag.categories.general)
assert_equal(1, Tag.categories.artist)
assert_equal(3, Tag.categories.copyright)
assert_equal(4, Tag.categories.character)
end
should "have a regular expression for matching category names and shortcuts" do
regexp = Tag.categories.regexp
assert_match(regexp, "artist")
assert_match(regexp, "art")
assert_match(regexp, "copyright")
assert_match(regexp, "copy")
assert_match(regexp, "co")
assert_match(regexp, "character")
assert_match(regexp, "char")
assert_match(regexp, "ch")
assert_no_match(regexp, "c")
assert_no_match(regexp, "woodle")
end
should "map a category name to its value" do
assert_equal(0, Tag.categories.value_for("general"))
assert_equal(0, Tag.categories.value_for("gen"))
assert_equal(1, Tag.categories.value_for("artist"))
assert_equal(1, Tag.categories.value_for("art"))
assert_equal(0, Tag.categories.value_for("unknown"))
end
end
context "A tag" do
setup do
MEMCACHE.flush_all
end
should "know its category name" do
@tag = Factory.create(:artist_tag)
assert_equal("Artist", @tag.category_name)
end
end
end