From 2d62b8f535fca01ebdc81768feddf9816e5efde5 Mon Sep 17 00:00:00 2001 From: Daniel Lobato Date: Thu, 8 Oct 2015 11:10:17 +0200 Subject: [PATCH] Fixes #12099 - Template locked? relying on rake makes tests fail app/models/template.rb has a method locked? that relies on !Foreman.in_rake? to bypass the locked validation when running some operations through Rake such as migrations or cloning templates. On Rails 4 rake test is also interpreted as being 'in rake' and tests fail when running them through rake test but not when running template tests individually. --- test/unit/provisioning_template_test.rb | 39 +++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/test/unit/provisioning_template_test.rb b/test/unit/provisioning_template_test.rb index 76c7b63a79c..08d4f3ad16e 100644 --- a/test/unit/provisioning_template_test.rb +++ b/test/unit/provisioning_template_test.rb @@ -85,10 +85,26 @@ class ProvisioningTemplateTest < ActiveSupport::TestCase assert FactoryGirl.create(:provisioning_template, :locked => true) end - test "should not edit a locked template" do - tmplt = templates(:locked) - tmplt.name = "something else" - refute_valid tmplt, :base, /is locked/ + context 'locked templates outside of rake' do + setup do + Foreman.stubs(:in_rake?).returns(false) + @template = templates(:locked) + end + + test "should not edit a locked template" do + @template.name = "something else" + refute_valid @template, :base, /is locked/ + end + + test "should not remove a locked template" do + refute_with_errors @template.destroy, @template, :base, /locked/ + end + + test "should not unlock a template if not allowed" do + User.current = FactoryGirl.create(:user) + @template.locked = false + refute_valid @template, :base, /not authorized/ + end end test "should clone a locked template as unlocked" do @@ -102,21 +118,6 @@ class ProvisioningTemplateTest < ActiveSupport::TestCase refute clone.locked end - test "should not remove a locked template" do - tmplt = templates(:locked) - refute_with_errors tmplt.destroy, tmplt, :base, /locked/ - end - - test "should not unlock a template if not allowed" do - tmplt = ProvisioningTemplate.create :name => "Vendor Template", :template => "provision test", - :template_kind => template_kinds(:provision), :default => true, - :vendor => "Katello" - tmplt.update_attribute(:locked, true) - User.current = FactoryGirl.create(:user) - tmplt.locked = false - refute_valid tmplt, :base, /not authorized/ - end - test "should change a locked template while in rake" do Foreman.stubs(:in_rake?).returns(true) tmplt = templates(:locked)