solidus_core 2.9.5 → 2.10.2
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/app/helpers/spree/base_helper.rb +4 -4
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
- data/app/models/concerns/spree/user_address_book.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +13 -17
- data/app/models/spree/adjustment.rb +20 -9
- data/app/models/spree/asset.rb +1 -1
- data/app/models/spree/base.rb +0 -2
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/calculator/price_sack.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
- data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
- data/app/models/spree/calculator/tiered_percent.rb +6 -6
- data/app/models/spree/carton.rb +3 -3
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/credit_card.rb +4 -4
- data/app/models/spree/customer_return.rb +1 -1
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/inventory_unit.rb +5 -23
- data/app/models/spree/line_item.rb +4 -4
- data/app/models/spree/line_item_action.rb +2 -2
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/option_values_variant.rb +2 -2
- data/app/models/spree/order.rb +11 -27
- data/app/models/spree/order/checkout.rb +1 -1
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order_cancellations.rb +1 -1
- data/app/models/spree/order_capturing.rb +2 -2
- data/app/models/spree/order_contents.rb +2 -2
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_promotion.rb +3 -3
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_taxation.rb +3 -3
- data/app/models/spree/payment.rb +8 -45
- data/app/models/spree/payment/processing.rb +3 -3
- data/app/models/spree/payment_capture_event.rb +1 -1
- data/app/models/spree/payment_method.rb +5 -2
- data/app/models/spree/payment_method/bogus_credit_card.rb +1 -1
- data/app/models/spree/payment_source.rb +1 -1
- data/app/models/spree/price.rb +2 -2
- data/app/models/spree/product.rb +5 -5
- data/app/models/spree/product/scopes.rb +218 -210
- data/app/models/spree/product_option_type.rb +2 -2
- data/app/models/spree/product_promotion_rule.rb +2 -2
- data/app/models/spree/product_property.rb +2 -2
- data/app/models/spree/promotion.rb +28 -13
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion_action.rb +2 -2
- data/app/models/spree/promotion_chooser.rb +2 -2
- data/app/models/spree/promotion_code.rb +11 -10
- data/app/models/spree/promotion_code/batch_builder.rb +3 -3
- data/app/models/spree/promotion_code_batch.rb +1 -1
- data/app/models/spree/promotion_rule.rb +2 -2
- data/app/models/spree/promotion_rule_role.rb +2 -2
- data/app/models/spree/promotion_rule_store.rb +2 -2
- data/app/models/spree/promotion_rule_taxon.rb +2 -2
- data/app/models/spree/promotion_rule_user.rb +2 -2
- data/app/models/spree/refund.rb +5 -5
- data/app/models/spree/reimbursement.rb +5 -13
- data/app/models/spree/reimbursement/credit.rb +2 -2
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
- data/app/models/spree/return_authorization.rb +4 -10
- data/app/models/spree/return_item.rb +13 -52
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/role_user.rb +2 -2
- data/app/models/spree/shipment.rb +7 -41
- data/app/models/spree/shipping_calculator.rb +0 -4
- data/app/models/spree/shipping_manifest.rb +3 -3
- data/app/models/spree/shipping_method.rb +2 -2
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_method_stock_location.rb +2 -2
- data/app/models/spree/shipping_method_zone.rb +2 -2
- data/app/models/spree/shipping_rate.rb +2 -2
- data/app/models/spree/shipping_rate_tax.rb +2 -2
- data/app/models/spree/state.rb +2 -2
- data/app/models/spree/state_change.rb +2 -2
- data/app/models/spree/stock/differentiator.rb +1 -1
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/stock_quantities.rb +13 -12
- data/app/models/spree/store_credit.rb +8 -8
- data/app/models/spree/store_credit_event.rb +3 -3
- data/app/models/spree/store_payment_method.rb +2 -2
- data/app/models/spree/store_shipping_method.rb +2 -2
- data/app/models/spree/tax_calculator/default.rb +0 -4
- data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
- data/app/models/spree/tax_rate.rb +5 -1
- data/app/models/spree/tax_rate_tax_category.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
- data/app/models/spree/unit_cancel.rb +5 -2
- data/app/models/spree/user_address.rb +2 -2
- data/app/models/spree/user_last_url_storer.rb +46 -0
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
- data/app/models/spree/user_stock_location.rb +2 -2
- data/app/models/spree/variant.rb +10 -10
- data/app/models/spree/variant/scopes.rb +37 -29
- data/app/models/spree/variant_property_rule.rb +1 -1
- data/app/models/spree/variant_property_rule_condition.rb +2 -2
- data/app/models/spree/variant_property_rule_value.rb +2 -2
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +2 -2
- data/app/models/spree/zone.rb +1 -1
- data/app/models/spree/zone_member.rb +2 -2
- data/config/initializers/inflections.rb +5 -0
- data/config/initializers/money.rb +2 -0
- data/config/locales/en.yml +34 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
- data/lib/spree/app_configuration.rb +18 -3
- data/lib/spree/core.rb +12 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -13
- data/lib/spree/core/controller_helpers/strong_parameters.rb +21 -7
- data/lib/spree/core/engine.rb +2 -2
- data/lib/spree/core/importer/order.rb +29 -28
- data/lib/spree/core/importer/product.rb +2 -2
- data/lib/spree/core/product_filters.rb +15 -15
- data/lib/spree/core/role_configuration.rb +2 -2
- data/lib/spree/core/search/variant.rb +1 -1
- data/lib/spree/core/state_machines.rb +78 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
- data/lib/spree/core/state_machines/payment.rb +61 -0
- data/lib/spree/core/state_machines/reimbursement.rb +33 -0
- data/lib/spree/core/state_machines/return_authorization.rb +32 -0
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/lib/spree/core/state_machines/shipment.rb +58 -0
- data/lib/spree/core/stock_configuration.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -8
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +2 -2
- data/lib/spree/permission_sets/default_customer.rb +1 -1
- data/lib/spree/permission_sets/user_management.rb +3 -0
- data/lib/spree/permitted_attributes.rb +78 -9
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +4 -1
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +6 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -1
- data/solidus_core.gemspec +6 -6
- data/spec/lib/search/base_spec.rb +5 -1
- data/spec/lib/search/variant_spec.rb +1 -1
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +8 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
- data/spec/lib/spree/core/validators/email_spec.rb +18 -18
- data/spec/lib/spree/event_spec.rb +15 -3
- data/spec/lib/spree/permitted_attributes_spec.rb +41 -0
- data/spec/models/spree/ability_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +23 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
- data/spec/models/spree/carton_spec.rb +10 -2
- data/spec/models/spree/classification_spec.rb +21 -9
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/concerns/user_methods_spec.rb +5 -4
- data/spec/models/spree/credit_card_spec.rb +2 -2
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +1 -1
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +5 -5
- data/spec/models/spree/order/payment_spec.rb +1 -1
- data/spec/models/spree/order_contents_spec.rb +1 -1
- data/spec/models/spree/order_inventory_spec.rb +3 -3
- data/spec/models/spree/order_merger_spec.rb +3 -3
- data/spec/models/spree/order_shipping_spec.rb +1 -1
- data/spec/models/spree/order_spec.rb +14 -21
- data/spec/models/spree/order_updater_spec.rb +4 -3
- data/spec/models/spree/payment_create_spec.rb +6 -16
- data/spec/models/spree/payment_spec.rb +12 -12
- data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
- data/spec/models/spree/preference_spec.rb +4 -4
- data/spec/models/spree/preferences/preferable_spec.rb +3 -3
- data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/taxon_spec.rb +1 -0
- data/spec/models/spree/promotion_rule_spec.rb +6 -6
- data/spec/models/spree/promotion_spec.rb +71 -54
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +3 -3
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
- data/spec/models/spree/return_item_spec.rb +11 -11
- data/spec/models/spree/returns_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +6 -6
- data/spec/models/spree/shipping_calculator_spec.rb +1 -13
- data/spec/models/spree/shipping_method_spec.rb +32 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
- data/spec/models/spree/stock/differentiator_spec.rb +2 -2
- data/spec/models/spree/stock/estimator_spec.rb +3 -3
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +4 -4
- data/spec/models/spree/stock/package_spec.rb +28 -28
- data/spec/models/spree/stock/quantifier_spec.rb +2 -2
- data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
- data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
- data/spec/models/spree/stock_quantities_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +8 -8
- data/spec/models/spree/tax_category_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +1 -0
- data/spec/models/spree/taxon_spec.rb +2 -2
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
- data/spec/models/spree/unit_cancel_spec.rb +5 -0
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
- data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
- data/spec/models/spree/user_spec.rb +3 -3
- metadata +46 -39
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -148
- data/spec/models/spree/order/updating_spec.rb +0 -18
|
@@ -17,13 +17,13 @@ module Spree
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "validates unique rules for a promotion" do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
promotion_one = TestRule.new
|
|
21
|
+
promotion_one.promotion_id = 1
|
|
22
|
+
promotion_one.save
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(
|
|
24
|
+
promotion_two = TestRule.new
|
|
25
|
+
promotion_two.promotion_id = 1
|
|
26
|
+
expect(promotion_two).not_to be_valid
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "generates its own partial path" do
|
|
@@ -434,12 +434,12 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
434
434
|
end
|
|
435
435
|
|
|
436
436
|
context 'when expires_at date is not already reached' do
|
|
437
|
-
let(:expires_at) { Time.current + 1.
|
|
437
|
+
let(:expires_at) { Time.current + 1.day }
|
|
438
438
|
it { is_expected.to be_falsey }
|
|
439
439
|
end
|
|
440
440
|
|
|
441
441
|
context 'when expires_at date is in the past' do
|
|
442
|
-
let(:expires_at) { Time.current - 1.
|
|
442
|
+
let(:expires_at) { Time.current - 1.day }
|
|
443
443
|
it { is_expected.to be_truthy }
|
|
444
444
|
end
|
|
445
445
|
end
|
|
@@ -454,12 +454,12 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
454
454
|
end
|
|
455
455
|
|
|
456
456
|
context 'when expires_at date is not already reached' do
|
|
457
|
-
let(:expires_at) { Time.current + 1.
|
|
457
|
+
let(:expires_at) { Time.current + 1.day }
|
|
458
458
|
it { is_expected.to be_truthy }
|
|
459
459
|
end
|
|
460
460
|
|
|
461
461
|
context 'when expires_at date is in the past' do
|
|
462
|
-
let(:expires_at) { Time.current - 1.
|
|
462
|
+
let(:expires_at) { Time.current - 1.day }
|
|
463
463
|
it { is_expected.to be_falsey }
|
|
464
464
|
end
|
|
465
465
|
end
|
|
@@ -569,80 +569,69 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
569
569
|
|
|
570
570
|
context "#eligible?" do
|
|
571
571
|
subject do
|
|
572
|
-
promotion.eligible?(promotable)
|
|
572
|
+
promotion.eligible?(promotable, promotion_code: promotion.codes.first)
|
|
573
573
|
end
|
|
574
574
|
|
|
575
|
-
|
|
575
|
+
shared_examples "a promotable" do
|
|
576
|
+
context "when empty" do
|
|
577
|
+
it { is_expected.to be true }
|
|
578
|
+
end
|
|
576
579
|
|
|
577
|
-
|
|
580
|
+
context "when promotion is expired" do
|
|
581
|
+
before { promotion.expires_at = Time.current - 10.days }
|
|
578
582
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
it { is_expected.to be false }
|
|
582
|
-
end
|
|
583
|
+
it { is_expected.to be false }
|
|
584
|
+
end
|
|
583
585
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
586
|
+
context "when promotion's usage limit is exceeded" do
|
|
587
|
+
before do
|
|
588
|
+
promotion.usage_limit = 1
|
|
589
|
+
create(:completed_order_with_promotion, promotion: promotion)
|
|
590
|
+
end
|
|
587
591
|
|
|
588
|
-
|
|
589
|
-
FactoryBot.create(
|
|
590
|
-
:completed_order_with_promotion,
|
|
591
|
-
promotion: promotion
|
|
592
|
-
)
|
|
593
|
-
promotion.usage_limit = 1
|
|
592
|
+
it { is_expected.to be false }
|
|
594
593
|
end
|
|
595
594
|
|
|
596
|
-
|
|
597
|
-
|
|
595
|
+
context "when promotion code's usage limit is exceeded" do
|
|
596
|
+
before do
|
|
597
|
+
promotion.per_code_usage_limit = 1
|
|
598
|
+
create(:completed_order_with_promotion, promotion: promotion)
|
|
599
|
+
promotion.codes.first.adjustments.update_all(eligible: true)
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
it { is_expected.to be false }
|
|
598
603
|
end
|
|
599
|
-
end
|
|
600
604
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
let(:promotion_code) { promotion.codes.first }
|
|
605
|
+
context "when promotion is at last usage on the same order" do
|
|
606
|
+
let(:order) { create(:completed_order_with_promotion, promotion: promotion) }
|
|
607
|
+
let(:promotable) { order }
|
|
605
608
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
promotion: promotion
|
|
610
|
-
)
|
|
611
|
-
promotion_code.adjustments.update_all(eligible: true)
|
|
612
|
-
end
|
|
609
|
+
before do
|
|
610
|
+
promotion.usage_limit = 1
|
|
611
|
+
end
|
|
613
612
|
|
|
614
|
-
|
|
615
|
-
expect(promotion.eligible?(promotable, promotion_code: promotion_code)).to eq(false)
|
|
613
|
+
it { is_expected.to be true }
|
|
616
614
|
end
|
|
617
|
-
end
|
|
618
615
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
616
|
+
context "when promotion code is at last usage on the same order" do
|
|
617
|
+
let(:order) { create(:completed_order_with_promotion, promotion: promotion) }
|
|
618
|
+
let(:promotable) { order }
|
|
622
619
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
620
|
+
before do
|
|
621
|
+
promotion.per_code_usage_limit = 1
|
|
622
|
+
end
|
|
626
623
|
|
|
627
|
-
context "and product is promotionable" do
|
|
628
|
-
let(:promotionable) { true }
|
|
629
624
|
it { is_expected.to be true }
|
|
630
625
|
end
|
|
631
|
-
|
|
632
|
-
context "and product is not promotionable" do
|
|
633
|
-
let(:promotionable) { false }
|
|
634
|
-
it { is_expected.to be false }
|
|
635
|
-
end
|
|
636
626
|
end
|
|
637
627
|
|
|
638
628
|
context "when promotable is a Spree::Order" do
|
|
629
|
+
let(:promotion) { create(:promotion, :with_order_adjustment) }
|
|
639
630
|
let(:promotable) { create :order }
|
|
640
631
|
|
|
641
|
-
|
|
642
|
-
it { is_expected.to be true }
|
|
643
|
-
end
|
|
632
|
+
it_behaves_like "a promotable"
|
|
644
633
|
|
|
645
|
-
context "
|
|
634
|
+
context "when it contains items" do
|
|
646
635
|
let!(:line_item) { create(:line_item, order: promotable) }
|
|
647
636
|
let!(:line_item2) { create(:line_item, order: promotable) }
|
|
648
637
|
|
|
@@ -650,6 +639,7 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
650
639
|
before do
|
|
651
640
|
line_item.product.update_column(:promotionable, false)
|
|
652
641
|
end
|
|
642
|
+
|
|
653
643
|
it { is_expected.to be false }
|
|
654
644
|
end
|
|
655
645
|
|
|
@@ -658,6 +648,7 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
658
648
|
line_item.product.update_column(:promotionable, false)
|
|
659
649
|
line_item2.product.update_column(:promotionable, false)
|
|
660
650
|
end
|
|
651
|
+
|
|
661
652
|
it { is_expected.to be false }
|
|
662
653
|
end
|
|
663
654
|
|
|
@@ -666,6 +657,32 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
666
657
|
end
|
|
667
658
|
end
|
|
668
659
|
end
|
|
660
|
+
|
|
661
|
+
context "when promotable is a Spree::LineItem" do
|
|
662
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
|
|
663
|
+
let(:promotable) { create(:line_item) }
|
|
664
|
+
|
|
665
|
+
it_behaves_like "a promotable"
|
|
666
|
+
|
|
667
|
+
context "and product is promotionable" do
|
|
668
|
+
before { promotable.product.promotionable = true }
|
|
669
|
+
|
|
670
|
+
it { is_expected.to be true }
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
context "and product is not promotionable" do
|
|
674
|
+
before { promotable.product.promotionable = false }
|
|
675
|
+
|
|
676
|
+
it { is_expected.to be false }
|
|
677
|
+
end
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
context "when promotable is a Spree::Shipment" do
|
|
681
|
+
let(:promotion) { create(:promotion, :with_free_shipping) }
|
|
682
|
+
let(:promotable) { create(:shipment) }
|
|
683
|
+
|
|
684
|
+
it_behaves_like "a promotable"
|
|
685
|
+
end
|
|
669
686
|
end
|
|
670
687
|
|
|
671
688
|
context "#eligible_rules" do
|
|
@@ -57,14 +57,14 @@ module Spree
|
|
|
57
57
|
context "multiple payment methods" do
|
|
58
58
|
let(:simulate) { true }
|
|
59
59
|
let!(:check_payment) { create(:check_payment, order: reimbursement.order, amount: 5.0, state: "completed") }
|
|
60
|
-
let(:payment) { reimbursement.order.payments.detect { |
|
|
60
|
+
let(:payment) { reimbursement.order.payments.detect { |item| item.payment_method.is_a? Spree::PaymentMethod::BogusCreditCard } }
|
|
61
61
|
let(:refund_amount) { 10.0 }
|
|
62
62
|
|
|
63
63
|
let(:refund_payment_methods) { subject.map { |refund| refund.payment.payment_method } }
|
|
64
64
|
|
|
65
65
|
before do
|
|
66
|
-
reimbursement.order.payments.first.
|
|
67
|
-
return_item.
|
|
66
|
+
reimbursement.order.payments.first.update!(amount: 5.0)
|
|
67
|
+
return_item.update!(amount: refund_amount)
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "includes refunds all payment type" do
|
|
@@ -18,7 +18,7 @@ module Spree
|
|
|
18
18
|
context "product has variants" do
|
|
19
19
|
it "returns all variants for the same product" do
|
|
20
20
|
product = create(:product, variants: Array.new(3) { create(:variant) })
|
|
21
|
-
product.variants.map { |
|
|
21
|
+
product.variants.map { |value| value.stock_items.first.update_column(:count_on_hand, 10) }
|
|
22
22
|
|
|
23
23
|
expect(SameProduct.eligible_variants(product.variants.first).sort).to eq product.variants.sort
|
|
24
24
|
end
|
|
@@ -26,8 +26,8 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
26
26
|
let(:return_item) { create(:return_item, inventory_unit: inventory_unit) }
|
|
27
27
|
|
|
28
28
|
before do
|
|
29
|
-
inventory_unit.
|
|
30
|
-
return_item.
|
|
29
|
+
inventory_unit.update!(state: 'shipped')
|
|
30
|
+
return_item.update!(reception_status: 'awaiting')
|
|
31
31
|
allow(return_item).to receive(:eligible_for_return?).and_return(true)
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -91,9 +91,9 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
91
91
|
let(:stock_item) { stock_location.stock_item(inventory_unit.variant) }
|
|
92
92
|
|
|
93
93
|
before do
|
|
94
|
-
inventory_unit.
|
|
95
|
-
return_item.
|
|
96
|
-
stock_location.
|
|
94
|
+
inventory_unit.update!(state: 'shipped')
|
|
95
|
+
return_item.update!(reception_status: 'awaiting')
|
|
96
|
+
stock_location.update!(restock_inventory: true)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
it 'increases the count on hand' do
|
|
@@ -102,9 +102,9 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
102
102
|
|
|
103
103
|
context 'when variant does not track inventory' do
|
|
104
104
|
before do
|
|
105
|
-
inventory_unit.
|
|
106
|
-
inventory_unit.variant.
|
|
107
|
-
return_item.
|
|
105
|
+
inventory_unit.update!(state: 'shipped')
|
|
106
|
+
inventory_unit.variant.update!(track_inventory: false)
|
|
107
|
+
return_item.update!(reception_status: 'awaiting')
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
it 'does not increase the count on hand' do
|
|
@@ -114,7 +114,7 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
114
114
|
|
|
115
115
|
context "when the stock location's restock_inventory is false" do
|
|
116
116
|
before do
|
|
117
|
-
stock_location.
|
|
117
|
+
stock_location.update!(restock_inventory: false)
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it 'does not increase the count on hand' do
|
|
@@ -135,7 +135,7 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
135
135
|
|
|
136
136
|
Spree::ReturnItem::INTERMEDIATE_RECEPTION_STATUSES.each do |status|
|
|
137
137
|
context "when the item was #{status}" do
|
|
138
|
-
before { return_item.
|
|
138
|
+
before { return_item.update!(reception_status: status) }
|
|
139
139
|
|
|
140
140
|
it 'processes the inventory unit' do
|
|
141
141
|
subject
|
|
@@ -293,7 +293,7 @@ RSpec.describe Spree::ReturnItem, type: :model do
|
|
|
293
293
|
subject { return_item.public_send("#{transition}!") }
|
|
294
294
|
context "awaiting status" do
|
|
295
295
|
before do
|
|
296
|
-
return_item.
|
|
296
|
+
return_item.update!(reception_status: 'awaiting')
|
|
297
297
|
allow(return_item).to receive(:eligible_for_return?).and_return(true)
|
|
298
298
|
end
|
|
299
299
|
|
|
@@ -5,9 +5,9 @@ require 'rails_helper'
|
|
|
5
5
|
module Spree
|
|
6
6
|
RSpec.describe ReturnsCalculator, type: :model do
|
|
7
7
|
let(:return_item) { build(:return_item) }
|
|
8
|
-
subject {
|
|
8
|
+
subject { described_class.new }
|
|
9
9
|
|
|
10
|
-
it '
|
|
10
|
+
it 'compute must be overridden' do
|
|
11
11
|
expect {
|
|
12
12
|
subject.compute(return_item)
|
|
13
13
|
}.to raise_error NotImplementedError
|
|
@@ -152,7 +152,7 @@ RSpec.describe Spree::Shipment, type: :model do
|
|
|
152
152
|
|
|
153
153
|
describe '#total_before_tax' do
|
|
154
154
|
before do
|
|
155
|
-
shipment.
|
|
155
|
+
shipment.update!(cost: 10)
|
|
156
156
|
end
|
|
157
157
|
let!(:admin_adjustment) { create(:adjustment, adjustable: shipment, order: shipment.order, amount: -1, source: nil) }
|
|
158
158
|
let!(:promo_adjustment) { create(:adjustment, adjustable: shipment, order: shipment.order, amount: -2, source: promo_action) }
|
|
@@ -250,7 +250,7 @@ RSpec.describe Spree::Shipment, type: :model do
|
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
it "can't get rates without a shipping address" do
|
|
253
|
-
shipment.order.
|
|
253
|
+
shipment.order.update!(ship_address: nil)
|
|
254
254
|
expect(shipment.refresh_rates).to eq([])
|
|
255
255
|
end
|
|
256
256
|
|
|
@@ -298,7 +298,7 @@ RSpec.describe Spree::Shipment, type: :model do
|
|
|
298
298
|
shared_examples_for "pending if backordered" do
|
|
299
299
|
it "should have a state of pending if backordered" do
|
|
300
300
|
# Set as ready so we can test for change
|
|
301
|
-
shipment.
|
|
301
|
+
shipment.update!(state: 'ready')
|
|
302
302
|
|
|
303
303
|
allow(shipment).to receive_messages(inventory_units: [mock_model(Spree::InventoryUnit, allow_ship?: false, canceled?: false, shipped?: false)])
|
|
304
304
|
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
|
|
@@ -310,7 +310,7 @@ RSpec.describe Spree::Shipment, type: :model do
|
|
|
310
310
|
before { allow(order).to receive_messages can_ship?: false }
|
|
311
311
|
it "should result in a 'pending' state" do
|
|
312
312
|
# Set as ready so we can test for change
|
|
313
|
-
shipment.
|
|
313
|
+
shipment.update!(state: 'ready')
|
|
314
314
|
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
|
|
315
315
|
shipment.update_state
|
|
316
316
|
end
|
|
@@ -768,8 +768,8 @@ RSpec.describe Spree::Shipment, type: :model do
|
|
|
768
768
|
.to receive(:new).and_return(inventory_unit_finalizer)
|
|
769
769
|
|
|
770
770
|
stock_item.set_count_on_hand(10)
|
|
771
|
-
stock_item.
|
|
772
|
-
inventory_unit.
|
|
771
|
+
stock_item.update!(backorderable: false)
|
|
772
|
+
inventory_unit.update!(pending: true)
|
|
773
773
|
end
|
|
774
774
|
|
|
775
775
|
subject { shipment.finalize! }
|
|
@@ -21,25 +21,13 @@ module Spree
|
|
|
21
21
|
)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
subject {
|
|
25
|
-
|
|
26
|
-
it 'computes with a shipment' do
|
|
27
|
-
shipment = mock_model(Spree::Shipment)
|
|
28
|
-
expect(subject).to receive(:compute_shipment).with(shipment)
|
|
29
|
-
subject.compute(shipment)
|
|
30
|
-
end
|
|
24
|
+
subject { described_class.new }
|
|
31
25
|
|
|
32
26
|
it 'computes with a package' do
|
|
33
27
|
expect(subject).to receive(:compute_package).with(package)
|
|
34
28
|
subject.compute(package)
|
|
35
29
|
end
|
|
36
30
|
|
|
37
|
-
it 'compute_shipment must be overridden' do
|
|
38
|
-
expect {
|
|
39
|
-
subject.compute_shipment(shipment)
|
|
40
|
-
}.to raise_error NameError
|
|
41
|
-
end
|
|
42
|
-
|
|
43
31
|
it 'compute_package must be overridden' do
|
|
44
32
|
expect {
|
|
45
33
|
subject.compute_package(package)
|
|
@@ -257,4 +257,36 @@ RSpec.describe Spree::ShippingMethod, type: :model do
|
|
|
257
257
|
it { should == 'back_end' }
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
|
+
|
|
261
|
+
describe '.available_to_store' do
|
|
262
|
+
let(:store) { create(:store) }
|
|
263
|
+
let(:first_shipping_method) { create(:shipping_method, stores: [store]) }
|
|
264
|
+
let(:second_shipping_method) { create(:shipping_method, stores: [store]) }
|
|
265
|
+
|
|
266
|
+
subject { [first_shipping_method, second_shipping_method] }
|
|
267
|
+
|
|
268
|
+
it 'raises an exception if no store is passed as argument' do
|
|
269
|
+
expect {
|
|
270
|
+
described_class.available_to_store(nil)
|
|
271
|
+
}.to raise_exception(ArgumentError, 'You must provide a store')
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
context 'when the store has no shipping methods associated' do
|
|
275
|
+
before { store.shipping_methods = [] }
|
|
276
|
+
|
|
277
|
+
it 'returns all shipping methods' do
|
|
278
|
+
expect(store.shipping_methods).to eq([])
|
|
279
|
+
expect(described_class.available_to_store(store)).to eq(subject)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
context 'when the store has shipping methods associated' do
|
|
284
|
+
before { create(:shipping_method) }
|
|
285
|
+
|
|
286
|
+
it 'returns the associated records' do
|
|
287
|
+
expect(store.shipping_methods).to eq(subject)
|
|
288
|
+
expect(described_class.available_to_store(store)).to eq(subject)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
260
292
|
end
|
|
@@ -115,8 +115,8 @@ module Spree
|
|
|
115
115
|
let(:stock_location) { order.shipments.first.stock_location }
|
|
116
116
|
|
|
117
117
|
before do
|
|
118
|
-
|
|
119
|
-
order.contents.add(variant, 1, shipment:
|
|
118
|
+
shipment_two = order.shipments.create!(stock_location: order.shipments.first.stock_location)
|
|
119
|
+
order.contents.add(variant, 1, shipment: shipment_two)
|
|
120
120
|
variant.stock_items.first.update_columns(count_on_hand: count_on_hand, backorderable: false)
|
|
121
121
|
end
|
|
122
122
|
|