mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-02 06:51:40 +00:00
Do not delete shipping method referenced by an order
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
module Spree
|
||||
module Admin
|
||||
ShippingMethodsController.class_eval do
|
||||
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
|
||||
|
||||
def do_not_destroy_referenced_shipping_methods
|
||||
order = Order.where(:shipping_method_id => @object).first
|
||||
if order
|
||||
flash[:error] = "That shipping method cannot be deleted as it is referenced by an order: #{order.number}."
|
||||
redirect_to collection_url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
21
spec/requests/admin/shipping_methods_spec.rb
Normal file
21
spec/requests/admin/shipping_methods_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'shipping methods' do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
scenario "deleting a shipping method referenced by an order" do
|
||||
login_to_admin_section
|
||||
|
||||
sm = create(:shipping_method)
|
||||
o = create(:order, 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 an order: #{o.number}."
|
||||
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 line item"
|
||||
end
|
||||
Reference in New Issue
Block a user