Skip to content
This repository
Browse code

Soft-delete shipping methods when they are deleted through admin backend

Fixes #1240
  • Loading branch information...
commit eac66f64d1c6e2f91d85441281307960e3dbadb5 1 parent a2e6030
Ryan Bigg authored June 04, 2012
11  core/app/controllers/spree/admin/shipping_methods_controller.rb
@@ -4,6 +4,17 @@ class ShippingMethodsController < ResourceController
4 4
       before_filter :load_data, :except => [:index]
5 5
       before_filter :set_shipping_category, :only => [:create, :update]
6 6
 
  7
+      def destroy
  8
+        @object.update_attribute(:deleted_at, Time.now)
  9
+
  10
+        flash.notice = flash_message_for(@object, :successfully_removed)
  11
+
  12
+        respond_with(@object) do |format|
  13
+          format.html { redirect_to collection_url }
  14
+          format.js  { render_js_for_destroy }
  15
+        end
  16
+      end
  17
+
7 18
       private
8 19
 
9 20
       def set_shipping_category
5  core/db/migrate/20120604030249_add_deleted_at_to_spree_shipping_methods.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AddDeletedAtToSpreeShippingMethods < ActiveRecord::Migration
  2
+  def change
  3
+    add_column :spree_shipping_methods, :deleted_at, :datetime
  4
+  end
  5
+end
12  core/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
... ...
@@ -0,0 +1,12 @@
  1
+require 'spec_helper'
  2
+
  3
+describe Spree::Admin::ShippingMethodsController do
  4
+  
  5
+  # Regression test for #1240
  6
+  it "should not hard-delete shipping methods" do
  7
+    Spree::ShippingMethod.should_receive(:find).and_return(shipping_method = stub_model(Spree::ShippingMethod))
  8
+    shipping_method.should_not_receive(:destroy)
  9
+    shipping_method.should_receive(:update_attribute)
  10
+    delete :destroy, :id => 1
  11
+  end
  12
+end

0 notes on commit eac66f6

Please sign in to comment.
Something went wrong with that request. Please try again.