Aliases/implications: Add tests for status and foreign keys.
This commit is contained in:
@@ -41,6 +41,15 @@ class TagAliasesControllerTest < ActionController::TestCase
|
||||
@tag_alias.reload
|
||||
assert_equal("xxx", @tag_alias.antecedent_name)
|
||||
end
|
||||
|
||||
should "not allow changing the status" do
|
||||
post :update, {:id => @tag_alias.id, :tag_alias => {:status => "active"}}, {:user_id => @user.id}
|
||||
@tag_alias.reload
|
||||
assert_equal("pending", @tag_alias.status)
|
||||
end
|
||||
|
||||
# TODO: Broken in shoulda-matchers 2.8.0. Need to upgrade to 3.1.1.
|
||||
should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update)
|
||||
end
|
||||
|
||||
context "for an approved alias" do
|
||||
|
||||
@@ -42,6 +42,15 @@ class TagImplicationsControllerTest < ActionController::TestCase
|
||||
@tag_implication.reload
|
||||
assert_equal("xxx", @tag_implication.antecedent_name)
|
||||
end
|
||||
|
||||
should "not allow changing the status" do
|
||||
post :update, {:id => @tag_implication.id, :tag_implication => {:status => "active"}}, {:user_id => @user.id}
|
||||
@tag_implication.reload
|
||||
assert_equal("pending", @tag_implication.status)
|
||||
end
|
||||
|
||||
# TODO: Broken in shoulda-matchers 2.8.0. Need to upgrade to 3.1.1.
|
||||
should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update)
|
||||
end
|
||||
|
||||
context "for an approved implication" do
|
||||
|
||||
@@ -17,6 +17,36 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "on validation" do
|
||||
subject do
|
||||
FactoryGirl.create(:tag, :name => "aaa")
|
||||
FactoryGirl.create(:tag, :name => "bbb")
|
||||
FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should allow_value('active').for(:status)
|
||||
should allow_value('deleted').for(:status)
|
||||
should allow_value('pending').for(:status)
|
||||
should allow_value('processing').for(:status)
|
||||
should allow_value('queued').for(:status)
|
||||
should allow_value('error: derp').for(:status)
|
||||
|
||||
should_not allow_value('ACTIVE').for(:status)
|
||||
should_not allow_value('error').for(:status)
|
||||
should_not allow_value('derp').for(:status)
|
||||
|
||||
should allow_value(nil).for(:forum_topic_id)
|
||||
should_not allow_value(-1).for(:forum_topic_id).with_message("must exist", against: :forum_topic)
|
||||
|
||||
should allow_value(nil).for(:approver_id)
|
||||
should_not allow_value(-1).for(:approver_id).with_message("must exist", against: :approver)
|
||||
|
||||
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_mass_assignment_of(:status).as(:member)
|
||||
end
|
||||
|
||||
should "populate the creator information" do
|
||||
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(CurrentUser.user.id, ta.creator_id)
|
||||
|
||||
@@ -16,6 +16,38 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "on validation" do
|
||||
subject do
|
||||
FactoryGirl.create(:tag, :name => "aaa")
|
||||
FactoryGirl.create(:tag, :name => "bbb")
|
||||
FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should allow_value('active').for(:status)
|
||||
should allow_value('deleted').for(:status)
|
||||
should allow_value('pending').for(:status)
|
||||
should allow_value('processing').for(:status)
|
||||
should allow_value('queued').for(:status)
|
||||
should allow_value('error: derp').for(:status)
|
||||
|
||||
should_not allow_value('ACTIVE').for(:status)
|
||||
should_not allow_value('error').for(:status)
|
||||
should_not allow_value('derp').for(:status)
|
||||
|
||||
should allow_value(nil).for(:forum_topic_id)
|
||||
should_not allow_value(-1).for(:forum_topic_id).with_message("must exist", against: :forum_topic)
|
||||
|
||||
should allow_value(nil).for(:approver_id)
|
||||
should_not allow_value(-1).for(:approver_id).with_message("must exist", against: :approver)
|
||||
|
||||
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_mass_assignment_of(:status).as(:member)
|
||||
should_not allow_mass_assignment_of(:forum_topic).as(:member)
|
||||
should_not allow_mass_assignment_of(:descendant_names).as(:member)
|
||||
end
|
||||
|
||||
should "ignore pending implications when building descendant names" do
|
||||
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c", :status => "pending")
|
||||
ti2.save
|
||||
|
||||
Reference in New Issue
Block a user