Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use paranoia_ prefixed methods #2350

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def update
def destroy
@product = find_product(params[:id])
authorize! :destroy, @product
@product.destroy
@product.paranoia_destroy
respond_with(@product, status: 204)
end

Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/stock_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update

def destroy
@stock_item = Spree::StockItem.accessible_by(current_ability, :destroy).find(params[:id])
@stock_item.destroy
@stock_item.paranoia_destroy
respond_with(@stock_item, status: 204)
end

Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/transfer_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def update
def destroy
authorize! :destroy, TransferItem
@transfer_item = Spree::TransferItem.accessible_by(current_ability, :destroy).find(params[:id])
if @transfer_item.destroy
if @transfer_item.paranoia_destroy
respond_with(@transfer_item, status: 200, default_template: :show)
else
invalid_resource!(@transfer_item)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create

def destroy
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
@variant.destroy
@variant.paranoia_destroy
respond_with(@variant, status: 204)
end

Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/checkouts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module Spree

# Regression Spec for https://github.com/spree/spree/issues/5389 and https://github.com/spree/spree/issues/5880
it "can update addresses but not transition to delivery w/o shipping setup" do
Spree::ShippingMethod.destroy_all
Spree::ShippingMethod.all.each(&:really_destroy!)
put spree.api_checkout_path(order),
params: { order_token: order.guest_token, order: {
bill_address_attributes: address,
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module Spree
specify do
get spree.api_product_path(product)
expect(json_response["slug"]).to match(/and-1-ways/)
product.destroy
product.paranoia_destroy

get spree.api_product_path(other_product)
expect(json_response["slug"]).to match(/droids/)
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/shipments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

it 'removes a destroyed variant from a shipment' do
order.contents.add(variant, 2)
variant.destroy
variant.paranoia_destroy

put spree.remove_api_shipment_path(shipment), params: { variant_id: variant.to_param, quantity: 1 }
expect(response.status).to eq(200)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def update

def destroy
@product = Spree::Product.friendly.find(params[:id])
@product.destroy
@product.paranoia_destroy!

flash[:success] = t('spree.notice_messages.product_deleted')

Expand Down
10 changes: 9 additions & 1 deletion backend/app/controllers/spree/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ def update_positions

def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy

destroy_result =
if @object.respond_to?(:paranoia_destroy)
@object.paranoia_destroy
else
@object.destroy
end

if destroy_result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good catch. Lots of extensions might inherit from this.

invoke_callbacks(:destroy, :after)
flash[:success] = flash_message_for(@object, :successfully_removed)
respond_with(@object) do |format|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ShippingMethodsController < ResourceController
before_action :set_zones, only: [:create, :update]

def destroy
@object.destroy
@object.paranoia_destroy

flash[:success] = flash_message_for(@object, :successfully_removed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

# Regression test for https://github.com/spree/spree/issues/1903
context 'when soft deleted products exist' do
let!(:soft_deleted_product) { create(:product, sku: "ABC123").destroy }
let!(:soft_deleted_product) { create(:product, sku: "ABC123") }
before { soft_deleted_product.paranoia_destroy }

context 'when params[:q][:with_deleted] is not set' do
let(:params) { { q: {} } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Admin
end

context "with a deleted product" do
before { product.destroy! }
before { product.paranoia_destroy! }

it "is the product" do
subject
Expand All @@ -32,7 +32,7 @@ module Admin
let!(:deleted_variant) { create(:variant, product: product) }

context "with deleted variants" do
before { deleted_variant.destroy }
before { deleted_variant.paranoia_destroy! }

context "when deleted is not requested" do
it "excludes deleted variants" do
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/orders/payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
end

before do
payment_method.destroy
payment_method.paranoia_destroy
visit spree.admin_order_payments_path(order.reload)
end

Expand Down
2 changes: 1 addition & 1 deletion core/solidus_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |s|
s.add_dependency 'kaminari', '>= 0.17', '< 2.0'
s.add_dependency 'monetize', '~> 1.1'
s.add_dependency 'paperclip', ['>= 4.2', '< 6']
s.add_dependency 'paranoia', '~> 2.3'
s.add_dependency 'paranoia', '~> 2.4'
s.add_dependency 'ransack', '~> 1.8'
s.add_dependency 'state_machines-activerecord', '~> 0.4'
s.add_dependency 'stringex', '~> 1.5.1'
Expand Down
4 changes: 2 additions & 2 deletions core/spec/lib/spree/core/importer/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ module Core
end
end

context 'variant was deleted' do
context 'variant was soft-deleted' do
it 'raise error as variant shouldnt be found' do
variant.product.destroy
variant.product.paranoia_destroy
hash = { sku: variant.sku }
expect {
Importer::Order.ensure_variant_id_from_params(hash)
Expand Down
7 changes: 6 additions & 1 deletion core/spec/models/spree/customer_return_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@
end

it "should NOT raise an error when no stock item exists in the stock location" do
inventory_unit.find_stock_item.destroy
inventory_unit.find_stock_item.really_destroy!
create(:customer_return_without_return_items, return_items: [return_item], stock_location_id: new_stock_location.id)
end

it "should NOT raise an error when a soft-deleted stock item exists in the stock location" do
inventory_unit.find_stock_item.paranoia_destroy
create(:customer_return_without_return_items, return_items: [return_item], stock_location_id: new_stock_location.id)
end

Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module Spree

context "when it cannot create shipments for all items" do
before do
StockItem.where(variant_id: return_item.exchange_variant_id).destroy_all
StockItem.where(variant_id: return_item.exchange_variant_id).each(&:really_destroy!)
end

it 'raises an UnableToCreateShipments error' do
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/line_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

context '#destroy' do
it "fetches deleted products" do
line_item.product.destroy
line_item.product.paranoia_destroy
expect(line_item.reload.product).to be_a Spree::Product
end

it "fetches deleted variants" do
line_item.variant.destroy
line_item.variant.paranoia_destroy
expect(line_item.reload.variant).to be_a Spree::Variant
end

Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
before { Spree::Config.track_inventory_levels = false }

it "creates on hand inventory units" do
variant.stock_items.destroy_all
variant.stock_items.each(&:really_destroy!)

subject.verify(shipment)

Expand All @@ -82,7 +82,7 @@
let(:new_quantity) { 1 }

it "creates on hand inventory units" do
variant.stock_items.destroy_all
variant.stock_items.each(&:really_destroy!)

subject.verify(shipment)

Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
context 'when variant is destroyed' do
before do
allow(order).to receive(:restart_checkout_flow)
order.line_items.first.variant.destroy
order.line_items.first.variant.paranoia_destroy
end

it 'should restart checkout flow' do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@
before do
gateway.save!
payment.save!
gateway.destroy
gateway.paranoia_destroy!
end

it "works with a soft deleted payment method" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/product/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
end

context "with soft-deleted master price" do
before { product.master.prices.destroy_all }
before { product.master.prices.each(&:paranoia_destroy!) }

it "doesn't include the product" do
expect(Spree::Product.available).to match_array([])
Expand Down
14 changes: 7 additions & 7 deletions core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Extension < Spree::Base
context "product has no variants" do
context "#destroy" do
it "should set deleted_at value" do
product.destroy
product.paranoia_destroy
expect(product.deleted_at).not_to be_nil
expect(product.master.reload.deleted_at).not_to be_nil
end
Expand All @@ -127,9 +127,9 @@ class Extension < Spree::Base

context "#destroy" do
it "should set deleted_at value" do
product.destroy
product.paranoia_destroy
expect(product.deleted_at).not_to be_nil
expect(product.variants_including_master.all? { |v| !v.deleted_at.nil? }).to be true
expect(product.variants_including_master).to all(be_paranoia_destroyed)
end
end
end
Expand Down Expand Up @@ -176,8 +176,8 @@ class Extension < Spree::Base
expect(product).not_to be_available
end

it "should not be available if destroyed" do
product.destroy
it "should not be available if soft-destroyed" do
product.paranoia_destroy
expect(product).not_to be_available
end
end
Expand Down Expand Up @@ -292,7 +292,7 @@ class Extension < Spree::Base

it "doesnt raise ReadOnlyRecord error" do
Spree::StockMovement.create!(stock_item: stock_item, quantity: 1)
product.destroy
product.paranoia_destroy
end
end

Expand All @@ -314,7 +314,7 @@ class Extension < Spree::Base

it "renames slug on destroy" do
old_slug = product.slug
product.destroy
product.paranoia_destroy
expect(old_slug).to_not eq product.slug
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
end
end

context "#destroy" do
context "#paranoia_destroy" do
before(:each) do
action.calculator = Spree::Calculator::FlatRate.new(preferred_amount: 10)
promotion.promotion_actions = [action]
Expand All @@ -87,7 +87,7 @@
context "when order is not complete" do
it "should not keep the adjustment" do
action.perform(payload)
action.destroy
action.paranoia_destroy
expect(order.adjustments.count).to eq(0)
end
end
Expand All @@ -99,7 +99,7 @@

before(:each) do
action.perform(payload)
action.destroy
action.paranoia_destroy
end

it "should keep the adjustment" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module Actions
end
end

context "#destroy" do
context "#paranoia_destroy" do
let!(:action) { promotion.actions.first }
let(:other_action) { other_promotion.actions.first }
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
Expand All @@ -153,7 +153,7 @@ module Actions
order.adjustments.create!(label: 'Check', amount: 0, order: order, source: action)

expect {
action.destroy
action.paranoia_destroy
}.to change { Adjustment.count }.by(-1)
end
end
Expand All @@ -167,7 +167,7 @@ module Actions

expect {
expect {
action.destroy
action.paranoia_destroy
}.not_to change { adjustment.reload.source_id }
}.not_to change { Spree::Adjustment.count }

Expand All @@ -179,7 +179,7 @@ module Actions
order.adjustments.create!(label: "Check", amount: 0, order: order, source: action)

expect {
action.destroy
action.paranoia_destroy
}.not_to change { other_action.adjustments.count }
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/return_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
end

context "when the inventory unit's variant does not yet have a stock item for the stock location it was returned to" do
before { inventory_unit.variant.stock_items.destroy_all }
before { inventory_unit.variant.stock_items.each(&:really_destroy!) }

it "creates a new stock item for the inventory unit with a count of 1" do
expect { subject }.to change(Spree::StockItem, :count).by(1)
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
end

context "variant was removed" do
before { variant.destroy }
before { variant.paranoia_destroy }

it "still returns variant expected" do
expect(shipment.manifest.first.variant).to eq variant
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/shipping_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DummyShippingCalculator < Spree::ShippingCalculator
context "soft deletion" do
let(:shipping_method) { create(:shipping_method) }
it "soft-deletes when destroy is called" do
shipping_method.destroy
shipping_method.paranoia_destroy
expect(shipping_method.deleted_at).not_to be_blank
end
end
Expand Down
Loading