solidus_core 2.7.4 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -17
- data/app/assets/images/logo/solidus.svg +18 -0
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +1 -7
- data/app/helpers/spree/taxons_helper.rb +2 -2
- data/app/mailers/spree/carton_mailer.rb +4 -4
- data/app/models/spree/calculator/flat_percent_item_total.rb +4 -1
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +5 -3
- data/app/models/spree/calculator/tiered_percent.rb +2 -1
- data/app/models/spree/country.rb +8 -0
- data/app/models/spree/fulfilment_changer.rb +9 -1
- data/app/models/spree/gallery/product_gallery.rb +18 -0
- data/app/models/spree/gallery/variant_gallery.rb +21 -0
- data/app/models/spree/image.rb +11 -1
- data/app/models/spree/inventory_unit.rb +8 -0
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/order.rb +0 -4
- data/app/models/spree/order_cancellations.rb +31 -10
- data/app/models/spree/order_contents.rb +1 -5
- data/app/models/spree/order_inventory.rb +5 -4
- data/app/models/spree/product.rb +9 -0
- data/app/models/spree/product/scopes.rb +3 -4
- data/app/models/spree/promotion.rb +1 -6
- data/app/models/spree/promotion_handler/coupon.rb +15 -0
- data/app/models/spree/reimbursement.rb +21 -6
- data/app/models/spree/reimbursement_performer.rb +12 -6
- data/app/models/spree/reimbursement_type.rb +1 -1
- data/app/models/spree/reimbursement_type/credit.rb +5 -2
- data/app/models/spree/reimbursement_type/exchange.rb +1 -1
- data/app/models/spree/reimbursement_type/original_payment.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
- data/app/models/spree/reimbursement_type/store_credit.rb +18 -3
- data/app/models/spree/shipment.rb +11 -11
- data/app/models/spree/stock/allocator/base.rb +19 -0
- data/app/models/spree/stock/allocator/on_hand_first.rb +42 -0
- data/app/models/spree/stock/content_item.rb +1 -1
- data/app/models/spree/stock/inventory_units_finalizer.rb +47 -0
- data/app/models/spree/stock/location_sorter/base.rb +38 -0
- data/app/models/spree/stock/location_sorter/default_first.rb +15 -0
- data/app/models/spree/stock/location_sorter/unsorted.rb +14 -0
- data/app/models/spree/stock/simple_coordinator.rb +24 -10
- data/app/models/spree/stock_location.rb +2 -0
- data/app/models/spree/store_credit.rb +4 -12
- data/app/models/spree/store_credit_event.rb +2 -2
- data/app/models/spree/store_credit_reason.rb +11 -0
- data/app/models/spree/taxon.rb +8 -3
- data/app/models/spree/unit_cancel.rb +3 -0
- data/app/models/spree/variant.rb +18 -7
- data/config/initializers/money.rb +5 -0
- data/config/locales/en.yml +661 -527
- data/db/default/spree/store_credit.rb +1 -1
- data/db/default/spree/zones.rb +2 -2
- data/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb +42 -0
- data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +41 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +0 -3
- data/lib/generators/spree/install/install_generator.rb +2 -2
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +2 -2
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/solidus/migrations/promotions_with_code_handlers.rb +66 -0
- data/lib/spree/app_configuration.rb +20 -4
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/stock_configuration.rb +12 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +4 -0
- data/lib/spree/money.rb +13 -11
- data/lib/spree/permission_sets.rb +0 -1
- data/lib/spree/permission_sets/promotion_management.rb +1 -0
- data/lib/spree/testing_support/dummy_app.rb +13 -2
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +5 -5
- data/lib/spree/testing_support/factories/{store_credit_update_reason_factory.rb → store_credit_reason_factory.rb} +1 -1
- data/lib/spree/testing_support/partial_double_verification.rb +13 -0
- data/lib/spree/testing_support/shared_examples/gallery.rb +18 -0
- data/spec/helpers/products_helper_spec.rb +10 -8
- data/spec/helpers/taxons_helper_spec.rb +3 -1
- data/spec/lib/i18n_spec.rb +5 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +6 -2
- data/spec/lib/spree/core/stock_configuration_spec.rb +19 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb +14 -0
- data/spec/lib/spree/money_spec.rb +12 -13
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +136 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +10 -1
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +18 -6
- data/spec/models/spree/calculator/tiered_percent_spec.rb +7 -1
- data/spec/models/spree/country_spec.rb +76 -0
- data/spec/models/spree/customer_return_spec.rb +2 -1
- data/spec/models/spree/fulfilment_changer_spec.rb +33 -0
- data/spec/models/spree/gallery/product_gallery_spec.rb +21 -0
- data/spec/models/spree/gallery/variant_gallery_spec.rb +21 -0
- data/spec/models/spree/inventory_unit_spec.rb +1 -4
- data/spec/models/spree/order/checkout_spec.rb +6 -6
- data/spec/models/spree/order/finalizing_spec.rb +1 -20
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +2 -1
- data/spec/models/spree/order/updating_spec.rb +1 -1
- data/spec/models/spree/order_cancellations_spec.rb +55 -14
- data/spec/models/spree/order_inventory_spec.rb +12 -5
- data/spec/models/spree/order_merger_spec.rb +6 -3
- data/spec/models/spree/order_spec.rb +3 -7
- data/spec/models/spree/order_updater_spec.rb +3 -8
- data/spec/models/spree/payment/cancellation_spec.rb +4 -3
- data/spec/models/spree/payment_spec.rb +1 -17
- data/spec/models/spree/permission_sets/promotion_management_spec.rb +2 -0
- data/spec/models/spree/product_spec.rb +10 -1
- data/spec/models/spree/promotion_handler/coupon_spec.rb +62 -8
- data/spec/models/spree/promotion_spec.rb +24 -10
- data/spec/models/spree/refund_spec.rb +2 -1
- data/spec/models/spree/reimbursement_performer_spec.rb +5 -4
- data/spec/models/spree/reimbursement_spec.rb +26 -2
- data/spec/models/spree/reimbursement_type/credit_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +14 -2
- data/spec/models/spree/return_item_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +20 -13
- data/spec/models/spree/shipping_calculator_spec.rb +13 -3
- data/spec/models/spree/stock/allocator/on_hand_first_spec.rb +146 -0
- data/spec/models/spree/stock/content_item_spec.rb +70 -0
- data/spec/models/spree/stock/estimator_spec.rb +5 -2
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +34 -0
- data/spec/models/spree/stock/location_sorter/default_first_spec.rb +20 -0
- data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +19 -0
- data/spec/models/spree/stock/simple_coordinator_spec.rb +17 -0
- data/spec/models/spree/store_credit_event_spec.rb +12 -12
- data/spec/models/spree/store_credit_spec.rb +2 -2
- data/spec/models/spree/unit_cancel_spec.rb +20 -1
- data/spec/models/spree/variant_spec.rb +46 -24
- data/spec/spec_helper.rb +1 -0
- metadata +30 -9
- data/.yardopts +0 -1
- data/app/models/spree/store_credit_update_reason.rb +0 -4
- data/lib/spree/permission_sets/report_display.rb +0 -11
- data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +0 -14
- data/spec/models/spree/permission_sets/report_display_spec.rb +0 -25
|
@@ -35,12 +35,19 @@ RSpec.describe Spree::OrderInventory, type: :model do
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
context "order is not completed" do
|
|
38
|
-
|
|
38
|
+
let(:inventory_unit_finalizer) { double(:inventory_unit_finalizer, run!: [true]) }
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
before do
|
|
41
|
+
allow(Spree::Stock::InventoryUnitsFinalizer)
|
|
42
|
+
.to receive(:new).and_return(inventory_unit_finalizer)
|
|
43
|
+
|
|
44
|
+
order.update_columns completed_at: nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "doesn't finalize the items" do
|
|
48
|
+
expect(inventory_unit_finalizer).to_not receive(:run!)
|
|
49
|
+
|
|
50
|
+
subject.verify(shipment)
|
|
44
51
|
end
|
|
45
52
|
end
|
|
46
53
|
|
|
@@ -68,7 +68,6 @@ module Spree
|
|
|
68
68
|
context "merging using extension-specific line_item_comparison_hooks" do
|
|
69
69
|
before do
|
|
70
70
|
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
|
71
|
-
allow(Spree::Variant).to receive(:price_modifier_amount).and_return(0.00)
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
after do
|
|
@@ -83,7 +82,9 @@ module Spree
|
|
|
83
82
|
end
|
|
84
83
|
|
|
85
84
|
specify do
|
|
86
|
-
|
|
85
|
+
without_partial_double_verification do
|
|
86
|
+
expect(order_1).to receive(:foos_match).with(@line_item_1, kind_of(Hash)).and_return(true)
|
|
87
|
+
end
|
|
87
88
|
subject.merge!(order_2)
|
|
88
89
|
expect(order_1.line_items.count).to eq(1)
|
|
89
90
|
|
|
@@ -95,7 +96,9 @@ module Spree
|
|
|
95
96
|
|
|
96
97
|
context "2 different line items" do
|
|
97
98
|
before do
|
|
98
|
-
|
|
99
|
+
without_partial_double_verification do
|
|
100
|
+
allow(order_1).to receive(:foos_match).and_return(false)
|
|
101
|
+
end
|
|
99
102
|
|
|
100
103
|
order_1.contents.add(variant, 1, foos: {})
|
|
101
104
|
order_2.contents.add(variant, 1, foos: { bar: :zoo })
|
|
@@ -15,10 +15,6 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
15
15
|
end
|
|
16
16
|
let(:code) { promotion.codes.first }
|
|
17
17
|
|
|
18
|
-
before do
|
|
19
|
-
allow(Spree::LegacyUser).to receive_messages(current: mock_model(Spree::LegacyUser, id: 123))
|
|
20
|
-
end
|
|
21
|
-
|
|
22
18
|
context '#store' do
|
|
23
19
|
it { is_expected.to respond_to(:store) }
|
|
24
20
|
|
|
@@ -324,7 +320,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
324
320
|
end
|
|
325
321
|
end
|
|
326
322
|
|
|
327
|
-
context "add_update_hook" do
|
|
323
|
+
context "add_update_hook", partial_double_verification: false do
|
|
328
324
|
before do
|
|
329
325
|
Spree::Order.class_eval do
|
|
330
326
|
register_update_hook :add_awesome_sauce
|
|
@@ -712,7 +708,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
712
708
|
expect(order.find_line_item_by_variant(mock_model(Spree::Variant))).to be_nil
|
|
713
709
|
end
|
|
714
710
|
|
|
715
|
-
context "match line item with options" do
|
|
711
|
+
context "match line item with options", partial_double_verification: false do
|
|
716
712
|
before do
|
|
717
713
|
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
|
718
714
|
end
|
|
@@ -1072,7 +1068,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
1072
1068
|
|
|
1073
1069
|
context 'an old-style refund exists' do
|
|
1074
1070
|
let(:order) { create(:order_ready_to_ship) }
|
|
1075
|
-
let(:payment) { order.payments.first.tap { |p| allow(p).to receive_messages(profiles_supported
|
|
1071
|
+
let(:payment) { order.payments.first.tap { |p| allow(p).to receive_messages(profiles_supported?: false) } }
|
|
1076
1072
|
let!(:refund_payment) {
|
|
1077
1073
|
build(:payment, amount: -1, order: order, state: 'completed', source: payment).tap do |p|
|
|
1078
1074
|
allow(p).to receive_messages(profiles_supported?: false)
|
|
@@ -513,15 +513,10 @@ module Spree
|
|
|
513
513
|
|
|
514
514
|
it "doesnt update each shipment" do
|
|
515
515
|
shipment = stub_model(Spree::Shipment)
|
|
516
|
-
shipments = [shipment]
|
|
517
|
-
allow(order).to receive_messages
|
|
518
|
-
allow(shipments).to receive_messages states: []
|
|
519
|
-
allow(shipments).to receive_messages ready: []
|
|
520
|
-
allow(shipments).to receive_messages pending: []
|
|
521
|
-
allow(shipments).to receive_messages shipped: []
|
|
522
|
-
|
|
516
|
+
order.shipments = [shipment]
|
|
517
|
+
allow(order.shipments).to receive_messages(states: [], ready: [], pending: [], shipped: [])
|
|
523
518
|
allow(updater).to receive(:update_totals) # Otherwise this gets called and causes a scene
|
|
524
|
-
expect(updater).not_to receive(:update_shipments)
|
|
519
|
+
expect(updater).not_to receive(:update_shipments)
|
|
525
520
|
updater.update
|
|
526
521
|
end
|
|
527
522
|
end
|
|
@@ -63,14 +63,15 @@ RSpec.describe Spree::Payment::Cancellation do
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
context 'if the payment_method does not respond to `try_void`' do
|
|
66
|
+
context 'if the payment_method does not respond to `try_void`', partial_double_verification: false do
|
|
67
67
|
before do
|
|
68
68
|
allow(payment_method).to receive(:respond_to?) { false }
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
allow(payment_method).to receive(:cancel) { double }
|
|
70
|
+
allow(payment).to receive(:handle_void_response)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it 'calls cancel instead' do
|
|
74
|
+
expect(payment_method).to receive(:cancel)
|
|
74
75
|
Spree::Deprecation.silence { subject }
|
|
75
76
|
end
|
|
76
77
|
|
|
@@ -9,7 +9,7 @@ RSpec.describe Spree::Payment, type: :model do
|
|
|
9
9
|
|
|
10
10
|
let(:gateway) do
|
|
11
11
|
gateway = Spree::PaymentMethod::BogusCreditCard.new(active: true, name: 'Bogus gateway')
|
|
12
|
-
allow(gateway).to receive_messages
|
|
12
|
+
allow(gateway).to receive_messages(source_required?: true)
|
|
13
13
|
gateway
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -207,22 +207,6 @@ RSpec.describe Spree::Payment, type: :model do
|
|
|
207
207
|
expect { payment.process! }.to raise_error(Spree::Core::GatewayError)
|
|
208
208
|
expect(payment.state).to eq('invalid')
|
|
209
209
|
end
|
|
210
|
-
|
|
211
|
-
# Regression test for https://github.com/spree/spree/issues/4598
|
|
212
|
-
it "should allow payments with a gateway_customer_profile_id" do
|
|
213
|
-
payment.source.update!(gateway_customer_profile_id: "customer_1", brand: 'visa')
|
|
214
|
-
expect(payment.payment_method.gateway_class).to receive(:supports?).with('visa').and_return(false)
|
|
215
|
-
expect(payment).to receive(:started_processing!)
|
|
216
|
-
payment.process!
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
# Another regression test for https://github.com/spree/spree/issues/4598
|
|
220
|
-
it "should allow payments with a gateway_payment_profile_id" do
|
|
221
|
-
payment.source.update!(gateway_payment_profile_id: "customer_1", brand: 'visa')
|
|
222
|
-
expect(payment.payment_method.gateway_class).to receive(:supports?).with('visa').and_return(false)
|
|
223
|
-
expect(payment).to receive(:started_processing!)
|
|
224
|
-
payment.process!
|
|
225
|
-
end
|
|
226
210
|
end
|
|
227
211
|
|
|
228
212
|
describe "#authorize!" do
|
|
@@ -16,6 +16,7 @@ RSpec.describe Spree::PermissionSets::PromotionManagement do
|
|
|
16
16
|
it { is_expected.to be_able_to(:manage, Spree::PromotionRule) }
|
|
17
17
|
it { is_expected.to be_able_to(:manage, Spree::PromotionAction) }
|
|
18
18
|
it { is_expected.to be_able_to(:manage, Spree::PromotionCategory) }
|
|
19
|
+
it { is_expected.to be_able_to(:manage, Spree::PromotionCode) }
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
context "when not activated" do
|
|
@@ -23,5 +24,6 @@ RSpec.describe Spree::PermissionSets::PromotionManagement do
|
|
|
23
24
|
it { is_expected.not_to be_able_to(:manage, Spree::PromotionRule) }
|
|
24
25
|
it { is_expected.not_to be_able_to(:manage, Spree::PromotionAction) }
|
|
25
26
|
it { is_expected.not_to be_able_to(:manage, Spree::PromotionCategory) }
|
|
27
|
+
it { is_expected.not_to be_able_to(:manage, Spree::PromotionCode) }
|
|
26
28
|
end
|
|
27
29
|
end
|
|
@@ -27,7 +27,7 @@ RSpec.describe Spree::Product, type: :model do
|
|
|
27
27
|
expect(clone.images.size).to eq(product.images.size)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it 'calls #duplicate_extra' do
|
|
30
|
+
it 'calls #duplicate_extra', partial_double_verification: false do
|
|
31
31
|
expect_any_instance_of(Spree::Product).to receive(:duplicate_extra) do |product, old_product|
|
|
32
32
|
product.name = old_product.name.reverse
|
|
33
33
|
end
|
|
@@ -572,4 +572,13 @@ RSpec.describe Spree::Product, type: :model do
|
|
|
572
572
|
end
|
|
573
573
|
end
|
|
574
574
|
end
|
|
575
|
+
|
|
576
|
+
describe '#gallery' do
|
|
577
|
+
let(:product) { Spree::Product.new }
|
|
578
|
+
subject { product.gallery }
|
|
579
|
+
|
|
580
|
+
it 'responds to #images' do
|
|
581
|
+
expect(subject).to respond_to(:images)
|
|
582
|
+
end
|
|
583
|
+
end
|
|
575
584
|
end
|
|
@@ -42,18 +42,34 @@ module Spree
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
describe "#set_error_code" do
|
|
45
|
-
let(:status) { :coupon_code_not_found }
|
|
46
|
-
|
|
47
45
|
subject { coupon.set_error_code status }
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
context 'not found' do
|
|
48
|
+
let(:status) { :coupon_code_not_found }
|
|
49
|
+
|
|
50
|
+
it 'has status_code' do
|
|
51
|
+
subject
|
|
52
|
+
expect(coupon.status_code).to eq(status)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'has error message' do
|
|
56
|
+
subject
|
|
57
|
+
expect(coupon.error).to eq(I18n.t(status, scope: 'spree'))
|
|
58
|
+
end
|
|
52
59
|
end
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
context 'not present' do
|
|
62
|
+
let(:status) { :coupon_code_not_present }
|
|
63
|
+
|
|
64
|
+
it 'has status_code' do
|
|
65
|
+
subject
|
|
66
|
+
expect(coupon.status_code).to eq(status)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'has error message' do
|
|
70
|
+
subject
|
|
71
|
+
expect(coupon.error).to eq(I18n.t(status, scope: 'spree'))
|
|
72
|
+
end
|
|
57
73
|
end
|
|
58
74
|
end
|
|
59
75
|
end
|
|
@@ -360,6 +376,44 @@ module Spree
|
|
|
360
376
|
end
|
|
361
377
|
end
|
|
362
378
|
end
|
|
379
|
+
|
|
380
|
+
context 'removing a coupon code from an order' do
|
|
381
|
+
let!(:promotion) { promotion_code.promotion }
|
|
382
|
+
let(:promotion_code) { create(:promotion_code, value: '10off') }
|
|
383
|
+
let!(:action) { Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
|
|
384
|
+
let(:calculator) { Calculator::FlatRate.new(preferred_amount: 10) }
|
|
385
|
+
let(:order) { create(:order_with_line_items, line_items_count: 3) }
|
|
386
|
+
|
|
387
|
+
context 'with an already applied coupon' do
|
|
388
|
+
before do
|
|
389
|
+
order.coupon_code = '10off'
|
|
390
|
+
subject.apply
|
|
391
|
+
order.reload
|
|
392
|
+
expect(order.total).to eq(100)
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it 'successfully removes the coupon code from the order' do
|
|
396
|
+
subject.remove
|
|
397
|
+
expect(subject.error).to eq nil
|
|
398
|
+
expect(subject.success).to eq I18n.t('spree.coupon_code_removed')
|
|
399
|
+
expect(order.reload.total).to eq(130)
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
context 'with a coupon code not applied to an order' do
|
|
404
|
+
before do
|
|
405
|
+
order.coupon_code = '10off'
|
|
406
|
+
expect(order.total).to eq(130)
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
it 'returns an error' do
|
|
410
|
+
subject.remove
|
|
411
|
+
expect(subject.success).to eq nil
|
|
412
|
+
expect(subject.error).to eq I18n.t('spree.coupon_code_not_present')
|
|
413
|
+
expect(order.reload.total).to eq(130)
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
end
|
|
363
417
|
end
|
|
364
418
|
end
|
|
365
419
|
end
|
|
@@ -49,6 +49,19 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
describe ".coupons" do
|
|
53
|
+
let(:promotion_code) { create(:promotion_code) }
|
|
54
|
+
let!(:promotion_with_code) { promotion_code.promotion }
|
|
55
|
+
let!(:another_promotion_code) { create(:promotion_code, promotion: promotion_with_code) }
|
|
56
|
+
let!(:promotion_without_code) { create(:promotion) }
|
|
57
|
+
|
|
58
|
+
subject { described_class.coupons }
|
|
59
|
+
|
|
60
|
+
it "returns only distinct promotions with a code associated" do
|
|
61
|
+
expect(subject).to eq [promotion_with_code]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
52
65
|
describe "#apply_automatically" do
|
|
53
66
|
subject { build(:promotion) }
|
|
54
67
|
|
|
@@ -632,15 +645,16 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
632
645
|
end
|
|
633
646
|
|
|
634
647
|
context "with 'any' match policy" do
|
|
635
|
-
let(:promotion) { Spree::Promotion.create(name: "Promo", match_policy: 'any') }
|
|
636
648
|
let(:promotable) { double('Promotable') }
|
|
637
649
|
|
|
650
|
+
before do
|
|
651
|
+
promotion.match_policy = 'any'
|
|
652
|
+
end
|
|
653
|
+
|
|
638
654
|
it "should have eligible rules if any of the rules are eligible" do
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
allow(
|
|
642
|
-
allow(promotion).to receive_messages(rules: [true_rule])
|
|
643
|
-
allow(promotion).to receive_message_chain(:rules, :for).and_return([true_rule])
|
|
655
|
+
true_rule = mock_model(Spree::PromotionRule, eligible?: true, applicable?: true)
|
|
656
|
+
promotion.promotion_rules = [true_rule]
|
|
657
|
+
allow(promotion.rules).to receive(:for) { promotion.rules }
|
|
644
658
|
expect(promotion.eligible_rules(promotable)).to eq [true_rule]
|
|
645
659
|
end
|
|
646
660
|
|
|
@@ -668,13 +682,13 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
668
682
|
describe '#line_item_actionable?' do
|
|
669
683
|
let(:order) { double Spree::Order }
|
|
670
684
|
let(:line_item) { double Spree::LineItem }
|
|
671
|
-
let(:true_rule) {
|
|
672
|
-
let(:false_rule) {
|
|
685
|
+
let(:true_rule) { mock_model Spree::PromotionRule, eligible?: true, applicable?: true, actionable?: true }
|
|
686
|
+
let(:false_rule) { mock_model Spree::PromotionRule, eligible?: true, applicable?: true, actionable?: false }
|
|
673
687
|
let(:rules) { [] }
|
|
674
688
|
|
|
675
689
|
before do
|
|
676
|
-
|
|
677
|
-
allow(rules).to receive(:for) { rules }
|
|
690
|
+
promotion.promotion_rules = rules
|
|
691
|
+
allow(promotion.rules).to receive(:for) { rules }
|
|
678
692
|
end
|
|
679
693
|
|
|
680
694
|
subject { promotion.line_item_actionable? order, line_item }
|
|
@@ -176,11 +176,12 @@ RSpec.describe Spree::Refund, type: :model do
|
|
|
176
176
|
let(:customer_return) { reimbursement.customer_return }
|
|
177
177
|
let(:reimbursement) { create(:reimbursement) }
|
|
178
178
|
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
|
179
|
+
let(:created_by_user) { create(:user, email: 'user@email.com') }
|
|
179
180
|
|
|
180
181
|
subject { Spree::Refund.total_amount_reimbursed_for(reimbursement) }
|
|
181
182
|
|
|
182
183
|
context 'with reimbursements performed' do
|
|
183
|
-
before { reimbursement.perform! }
|
|
184
|
+
before { reimbursement.perform!(created_by: created_by_user) }
|
|
184
185
|
|
|
185
186
|
it 'returns the total amount' do
|
|
186
187
|
amount = Spree::Refund.total_amount_reimbursed_for(reimbursement)
|
|
@@ -7,25 +7,26 @@ RSpec.describe Spree::ReimbursementPerformer, type: :model do
|
|
|
7
7
|
let(:return_item) { reimbursement.return_items.first }
|
|
8
8
|
let(:reimbursement_type) { double("ReimbursementType") }
|
|
9
9
|
let(:reimbursement_type_hash) { { reimbursement_type => [return_item] } }
|
|
10
|
+
let(:created_by_user) { create(:user, email: 'user@email.com') }
|
|
10
11
|
|
|
11
12
|
before do
|
|
12
13
|
expect(Spree::ReimbursementPerformer).to receive(:calculate_reimbursement_types).and_return(reimbursement_type_hash)
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
describe ".simulate" do
|
|
16
|
-
subject { Spree::ReimbursementPerformer.simulate(reimbursement) }
|
|
17
|
+
subject { Spree::ReimbursementPerformer.simulate(reimbursement, created_by: created_by_user) }
|
|
17
18
|
|
|
18
19
|
it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
|
|
19
|
-
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true)
|
|
20
|
+
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true, created_by: created_by_user)
|
|
20
21
|
subject
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
describe '.perform' do
|
|
25
|
-
subject { Spree::ReimbursementPerformer.perform(reimbursement) }
|
|
26
|
+
subject { Spree::ReimbursementPerformer.perform(reimbursement, created_by: created_by_user) }
|
|
26
27
|
|
|
27
28
|
it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
|
|
28
|
-
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false)
|
|
29
|
+
expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false, created_by: created_by_user)
|
|
29
30
|
subject
|
|
30
31
|
end
|
|
31
32
|
end
|
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
require 'rails_helper'
|
|
4
4
|
|
|
5
5
|
RSpec.describe Spree::Reimbursement, type: :model do
|
|
6
|
+
describe ".create" do
|
|
7
|
+
let(:customer_return) { create(:customer_return) }
|
|
8
|
+
let(:order) { customer_return.order }
|
|
9
|
+
let(:reimbursement) { build(:reimbursement, order: order) }
|
|
10
|
+
|
|
11
|
+
subject { reimbursement.save }
|
|
12
|
+
|
|
13
|
+
context "when total is not present" do
|
|
14
|
+
before do
|
|
15
|
+
allow(reimbursement).to receive(:calculated_total) { 100 }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it { expect { subject }.to change(reimbursement, :total).from(nil).to(100.0) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "when total is present" do
|
|
22
|
+
let(:reimbursement) { build(:reimbursement, order: order, total: 10) }
|
|
23
|
+
|
|
24
|
+
it { expect { subject }.not_to change(reimbursement, :total).from(10) }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
6
28
|
describe ".before_create" do
|
|
7
29
|
describe "#generate_number" do
|
|
8
30
|
context "number is assigned" do
|
|
@@ -66,8 +88,9 @@ RSpec.describe Spree::Reimbursement, type: :model do
|
|
|
66
88
|
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
|
67
89
|
|
|
68
90
|
let(:reimbursement) { create(:reimbursement, customer_return: customer_return, order: order, return_items: [return_item]) }
|
|
91
|
+
let(:created_by_user) { create(:user, email: 'user@email.com') }
|
|
69
92
|
|
|
70
|
-
subject { reimbursement.perform! }
|
|
93
|
+
subject { reimbursement.perform!(created_by: created_by_user) }
|
|
71
94
|
|
|
72
95
|
before do
|
|
73
96
|
order.shipments.each do |shipment|
|
|
@@ -230,13 +253,14 @@ RSpec.describe Spree::Reimbursement, type: :model do
|
|
|
230
253
|
end
|
|
231
254
|
|
|
232
255
|
describe "#return_all" do
|
|
233
|
-
subject { reimbursement.return_all }
|
|
256
|
+
subject { reimbursement.return_all(created_by: created_by_user) }
|
|
234
257
|
|
|
235
258
|
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
|
|
236
259
|
let(:order) { create(:shipped_order, line_items_count: 1) }
|
|
237
260
|
let(:inventory_unit) { order.inventory_units.first }
|
|
238
261
|
let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }
|
|
239
262
|
let(:reimbursement) { build(:reimbursement, order: order, return_items: [return_item]) }
|
|
263
|
+
let(:created_by_user) { create(:user, email: 'user@email.com') }
|
|
240
264
|
|
|
241
265
|
it "accepts all the return items" do
|
|
242
266
|
expect { subject }.to change { return_item.acceptance_status }.to "accepted"
|