updated tag unit tests

This commit is contained in:
albert
2010-02-11 14:59:58 -05:00
parent 2f3a6e4a8b
commit bed94a4e30
21 changed files with 731 additions and 269 deletions

View File

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

8
test/unit/pool_test.rb Normal file
View File

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

View File

@@ -34,4 +34,133 @@ class PostTest < ActiveSupport::TestCase
assert(!@post.is_deleted?, "Post should not be deleted.")
end
end
context "A post version" do
should "be created on any save" do
@user = Factory.create(:user)
@post = Factory.create(:post)
assert_equal(1, @post.versions.size)
@post.update_attributes(:rating => "e", :updater_id => @user.id, :updater_ip_addr => "125.0.0.0")
assert_equal(2, @post.versions.size)
assert_equal(@user.id, @post.versions.last.updater_id)
assert_equal("125.0.0.0", @post.versions.last.updater_ip_addr)
end
end
context "A post's tags" do
setup do
@post = Factory.create(:post)
end
should "have an array representation" do
assert_equal(%w(tag1 tag2), @post.tag_array)
end
should "be counted" do
@user = Factory.create(:user)
@artist_tag = Factory.create(:artist_tag)
@copyright_tag = Factory.create(:copyright_tag)
@general_tag = Factory.create(:tag)
@new_post = Factory.create(:post, :tag_string => "#{@artist_tag.name} #{@copyright_tag.name} #{@general_tag.name}")
assert_equal(1, @new_post.tag_count_artist)
assert_equal(1, @new_post.tag_count_copyright)
assert_equal(1, @new_post.tag_count_general)
assert_equal(0, @new_post.tag_count_character)
assert_equal(3, @new_post.tag_count)
@new_post.update_attributes(:tag_string => "babs", :updater_id => @user.id, :updater_ip_addr => "127.0.0.1")
assert_equal(0, @new_post.tag_count_artist)
assert_equal(0, @new_post.tag_count_copyright)
assert_equal(1, @new_post.tag_count_general)
assert_equal(0, @new_post.tag_count_character)
assert_equal(1, @new_post.tag_count)
end
should "be merged with any changes that were made after loading the initial set of tags part 1" do
@user = Factory.create(:user)
@post = Factory.create(:post, :tag_string => "aaa bbb ccc")
# user a adds <ddd>
@post_edited_by_user_a = Post.find(@post.id)
@post_edited_by_user_a.update_attributes(
:updater_id => @user.id,
:updater_ip_addr => "127.0.0.1",
:old_tag_string => "aaa bbb ccc",
:tag_string => "aaa bbb ccc ddd"
)
# user b removes <ccc> adds <eee>
@post_edited_by_user_b = Post.find(@post.id)
@post_edited_by_user_b.update_attributes(
:updater_id => @user.id,
:updater_ip_addr => "127.0.0.1",
:old_tag_string => "aaa bbb ccc",
:tag_string => "aaa bbb eee"
)
# final should be <aaa>, <bbb>, <ddd>, <eee>
@final_post = Post.find(@post.id)
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
end
should "be merged with any changes that were made after loading the initial set of tags part 2" do
# This is the same as part 1, only the order of operations is reversed.
# The results should be the same.
@user = Factory.create(:user)
@post = Factory.create(:post, :tag_string => "aaa bbb ccc")
# user a removes <ccc> adds <eee>
@post_edited_by_user_a = Post.find(@post.id)
@post_edited_by_user_a.update_attributes(
:updater_id => @user.id,
:updater_ip_addr => "127.0.0.1",
:old_tag_string => "aaa bbb ccc",
:tag_string => "aaa bbb eee"
)
# user b adds <ddd>
@post_edited_by_user_b = Post.find(@post.id)
@post_edited_by_user_b.update_attributes(
:updater_id => @user.id,
:updater_ip_addr => "127.0.0.1",
:old_tag_string => "aaa bbb ccc",
:tag_string => "aaa bbb ccc ddd"
)
# final should be <aaa>, <bbb>, <ddd>, <eee>
@final_post = Post.find(@post.id)
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
end
end
context "Adding a meta-tag" do
setup do
@post = Factory.create(:post)
end
should "be ignored" do
@user = Factory.create(:user)
@post.update_attributes(
:updater_id => @user.id,
:updater_ip_addr => "127.0.0.1",
:tag_string => "aaa pool:1234 pool:test rating:s fav:bob"
)
assert_equal("aaa", @post.tag_string)
end
end
context "Favoriting a post" do
should "update the favorite string" do
@user = Factory.create(:user)
@post = Factory.create(:post)
@post.add_favorite(@user.id)
assert_equal("fav:#{@user.id}", @post.fav_string)
@post.remove_favorite(@user.id)
assert_equal("", @post.fav_string)
end
end
end

View File

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

View File

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

View File

@@ -108,15 +108,15 @@ class TagTest < ActiveSupport::TestCase
tag1 = Factory.create(:tag, :name => "abc")
tag2 = Factory.create(:tag, :name => "acb")
assert_equal({md5: "abc"}, Tag.parse_query("md5:abc"))
assert_equal({:post_id => [:between, 1, 2]}, Tag.parse_query("id:1..2"))
assert_equal({:post_id => [:gte, 1]}, Tag.parse_query("id:1.."))
assert_equal({:post_id => [:lte, 2]}, Tag.parse_query("id:..2"))
assert_equal({:post_id => [:gt, 2]}, Tag.parse_query("id:>2"))
assert_equal({:post_id => [:lt, 3]}, Tag.parse_query("id:<3"))
assert_equal(["abc"], Tag.parse_query("md5:abc")[:md5])
assert_equal([:between, 1, 2], Tag.parse_query("id:1..2")[:post_id])
assert_equal([:gte, 1], Tag.parse_query("id:1..")[:post_id])
assert_equal([:lte, 2], Tag.parse_query("id:..2")[:post_id])
assert_equal([:gt, 2], Tag.parse_query("id:>2")[:post_id])
assert_equal([:lt, 3], Tag.parse_query("id:<3")[:post_id])
Tag.expects(:normalize_tags_in_query).returns(nil)
assert_equal({:include => ["acb"]}, Tag.parse_query("a*b"))
assert_equal(["acb"], Tag.parse_query("a*b")[:tags][:include])
end
end