Skip to content

Commit

Permalink
Merge pull request ManageIQ#16792 from hstastna/Default_Container_Ima…
Browse files Browse the repository at this point in the history
…ge_Rate_delete_description

Add condition to fix deletion of Default Container Image Rate
  • Loading branch information
gtanzillo authored Jan 24, 2018
2 parents 61e7ea9 + 65ddd88 commit 164cd08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/chargeback_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def ensure_unassigned
end

def ensure_nondefault
if default?
if default? || description == 'Default Container Image Rate'
errors.add(:rate, "default rate cannot be deleted")
throw :abort
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/chargeback_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
expect(cbr.errors.first).to include("default rate cannot be deleted")
end

it "when non-default with default description" do
cbr = FactoryGirl.create(:chargeback_rate, :description => "Default Container Image Rate", :default => false)
cbr.destroy
expect(cbr).to_not be_destroyed
expect(cbr.errors.count).to be(1)
expect(cbr.errors.first).to include("default rate cannot be deleted")
end

it "when non-default" do
cbr = FactoryGirl.create(:chargeback_rate, :description => "Non-default", :default => false)
cbr.destroy
Expand Down

0 comments on commit 164cd08

Please sign in to comment.