solidus_core 2.10.0.beta1 → 2.10.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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -4
  3. data/app/helpers/spree/products_helper.rb +2 -1
  4. data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
  5. data/app/models/concerns/spree/user_methods.rb +2 -2
  6. data/app/models/spree/address.rb +11 -15
  7. data/app/models/spree/adjustment.rb +11 -0
  8. data/app/models/spree/calculator/price_sack.rb +1 -1
  9. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  10. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  11. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  12. data/app/models/spree/carton.rb +1 -1
  13. data/app/models/spree/credit_card.rb +2 -2
  14. data/app/models/spree/inventory_unit.rb +1 -19
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/order.rb +3 -2
  17. data/app/models/spree/order/checkout.rb +1 -1
  18. data/app/models/spree/order/payments.rb +2 -2
  19. data/app/models/spree/order_capturing.rb +2 -2
  20. data/app/models/spree/order_taxation.rb +2 -2
  21. data/app/models/spree/payment.rb +4 -41
  22. data/app/models/spree/payment/processing.rb +2 -2
  23. data/app/models/spree/payment_method.rb +2 -2
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product/scopes.rb +8 -7
  26. data/app/models/spree/promotion.rb +27 -12
  27. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  28. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  29. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  30. data/app/models/spree/promotion/rules/product.rb +3 -3
  31. data/app/models/spree/promotion_action.rb +1 -1
  32. data/app/models/spree/promotion_chooser.rb +2 -2
  33. data/app/models/spree/promotion_code.rb +9 -8
  34. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  35. data/app/models/spree/promotion_rule.rb +1 -1
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +3 -11
  38. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  39. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  40. data/app/models/spree/return_authorization.rb +1 -7
  41. data/app/models/spree/return_item.rb +3 -42
  42. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  43. data/app/models/spree/shipment.rb +4 -38
  44. data/app/models/spree/shipping_calculator.rb +0 -4
  45. data/app/models/spree/shipping_method.rb +1 -1
  46. data/app/models/spree/state.rb +1 -1
  47. data/app/models/spree/stock/differentiator.rb +1 -1
  48. data/app/models/spree/stock/package.rb +1 -1
  49. data/app/models/spree/stock_item.rb +1 -1
  50. data/app/models/spree/stock_quantities.rb +13 -12
  51. data/app/models/spree/tax_calculator/default.rb +0 -4
  52. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  53. data/app/models/spree/tax_rate.rb +4 -0
  54. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  55. data/app/models/spree/user_last_url_storer.rb +46 -0
  56. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  57. data/app/models/spree/variant.rb +9 -9
  58. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  59. data/app/models/spree/zone.rb +1 -1
  60. data/config/initializers/money.rb +2 -0
  61. data/config/locales/en.yml +12 -0
  62. data/lib/generators/spree/install/install_generator.rb +3 -0
  63. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  64. data/lib/spree/app_configuration.rb +18 -3
  65. data/lib/spree/core.rb +12 -0
  66. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  67. data/lib/spree/core/engine.rb +2 -2
  68. data/lib/spree/core/environment_extension.rb +9 -0
  69. data/lib/spree/core/importer/order.rb +26 -26
  70. data/lib/spree/core/product_filters.rb +15 -15
  71. data/lib/spree/core/role_configuration.rb +2 -2
  72. data/lib/spree/core/search/variant.rb +1 -1
  73. data/lib/spree/core/state_machines.rb +78 -0
  74. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  75. data/lib/spree/core/state_machines/payment.rb +61 -0
  76. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  77. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  78. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  79. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  80. data/lib/spree/core/state_machines/shipment.rb +58 -0
  81. data/lib/spree/core/stock_configuration.rb +1 -0
  82. data/lib/spree/core/validators/email.rb +1 -8
  83. data/lib/spree/core/version.rb +1 -1
  84. data/lib/spree/money.rb +2 -2
  85. data/lib/spree/permission_sets/user_management.rb +3 -0
  86. data/lib/spree/permitted_attributes.rb +3 -3
  87. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  88. data/lib/spree/testing_support/dummy_app.rb +4 -1
  89. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  90. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  91. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  92. data/solidus_core.gemspec +2 -2
  93. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  94. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  95. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  96. data/spec/models/spree/address_spec.rb +23 -0
  97. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  98. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  99. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  100. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  101. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  102. data/spec/models/spree/carton_spec.rb +8 -0
  103. data/spec/models/spree/classification_spec.rb +21 -9
  104. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  105. data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
  106. data/spec/models/spree/order_merger_spec.rb +3 -3
  107. data/spec/models/spree/order_spec.rb +8 -15
  108. data/spec/models/spree/order_updater_spec.rb +4 -3
  109. data/spec/models/spree/payment_create_spec.rb +4 -14
  110. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  111. data/spec/models/spree/preference_spec.rb +4 -4
  112. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  113. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  114. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  115. data/spec/models/spree/promotion_spec.rb +73 -52
  116. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
  117. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  118. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  119. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  120. data/spec/models/spree/shipping_method_spec.rb +32 -0
  121. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  122. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  123. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  124. data/spec/models/spree/stock/package_spec.rb +28 -28
  125. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  126. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  127. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  128. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  129. data/spec/models/spree/store_credit_spec.rb +1 -1
  130. data/spec/models/spree/tax_rate_spec.rb +1 -0
  131. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  132. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  133. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  134. metadata +17 -12
  135. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
  136. 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
