mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Do not delete shipping method referenced by a product distribution
This commit is contained in:
@@ -9,6 +9,13 @@ module Spree
|
||||
flash[:error] = "That shipping method cannot be deleted as it is referenced by an order: #{order.number}."
|
||||
redirect_to collection_url
|
||||
end
|
||||
|
||||
product_distribution = ProductDistribution.where(:shipping_method_id => @object).first
|
||||
if product_distribution
|
||||
p = product_distribution.product
|
||||
flash[:error] = "That shipping method cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
|
||||
redirect_to collection_url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,6 +25,16 @@ feature 'shipping methods' do
|
||||
Spree::ShippingMethod.find(@sm.id).should_not be_nil
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method referenced by a product distribution"
|
||||
scenario "deleting a shipping method referenced by a product distribution" do
|
||||
p = create(:product)
|
||||
d = create(:distributor)
|
||||
create(:product_distribution, product: p, distributor: d, shipping_method: @sm)
|
||||
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
|
||||
page.should have_content "That shipping method cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
|
||||
Spree::ShippingMethod.find(@sm.id).should_not be_nil
|
||||
end
|
||||
|
||||
scenario "deleting a shipping method referenced by a line item"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user