tests: don't automatically approve aliases/implications on creation.
Automagically approving inactive aliases makes testing more difficult.
This commit is contained in:
@@ -5,12 +5,5 @@ FactoryBot.define do
|
|||||||
status "active"
|
status "active"
|
||||||
skip_secondary_validations true
|
skip_secondary_validations true
|
||||||
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
||||||
|
|
||||||
after(:create) do |tag_alias|
|
|
||||||
unless tag_alias.status == "pending"
|
|
||||||
approver = FactoryBot.create(:admin_user) unless approver.present?
|
|
||||||
tag_alias.approve!(approver: approver)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,12 +4,5 @@ FactoryBot.define do
|
|||||||
consequent_name "bbb"
|
consequent_name "bbb"
|
||||||
status "active"
|
status "active"
|
||||||
skip_secondary_validations true
|
skip_secondary_validations true
|
||||||
|
|
||||||
after(:create) do |tag_implication|
|
|
||||||
unless tag_implication.status == "pending"
|
|
||||||
approver = FactoryBot.create(:admin_user) unless approver.present?
|
|
||||||
tag_implication.approve!(approver: approver)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ require 'test_helper'
|
|||||||
class TagAliasTest < ActiveSupport::TestCase
|
class TagAliasTest < ActiveSupport::TestCase
|
||||||
context "A tag alias" do
|
context "A tag alias" do
|
||||||
setup do
|
setup do
|
||||||
|
@admin = FactoryBot.create(:admin_user)
|
||||||
|
|
||||||
Timecop.travel(1.month.ago) do
|
Timecop.travel(1.month.ago) do
|
||||||
user = FactoryBot.create(:user)
|
user = FactoryBot.create(:user)
|
||||||
CurrentUser.user = user
|
CurrentUser.user = user
|
||||||
@@ -20,7 +22,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
subject do
|
subject do
|
||||||
FactoryBot.create(:tag, :name => "aaa")
|
FactoryBot.create(:tag, :name => "aaa")
|
||||||
FactoryBot.create(:tag, :name => "bbb")
|
FactoryBot.create(:tag, :name => "bbb")
|
||||||
FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "active")
|
||||||
end
|
end
|
||||||
|
|
||||||
should allow_value('active').for(:status)
|
should allow_value('active').for(:status)
|
||||||
@@ -42,7 +44,6 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should_not allow_value(nil).for(:creator_id)
|
should_not allow_value(nil).for(:creator_id)
|
||||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "on secondary validation" do
|
context "on secondary validation" do
|
||||||
@@ -97,22 +98,21 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||||
ss = FactoryBot.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
|
ss = FactoryBot.create(:saved_search, :query => "123 ... 456", :user => CurrentUser.user)
|
||||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
|
ta = FactoryBot.create(:tag_alias, :antecedent_name => "...", :consequent_name => "bbb")
|
||||||
ss.reload
|
ta.approve!(approver: @admin)
|
||||||
assert_equal(%w(123 456 bbb), ss.query.split.sort)
|
|
||||||
|
assert_equal(%w(123 456 bbb), ss.reload.query.split.sort)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update any affected posts when saved" do
|
should "update any affected posts when saved" do
|
||||||
assert_equal(0, TagAlias.count)
|
|
||||||
post1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
|
post1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
|
||||||
post2 = FactoryBot.create(:post, :tag_string => "ccc ddd")
|
post2 = FactoryBot.create(:post, :tag_string => "ccc ddd")
|
||||||
assert_equal("aaa bbb", post1.tag_string)
|
|
||||||
assert_equal("ccc ddd", post2.tag_string)
|
|
||||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
|
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
|
||||||
post1.reload
|
ta.approve!(approver: @admin)
|
||||||
post2.reload
|
|
||||||
assert_equal("bbb ccc", post1.tag_string)
|
assert_equal("bbb ccc", post1.reload.tag_string)
|
||||||
assert_equal("ccc ddd", post2.tag_string)
|
assert_equal("ccc ddd", post2.reload.tag_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not validate for transitive relations" do
|
should "not validate for transitive relations" do
|
||||||
@@ -126,15 +126,19 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "move existing aliases" do
|
should "move existing aliases" do
|
||||||
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "pending")
|
||||||
ta2 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
ta2 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc", :status => "pending")
|
||||||
ta1.reload
|
ta1.approve!(approver: @admin)
|
||||||
assert_equal("ccc", ta1.consequent_name)
|
ta2.approve!(approver: @admin)
|
||||||
|
|
||||||
|
assert_equal("ccc", ta1.reload.consequent_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "move existing implications" do
|
should "move existing implications" do
|
||||||
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||||
|
ta.approve!(approver: @admin)
|
||||||
|
|
||||||
ti.reload
|
ti.reload
|
||||||
assert_equal("ccc", ti.consequent_name)
|
assert_equal("ccc", ti.consequent_name)
|
||||||
end
|
end
|
||||||
@@ -149,10 +153,11 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "push the antecedent's category to the consequent" do
|
should "push the antecedent's category to the consequent" do
|
||||||
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
|
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
|
||||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
tag2 = FactoryBot.create(:tag, :name => "bbb", :category => 0)
|
||||||
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||||
tag2.reload
|
ta.approve!(approver: @admin)
|
||||||
assert_equal(1, tag2.category)
|
|
||||||
|
assert_equal(1, tag2.reload.category)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an associated forum topic" do
|
context "with an associated forum topic" do
|
||||||
|
|||||||
@@ -209,8 +209,10 @@ class TagImplicationTest < ActiveSupport::TestCase
|
|||||||
p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
||||||
p1.reload
|
ti1.approve!
|
||||||
assert_equal("aaa bbb ccc xxx yyy", p1.tag_string)
|
ti2.approve!
|
||||||
|
|
||||||
|
assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an associated forum topic" do
|
context "with an associated forum topic" do
|
||||||
|
|||||||
Reference in New Issue
Block a user