- p1 = TestRule.new
21
- p1.promotion_id = 1
22
- p1.save
20
+ promotion_one = TestRule.new
21
+ promotion_one.promotion_id = 1
22
+ promotion_one.save
23
23
 
24
- p2 = TestRule.new
25
- p2.promotion_id = 1
26
- expect(p2).not_to be_valid
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.days }
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.days }
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.days }
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.days }
462
+ let(:expires_at) { Time.current - 1.day }
463
463
  it { is_expected.to be_falsey }
464
464
  end
465
465
  end
@@ -569,76 +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
- let(:promotable) { create :order }
575
+ shared_examples "a promotable" do
576
+ context "when empty" do
577
+ it { is_expected.to be true }
578
+ end
576
579
 
577
- it { is_expected.to be true }
580
+ context "when promotion is expired" do
581
+ before { promotion.expires_at = Time.current - 10.days }
578
582
 
579
- context "when promotion is expired" do
580
- before { promotion.expires_at = Time.current - 10.days }
581
- it { is_expected.to be false }
582
- end
583
+ it { is_expected.to be false }
584
+ end
583
585
 
584
- context "when the promotion's usage limit is exceeded" do
585
- let(:promotion) { FactoryBot.create(:promotion, :with_order_adjustment) }
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
586
591
 
587
- before do
588
- FactoryBot.create(
589
- :completed_order_with_promotion,
590
- promotion: promotion
591
- )
592
- promotion.usage_limit = 1
592
+ it { is_expected.to be false }
593
593
  end
594
594
 
595
- it "returns false" do
596
- expect(promotion.eligible?(promotable)).to eq(false)
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 }
597
603
  end
598
- end
599
604
 
600
- context "when the promotion code's usage limit is exceeded" do
601
- let(:promotion) { create(:promotion, :with_order_adjustment, code: 'abc123', per_code_usage_limit: 1) }
602
- 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 }
603
608
 
604
- before do
605
- FactoryBot.create(
606
- :completed_order_with_promotion,
607
- promotion: promotion
608
- )
609
- promotion_code.adjustments.update_all(eligible: true)
610
- end
609
+ before do
610
+ promotion.usage_limit = 1
611
+ end
611
612
 
612
- it "returns false" do
613
- expect(promotion.eligible?(promotable, promotion_code: promotion_code)).to eq(false)
613
+ it { is_expected.to be true }
614
614
  end
615
- end
616
615
 
617
- context "when promotable is a Spree::LineItem" do
618
- let(:promotable) { create :line_item }
619
- let(:product) { promotable.product }
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 }
620
619
 
621
- before do
622
- product.promotionable = promotionable
623
- end
620
+ before do
621
+ promotion.per_code_usage_limit = 1
622
+ end
624
623
 
