mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix edge case when trying to deactivate the only availabe voucher
Plus spec
This commit is contained in:
@@ -270,7 +270,7 @@ module Admin
|
||||
end
|
||||
|
||||
def update_vouchers
|
||||
return if params[:enterprise][:voucher_ids].blank?
|
||||
params[:enterprise][:voucher_ids] = [] if params[:enterprise][:voucher_ids].blank?
|
||||
|
||||
params_voucher_ids = params[:enterprise][:voucher_ids].map(&:to_i)
|
||||
voucher_ids = @enterprise.vouchers.map(&:id)
|
||||
|
||||
@@ -319,6 +319,19 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
expect(voucher_a.reload.deleted?).to be(true)
|
||||
end
|
||||
|
||||
context "when desactivating the only existing voucher" do
|
||||
it "deactivates the voucher" do
|
||||
voucher_b.really_destroy!
|
||||
|
||||
# Rails won't populate vouchers_id params if no voucher selected
|
||||
spree_put :update,
|
||||
id: enterprise,
|
||||
enterprise: {}
|
||||
|
||||
expect(voucher_a.reload.deleted?).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when activating and deactivating voucher at the same time" do
|
||||
it "deactivates and activates accordingly" do
|
||||
voucher_c = create(:voucher, enterprise: enterprise, code: "voucher 3")
|
||||
|
||||
Reference in New Issue
Block a user