Skip to content

Commit

Permalink
Fixes #12099 - Template locked? relying on rake makes tests fail
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dLobatog committed Oct 16, 2015
1 parent 2d02fa7 commit 2d62b8f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions test/unit/provisioning_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 2d62b8f

Please sign in to comment.