625
- context "and product is promotionable" do
626
- let(:promotionable) { true }
627
624
  it { is_expected.to be true }
628
625
  end
629
-
630
- context "and product is not promotionable" do
631
- let(:promotionable) { false }
632
- it { is_expected.to be false }
633
- end
634
626
  end
635
627
 
636
628
  context "when promotable is a Spree::Order" do
637
- context "and it is empty" do
638
- it { is_expected.to be true }
639
- end
629
+ let(:promotion) { create(:promotion, :with_order_adjustment) }
630
+ let(:promotable) { create :order }
640
631
 
641
- context "and it contains items" do
632
+ it_behaves_like "a promotable"
633
+
634
+ context "when it contains items" do
642
635
  let!(:line_item) { create(:line_item, order: promotable) }
643
636
  let!(:line_item2) { create(:line_item, order: promotable) }
644
637
 
@@ -646,6 +639,7 @@ RSpec.describe Spree::Promotion, type: :model do
646
639
  before do
647
640
  line_item.product.update_column(:promotionable, false)
648
641
  end
642
+
649
643
  it { is_expected.to be false }
650
644
  end
651
645
 
@@ -654,6 +648,7 @@ RSpec.describe Spree::Promotion, type: :model do
654
648
  line_item.product.update_column(:promotionable, false)
655
649
  line_item2.product.update_column(:promotionable, false)
656
650
  end
651
+
657
652
  it { is_expected.to be false }
658
653
  end
659
654
 
@@ -662,6 +657,32 @@ RSpec.describe Spree::Promotion, type: :model do
662
657
  end
663
658
  end
664
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
665
686
  end
666
687
 
667
688
  context "#eligible_rules" do
@@ -57,7 +57,7 @@ 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 { |p| p.payment_method.is_a? Spree::PaymentMethod::BogusCreditCard } }
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 } }
@@ -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 { |v| v.stock_items.first.update_column(:count_on_hand, 10) }
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
@@ -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 { ReturnsCalculator.new }
8
+ subject { described_class.new }
9
9
 
10
- it 'compute_shipment must be overridden' do
10
+ it 'compute must be overridden' do
11
11
  expect {
12
12
  subject.compute(return_item)
13
13
  }.to raise_error NotImplementedError
@@ -21,25 +21,13 @@ module Spree
21
21
  )
22
22
  end
23
23
 
24
- subject { ShippingCalculator.new }
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
- shipment2 = order.shipments.create!(stock_location: order.shipments.first.stock_location)
119
- order.contents.add(variant, 1, shipment: shipment2)
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
 
@@ -19,11 +19,11 @@ module Spree
19
19
  let(:order) { mock_model(Order, line_items: [line_item1, line_item2]) }
20
20
 
21
21
  let(:package1) do
22
- Package.new(stock_location).tap { |p| p.add(inventory_unit1) }
22
+ Package.new(stock_location).tap { |package| package.add(inventory_unit1) }
23
23
  end
24
24
 
25
25
  let(:package2) do
26
- Package.new(stock_location).tap { |p| p.add(inventory_unit2) }
26
+ Package.new(stock_location).tap { |package| package.add(inventory_unit2) }
27
27
  end
28
28
 
29
29
  let(:packages) { [package1, package2] }
@@ -8,8 +8,8 @@ module Spree
8
8
  let(:shipping_rate) { 4.00 }
9
9
  let!(:shipping_method) { create(:shipping_method, cost: shipping_rate, currency: currency) }
10
10
  let(:package) do
11
- build(:stock_package, contents: inventory_units.map { |i| ContentItem.new(i) }).tap do |p|
12
- p.shipment = p.to_shipment
11
+ build(:stock_package, contents: inventory_units.map { |unit| ContentItem.new(unit) }).tap do |package|
12
+ package.shipment = package.to_shipment
13
13
  end
14
14
  end
15
15
  let(:order) { create(:order_with_line_items, shipping_method: shipping_method) }
@@ -61,7 +61,7 @@ module Spree
61
61
  end
