Skip to content

Commit

Permalink
Merge pull request #3488 from nebulab/remove-paranoia
Browse files Browse the repository at this point in the history
Discard Paranoia
  • Loading branch information
kennyadsl committed Jan 29, 2021
2 parents dc813e6 + df54786 commit b0092d0
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 113 deletions.
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 @@ -95,7 +95,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.all.each(&:really_destroy!)
Spree::ShippingMethod.all.each(&:destroy)
put spree.api_checkout_path(order),
params: { order_token: order.guest_token, order: {
bill_address_attributes: address,
Expand Down
2 changes: 0 additions & 2 deletions backend/app/controllers/spree/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def destroy
destroy_result =
if @object.respond_to?(:discard)
@object.discard
elsif @object.respond_to?(:paranoia_destroy)
@object.paranoia_destroy
else
@object.destroy
end
Expand Down
6 changes: 2 additions & 4 deletions core/app/models/concerns/spree/soft_deletable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ module SoftDeletable
extend ActiveSupport::Concern

included do
acts_as_paranoid
include Spree::ParanoiaDeprecations::InstanceMethods
extend Spree::ParanoiaDeprecations::ClassMethods

include Discard::Model
self.discard_column = :deleted_at

default_scope { kept }
end
end
end
4 changes: 0 additions & 4 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module Spree
# variations, called variants. Product properties include description,
# permalink, availability, shipping category, etc. that do not change by
# variant.
#
# @note this model uses {https://github.com/radar/paranoia paranoia}.
# +#destroy+ will only soft-destroy records and the default scope hides
# soft-destroyed records using +WHERE deleted_at IS NULL+.
class Product < Spree::Base
extend FriendlyId
friendly_id :slug_candidates, use: :history
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Variant < Spree::Base
after_save :clear_in_stock_cache
after_touch :clear_in_stock_cache

after_real_destroy :destroy_option_values_variants
after_destroy :destroy_option_values_variants

# Returns variants that are in stock. When stock locations are provided as
# a parameter, the scope is limited to variants that are in stock in the
Expand Down
2 changes: 0 additions & 2 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
require 'mail'
require 'monetize'
require 'paperclip'
require 'paranoia'
require 'ransack'
require 'state_machines-activerecord'

require 'spree/deprecation'
require 'spree/paranoia_deprecations'

# This is required because ActiveModel::Validations#invalid? conflicts with the
# invalid state of a Payment. In the future this should be removed.
Expand Down
41 changes: 0 additions & 41 deletions core/lib/spree/paranoia_deprecations.rb

This file was deleted.

1 change: 0 additions & 1 deletion core/solidus_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Gem::Specification.new do |s|
s.add_dependency 'mini_magick', '~> 4.10'
s.add_dependency 'monetize', '~> 1.8'
s.add_dependency 'paperclip', '>= 4.2'
s.add_dependency 'paranoia', '~> 2.4'
s.add_dependency 'ransack', '~> 2.0'
s.add_dependency 'state_machines-activerecord', '~> 0.6'
end
5 changes: 0 additions & 5 deletions core/spec/models/spree/concerns/soft_deletable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
end
end

it 'includes Paranoia' do
expect(Post).to respond_to(:with_deleted)
expect(Post.new).to respond_to(:deleted?)
end

it 'includes Discard' do
expect(Post).to respond_to(:with_discarded)
expect(Post.new).to respond_to(:discarded?)
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/customer_return_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
end

it "should NOT raise an error when no stock item exists in the stock location" do
inventory_unit.find_stock_item.really_destroy!
inventory_unit.find_stock_item.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 @@ -54,7 +54,7 @@ module Spree

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

it 'raises an UnableToCreateShipments error' do
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 @@ -75,7 +75,7 @@
before { stub_spree_preferences(track_inventory_levels: false) }

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

subject.verify(shipment)

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

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

subject.verify(shipment)

Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/order_merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ module Spree
end

it "should create errors with invalid line items" do
allow(order_2.line_items.first).to receive(:variant) { nil }
order_2.line_items.first.variant.destroy
order_2.line_items.reload # so that it registers as invalid
subject.merge!(order_2)
expect(order_1.errors.full_messages).not_to be_empty
end
Expand Down
13 changes: 0 additions & 13 deletions core/spec/models/spree/promotion/actions/create_adjustment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,4 @@
subject { action.discard }
it_should_behave_like "destroying adjustments from incomplete orders"
end

context "#paranoia_destroy" do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Calling #destroy \(or #paranoia_destroy\) on a .* currently/, any_args)
expect(Spree::Deprecation).to receive(:warn).
with(/^Calling #delete \(or #paranoia_delete\) on a .* currently/, any_args)
end

subject { action.paranoia_destroy }

it_should_behave_like "destroying adjustments from incomplete orders"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,5 @@ module Spree
subject { action.discard }
it_should_behave_like "destroying adjustments from incomplete orders"
end

describe "#paranoia_destroy" do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Calling #destroy \(or #paranoia_destroy\) on a .* currently/, any_args)
expect(Spree::Deprecation).to receive(:warn).
with(/^Calling #delete \(or #paranoia_delete\) on a .* currently/, any_args)
end

subject { action.paranoia_destroy }

it_should_behave_like "destroying adjustments from incomplete orders"
end
end
end
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 @@ -114,7 +114,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.each(&:really_destroy!) }
before { inventory_unit.variant.stock_items.each(&: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
4 changes: 2 additions & 2 deletions core/spec/models/spree/stock/availability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Spree::Stock
end

context 'with no stock_item' do
before { stock_item.really_destroy! }
before { stock_item.destroy! }

it "returns empty hash" do
expect(subject).to eq({})
Expand Down Expand Up @@ -133,7 +133,7 @@ module Spree::Stock
end

context 'with no stock_item' do
before { stock_item.really_destroy! }
before { stock_item.destroy }

it { is_expected.to eq({}) }
end
Expand Down
8 changes: 4 additions & 4 deletions core/spec/models/spree/stock/estimator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Stock
end

it "sorts shipping rates by cost" do
ShippingMethod.all.each(&:really_destroy!)
ShippingMethod.all.each(&:destroy)
create(:shipping_method, cost: 5)
create(:shipping_method, cost: 3)
create(:shipping_method, cost: 4)
Expand All @@ -94,7 +94,7 @@ module Stock
end

context "general shipping methods" do
before { Spree::ShippingMethod.all.each(&:really_destroy!) }
before { Spree::ShippingMethod.all.each(&:destroy) }

context 'with two shipping methods of different cost' do
let!(:shipping_methods) do
Expand Down Expand Up @@ -127,7 +127,7 @@ module Stock
end

context "involves backend only shipping methods" do
before{ Spree::ShippingMethod.all.each(&:really_destroy!) }
before{ Spree::ShippingMethod.all.each(&:destroy) }
let!(:backend_method) { create(:shipping_method, available_to_users: false, cost: 0.00) }
let!(:generic_method) { create(:shipping_method, cost: 5.00) }

Expand All @@ -142,7 +142,7 @@ module Stock
end

context "excludes shipping methods from other stores" do
before{ Spree::ShippingMethod.all.each(&:really_destroy!) }
before{ Spree::ShippingMethod.all.each(&:destroy) }

let!(:other_method) do
create(
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/stock/simple_coordinator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module Stock

context 'with no stock locations' do
let(:location_1_inventory) { 0 }
before { variant.stock_items.each(&:really_destroy!) }
before { variant.stock_items.destroy_all }
it_behaves_like "an unfulfillable package"
end

Expand Down
7 changes: 4 additions & 3 deletions core/spec/models/spree/stock_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module Spree
describe '#stock_item_or_create' do
before do
variant = create(:variant)
variant.stock_items.each(&:really_destroy!)
variant.stock_items.destroy_all
variant.save
end

Expand Down Expand Up @@ -215,7 +215,7 @@ module Spree

it 'zero on_hand and backordered' do
subject
variant.stock_items.each(&:really_destroy!)
variant.stock_items.destroy_all
on_hand, backordered = subject.fill_status(variant, 1)
expect(on_hand).to eq 0
expect(backordered).to eq 0
Expand Down Expand Up @@ -262,7 +262,8 @@ def move
end

context "no stock item exists" do
before { subject.stock_items.each(&:really_destroy!) }
before { subject.stock_items.destroy_all }

context "positive movement" do
let(:quantity) { 1 }
it "creates a stock item" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/variant/vat_price_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# We need to remove the price for FR from the database so it is created in memory, and then run VatPriceGenerator twice to trigger the duplicate price issue.
it "will not build duplicate prices on multiple runs" do
variant.prices.where(country_iso: "FR").each(&:really_destroy!)
variant.prices.where(country_iso: "FR").each(&:destroy)
variant.reload
described_class.new(variant).run
expect { subject }.not_to change { variant.prices.size }
Expand Down
9 changes: 1 addition & 8 deletions core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,7 @@
context "and a variant is really deleted" do
let!(:old_option_values_variant_ids) { variant.option_values_variants.pluck(:id) }

before do
allow(Spree::Deprecation).to receive(:warn).
with(/^.*\.with_deleted has been deprecated/, any_args)

# #really_destroy! will be replaced here with #destroy when Paranoia
# will be removed in Solidus 3.0
variant.really_destroy!
end
before { variant.destroy }

it "leaves no stale records behind" do
expect(old_option_values_variant_ids).to be_present
Expand Down
2 changes: 1 addition & 1 deletion frontend/spec/features/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
end

context "user has payment sources", js: true do
before { Spree::PaymentMethod.all.each(&:really_destroy!) }
before { Spree::PaymentMethod.all.each(&:destroy) }
let!(:bogus) { create(:credit_card_payment_method) }
let(:user) { create(:user) }

Expand Down

0 comments on commit b0092d0

Please sign in to comment.