From ad0476e83c1e68e71d3dd1b2a83ab3023472245e Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Wed, 10 Jan 2018 17:29:39 +0100 Subject: [PATCH 1/2] Add condition to fix deletion of Default Container Image Rate Fixing https://bugzilla.redhat.com/show_bug.cgi?id=1486658 Add condition to ensure_nondefault method in chargeback rate model to fix deletion of Default Container Image Rate in Cloud Intel -> Chargeback -> Rates so that the Rate can't be deleted and error message is displayed. --- app/models/chargeback_rate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/chargeback_rate.rb b/app/models/chargeback_rate.rb index 3818e7397cf..f327fe760f5 100644 --- a/app/models/chargeback_rate.rb +++ b/app/models/chargeback_rate.rb @@ -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 From 65ddd88061131af8f10df7f4450c1e1cb3b94fea Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Wed, 10 Jan 2018 17:49:34 +0100 Subject: [PATCH 2/2] Add spec test for Default Container Image Rate --- spec/models/chargeback_rate_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/models/chargeback_rate_spec.rb b/spec/models/chargeback_rate_spec.rb index fc8073996f5..7215f741c57 100644 --- a/spec/models/chargeback_rate_spec.rb +++ b/spec/models/chargeback_rate_spec.rb @@ -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