62
62
 
63
63
  context "when the order's ship address is in a different zone" do
64
- before { shipping_method.zones.each{ |z| z.members.delete_all } }
64
+ before { shipping_method.zones.each{ |zone| zone.members.delete_all } }
65
65
  it_should_behave_like "shipping rate doesn't match"
66
66
  end
67
67
 
@@ -51,41 +51,41 @@ module Spree
51
51
  end
52
52
 
53
53
  it 'builds the correct list of shipping methods based on stock location and categories' do
54
- category1 = create(:shipping_category)
55
- category2 = create(:shipping_category)
56
- method1 = create(:shipping_method, available_to_all: true)
57
- method2 = create(:shipping_method, stock_locations: [stock_location])
58
- method1.shipping_categories = [category1, category2]
59
- method2.shipping_categories = [category1, category2]
60
- variant1 = mock_model(Variant, shipping_category_id: category1.id)
61
- variant2 = mock_model(Variant, shipping_category_id: category2.id)
62
- variant3 = mock_model(Variant, shipping_category_id: nil)
63
- contents = [ContentItem.new(build(:inventory_unit, variant: variant1)),
64
- ContentItem.new(build(:inventory_unit, variant: variant1)),
65
- ContentItem.new(build(:inventory_unit, variant: variant2)),
66
- ContentItem.new(build(:inventory_unit, variant: variant3))]
54
+ category_one = create(:shipping_category)
55
+ category_two = create(:shipping_category)
56
+ method_one = create(:shipping_method, available_to_all: true)
57
+ method_two = create(:shipping_method, stock_locations: [stock_location])
58
+ method_one.shipping_categories = [category_one, category_two]
59
+ method_two.shipping_categories = [category_one, category_two]
60
+ variant_one = mock_model(Variant, shipping_category_id: category_one.id)
61
+ variant_two = mock_model(Variant, shipping_category_id: category_two.id)
62
+ variant_three = mock_model(Variant, shipping_category_id: nil)
63
+ contents = [ContentItem.new(build(:inventory_unit, variant: variant_one)),
64
+ ContentItem.new(build(:inventory_unit, variant: variant_one)),
65
+ ContentItem.new(build(:inventory_unit, variant: variant_two)),
66
+ ContentItem.new(build(:inventory_unit, variant: variant_three))]
67
67
 
68
68
  package = Package.new(stock_location, contents)
69
- expect(package.shipping_methods).to match_array([method1, method2])
69
+ expect(package.shipping_methods).to match_array([method_one, method_two])
70
70
  end
71
71
  # Contains regression test for https://github.com/spree/spree/issues/2804
72
72
  it 'builds a list of shipping methods common to all categories' do
73
- category1 = create(:shipping_category)
74
- category2 = create(:shipping_category)
75
- method1 = create(:shipping_method)
76
- method2 = create(:shipping_method)
77
- method1.shipping_categories = [category1, category2]
78
- method2.shipping_categories = [category1]
79
- variant1 = mock_model(Variant, shipping_category_id: category1.id)
80
- variant2 = mock_model(Variant, shipping_category_id: category2.id)
81
- variant3 = mock_model(Variant, shipping_category_id: nil)
82
- contents = [ContentItem.new(build(:inventory_unit, variant: variant1)),
83
- ContentItem.new(build(:inventory_unit, variant: variant1)),
84
- ContentItem.new(build(:inventory_unit, variant: variant2)),
85
- ContentItem.new(build(:inventory_unit, variant: variant3))]
73
+ category_one = create(:shipping_category)
74
+ category_two = create(:shipping_category)
75
+ method_one = create(:shipping_method)
76
+ method_two = create(:shipping_method)
77
+ method_one.shipping_categories = [category_one, category_two]
78
+ method_two.shipping_categories = [category_one]
79
+ variant_one = mock_model(Variant, shipping_category_id: category_one.id)
80
+ variant_two = mock_model(Variant, shipping_category_id: category_two.id)
81
+ variant_three = mock_model(Variant, shipping_category_id: nil)
82
+ contents = [ContentItem.new(build(:inventory_unit, variant: variant_one)),
83
+ ContentItem.new(build(:inventory_unit, variant: variant_one)),
84
+ ContentItem.new(build(:inventory_unit, variant: variant_two)),
85
+ ContentItem.new(build(:inventory_unit, variant: variant_three))]
86
86
 
