This commit is contained in:
Toks
2013-10-06 16:56:39 -04:00
parent 5005614e97
commit c5b5ca9825
7 changed files with 76 additions and 10 deletions

View File

@@ -2,9 +2,12 @@ FactoryGirl.define do
factory :tag_alias do
antecedent_name "aaa"
consequent_name "bbb"
status "active"
after(:create) do |tag_alias|
tag_alias.process!
unless tag_alias.status == "pending"
tag_alias.process!
end
end
end
end

View File

@@ -2,9 +2,12 @@ FactoryGirl.define do
factory :tag_implication do
antecedent_name "aaa"
consequent_name "bbb"
status "active"
after(:create) do |tag_implication|
tag_implication.process!
unless tag_implication.status == "pending"
tag_implication.process!
end
end
end
end

View File

@@ -53,15 +53,29 @@ class TagAliasTest < ActiveSupport::TestCase
end
should "not validate for transitive relations" do
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
assert_difference("TagAlias.count", 0) do
ta3 = FactoryGirl.build(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ddd")
ta3.save
assert(ta3.errors.any?, "Tag alias should be invalid")
assert_equal("Tag alias can not create a transitive relation with another tag alias", ta3.errors.full_messages.join)
ta2 = FactoryGirl.build(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
ta2.save
assert(ta2.errors.any?, "Tag alias should be invalid")
assert_equal("Tag alias can not create a transitive relation with another tag alias", ta2.errors.full_messages.join)
end
end
should "move existing aliases" do
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "active")
ta2 = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc", :status => "active")
ta1.reload
assert_equal("ccc", ta1.consequent_name)
end
should "move existing implications" do
ti = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "active")
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc", :status => "active")
ti.reload
assert_equal("ccc", ti.consequent_name)
end
should "not push the antecedent's category to the consequent if the antecedent is general" do
tag1 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb", :category => 1)

View File

@@ -17,7 +17,7 @@ class TagImplicationTest < ActiveSupport::TestCase
end
should "ignore pending implications when building descendant names" do
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c")
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c", :status => "pending")
ti2.save
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "a", :consequent_name => "b")
assert_equal("b", ti1.descendant_names)
@@ -44,6 +44,14 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("Antecedent name has already been taken", ti2.errors.full_messages.join(""))
end
should "not validate if its consequent is aliased to another tag" do
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
ti = FactoryGirl.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti.save
assert(ti.errors.any?, "Tag implication should not have validated.")
assert_equal("Consequent tag must not be aliased to another tag", ti.errors.full_messages.join(""))
end
should "calculate all its descendants" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
assert_equal("ccc", ti1.descendant_names)