added tag alias unit test
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DeletedPostTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
@@ -83,9 +83,21 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post2 = Factory.create(:post, :tag_string => "bbb ccc ddd")
|
||||
post3 = Factory.create(:post, :tag_string => "ccc ddd eee")
|
||||
user = Factory.create(:user)
|
||||
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
||||
assert_equal(2, Tag.find_by_name("bbb").post_count)
|
||||
assert_equal(3, Tag.find_by_name("ccc").post_count)
|
||||
post3.update_attributes(
|
||||
:tag_string => "xxx",
|
||||
:updater_id => user.id,
|
||||
:updater_ip_addr => "127.0.0.1"
|
||||
)
|
||||
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
||||
assert_equal(2, Tag.find_by_name("bbb").post_count)
|
||||
assert_equal(2, Tag.find_by_name("ccc").post_count)
|
||||
assert_equal(1, Tag.find_by_name("ddd").post_count)
|
||||
assert_equal(0, Tag.find_by_name("eee").post_count)
|
||||
assert_equal(1, Tag.find_by_name("xxx").post_count)
|
||||
end
|
||||
|
||||
should "be counted" do
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostVersionTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,37 @@
|
||||
require 'test_helper'
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TagAliasTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "A tag alias" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "convert a tag to its normalized version" do
|
||||
tag1 = Factory.create(:tag, :name => "aaa")
|
||||
tag2 = Factory.create(:tag, :name => "bbb")
|
||||
ta = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
normalized_tags = TagAlias.to_aliased(["aaa", "ccc"])
|
||||
assert_equal(["bbb", "ccc"], normalized_tags.sort)
|
||||
end
|
||||
|
||||
should "update the cache" do
|
||||
tag1 = Factory.create(:tag, :name => "aaa")
|
||||
tag2 = Factory.create(:tag, :name => "bbb")
|
||||
ta = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal("bbb", MEMCACHE.get("ta:aaa"))
|
||||
end
|
||||
|
||||
should "update any affected posts when saved" do
|
||||
assert_equal(0, TagAlias.count)
|
||||
post1 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post2 = Factory.create(:post, :tag_string => "ccc ddd")
|
||||
assert_equal("aaa bbb", post1.tag_string)
|
||||
assert_equal("ccc ddd", post2.tag_string)
|
||||
ta = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
|
||||
post1.reload
|
||||
post2.reload
|
||||
assert_equal("ccc bbb", post1.tag_string)
|
||||
assert_equal("ccc ddd", post2.tag_string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostUnapprovalTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user