Do not delete shipping method referenced by an order

This commit is contained in:
Rohan Mitchell
2012-10-02 11:51:13 +10:00
parent 3886ec39f7
commit 2aa450b072
2 changed files with 36 additions and 0 deletions

View File

@@ -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

View 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