87
87
  package = Package.new(stock_location, contents)
88
- expect(package.shipping_methods).to match_array([method1])
88
+ expect(package.shipping_methods).to match_array([method_one])
89
89
  end
90
90
 
91
91
  it 'builds an empty list of shipping methods when no categories' do
@@ -90,8 +90,8 @@ module Spree
90
90
 
91
91
  expect(shipments.size).to eq 2
92
92
 
93
- location_1_shipment = shipments.detect { |p| p.stock_location == stock_location_1 }
94
- location_2_shipment = shipments.detect { |p| p.stock_location == stock_location_2 }
93
+ location_1_shipment = shipments.detect { |shipment| shipment.stock_location == stock_location_1 }
94
+ location_2_shipment = shipments.detect { |shipment| shipment.stock_location == stock_location_2 }
95
95
 
96
96
  expect(location_1_shipment).to be_present
97
97
  expect(location_2_shipment).to be_present
@@ -107,8 +107,8 @@ module Spree
107
107
  let!(:variant) { create(:variant, track_inventory: true) }
108
108
 
109
109
  before do
110
- stock_item1 = variant.stock_items.create!(stock_location: stock_location_1, backorderable: false)
111
- stock_item1.set_count_on_hand(location_1_inventory)
110
+ stock_item_one = variant.stock_items.create!(stock_location: stock_location_1, backorderable: false)
111
+ stock_item_one.set_count_on_hand(location_1_inventory)
112
112
  end
113
113
 
114
114
  let!(:order) { create(:order) }
@@ -119,7 +119,7 @@ module Spree
119
119
  shared_examples "a fulfillable package" do
120
120
  it "packages correctly" do
121
121
  expect(shipments).not_to be_empty
122
- inventory_units = shipments.flat_map { |s| s.inventory_units }
122
+ inventory_units = shipments.flat_map { |shipment| shipment.inventory_units }
123
123
  expect(inventory_units.size).to eq(5)
124
124
  expect(inventory_units.uniq.size).to eq(5)
125
125
  end
@@ -157,8 +157,8 @@ module Spree
157
157
  context 'with two stock locations' do
158
158
  let!(:stock_location_2) { create(:stock_location, propagate_all_variants: false, active: true) }
159
159
  before do
160
- stock_item2 = variant.stock_items.create!(stock_location: stock_location_2, backorderable: false)
161
- stock_item2.set_count_on_hand(location_2_inventory)
160
+ stock_item_two = variant.stock_items.create!(stock_location: stock_location_2, backorderable: false)
161
+ stock_item_two.set_count_on_hand(location_2_inventory)
162
162
  end
163
163
 
164
164
  context "with no inventory" do
@@ -214,11 +214,11 @@ module Spree
214
214
  let!(:stock_location_2) { create(:stock_location, propagate_all_variants: false, active: true) }
215
215
  let!(:stock_location_3) { create(:stock_location, propagate_all_variants: false, active: true) }
216
216
  before do
217
- stock_item2 = variant.stock_items.create!(stock_location: stock_location_2, backorderable: false)
218
- stock_item2.set_count_on_hand(location_2_inventory)
217
+ stock_item_two = variant.stock_items.create!(stock_location: stock_location_2, backorderable: false)
218
+ stock_item_two.set_count_on_hand(location_2_inventory)
219
219
 
220
- stock_item3 = variant.stock_items.create!(stock_location: stock_location_3, backorderable: false)
221
- stock_item3.set_count_on_hand(location_3_inventory)
220
+ stock_item_three = variant.stock_items.create!(stock_location: stock_location_3, backorderable: false)
221
+ stock_item_three.set_count_on_hand(location_3_inventory)
222
222
  end
223
223
 
224
224
  # Regression test for https://github.com/solidusio/solidus/issues/2122