Skip to content
Browse files

Do not include deleted products by default

Allow them to be included by passing a show_deleted parameter

Fixes #1626
  • Loading branch information...
1 parent c9f2419 commit 934e3e621d5d074cd96f691472c8131d354674ef @radar radar committed Jun 4, 2012
View
4 api/app/controllers/spree/api/v1/base_controller.rb
@@ -71,6 +71,10 @@ def product_scope
else
scope = Product.active
end
+ unless params[:show_deleted]
+ scope = scope.not_deleted
+ end
+
scope.includes(:master)
end
View
17 api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -132,6 +132,23 @@ module Spree
json_response["pages"].should == 1
end
+ # Regression test for #1626
+ context "deleted products" do
+ before do
+ create(:product, :deleted_at => Time.now)
+ end
+
+ it "does not include deleted products" do
+ api_get :index
+ json_response["products"].count.should == 2
+ end
+
+ it "can include deleted products" do
+ api_get :index, :show_deleted => 1
+ json_response["products"].count.should == 3
+ end
+ end
+
it "can create a new product" do
api_post :create, :product => { :name => "The Other Product",
:price => 19.99 }

0 comments on commit 934e3e6

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