Merge pull request #8950 from jibees/5903-delete-coordinators_fees-linked-to-cloned-OC

Delete linked coordinators fees when deleting an order cycle
This commit is contained in:
Filipe
2022-04-18 11:55:53 +01:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -10,7 +10,8 @@ class OrderCycle < ApplicationRecord
belongs_to :coordinator, class_name: 'Enterprise'
has_many :coordinator_fee_refs, class_name: 'CoordinatorFee'
has_many :coordinator_fees, through: :coordinator_fee_refs, source: :enterprise_fee
has_many :coordinator_fees, through: :coordinator_fee_refs, source: :enterprise_fee,
dependent: :destroy
has_many :exchanges, dependent: :destroy

View File

@@ -401,6 +401,33 @@ module Admin
expect(flash[:error]).to eq I18n.t('admin.order_cycles.destroy_errors.schedule_present')
end
end
describe "when an order cycle has any coordinator_fees" do
let(:enterprise_fee1) { create(:enterprise_fee) }
before do
oc.coordinator_fees << enterprise_fee1
end
it "actually delete the order cycle" do
get :destroy, params: { id: oc.id }
expect(OrderCycle.find_by(id: oc.id)).to be nil
expect(response).to redirect_to admin_order_cycles_path
end
describe "when the order_cycle was previously cloned" do
let(:cloned) { oc.clone! }
it "actually delete the order cycle" do
get :destroy, params: { id: cloned.id }
expect(OrderCycle.find_by(id: cloned.id)).to be nil
expect(OrderCycle.find_by(id: oc.id)).to_not be nil
expect(EnterpriseFee.find_by(id: enterprise_fee1.id)).to_not be nil
expect(response).to redirect_to admin_order_cycles_path
end
end
end
end
end
end