solidus_core 2.8.6 → 2.9.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/logo/solidus.svg +1 -18
  3. data/app/assets/images/logo/solidus_logo.png +0 -0
  4. data/app/mailers/spree/test_mailer.rb +2 -0
  5. data/app/models/concerns/spree/default_price.rb +1 -1
  6. data/app/models/concerns/spree/ransackable_attributes.rb +1 -1
  7. data/app/models/concerns/spree/user_reporting.rb +1 -1
  8. data/app/models/spree/billing_integration.rb +7 -2
  9. data/app/models/spree/country.rb +2 -0
  10. data/app/models/spree/customer_return.rb +1 -1
  11. data/app/models/spree/image.rb +2 -44
  12. data/app/models/spree/image/paperclip_attachment.rb +55 -0
  13. data/app/models/spree/inventory_unit.rb +0 -1
  14. data/app/models/spree/option_type.rb +2 -0
  15. data/app/models/spree/option_value.rb +1 -1
  16. data/app/models/spree/order.rb +8 -13
  17. data/app/models/spree/payment.rb +1 -1
  18. data/app/models/spree/payment_method.rb +8 -4
  19. data/app/models/spree/product.rb +1 -1
  20. data/app/models/spree/promotion.rb +18 -11
  21. data/app/models/spree/promotion/rules/first_order.rb +1 -3
  22. data/app/models/spree/promotion/rules/item_total.rb +9 -1
  23. data/app/models/spree/promotion/rules/one_use_per_user.rb +2 -2
  24. data/app/models/spree/promotion/rules/product.rb +3 -3
  25. data/app/models/spree/promotion/rules/taxon.rb +5 -8
  26. data/app/models/spree/promotion/rules/user_logged_in.rb +1 -1
  27. data/app/models/spree/promotion_handler/coupon.rb +19 -3
  28. data/app/models/spree/property.rb +2 -0
  29. data/app/models/spree/reimbursement.rb +5 -5
  30. data/app/models/spree/return_item.rb +6 -2
  31. data/app/models/spree/state.rb +6 -0
  32. data/app/models/spree/stock/location_filter/active.rb +14 -0
  33. data/app/models/spree/stock/location_filter/base.rb +43 -0
  34. data/app/models/spree/stock/simple_coordinator.rb +4 -1
  35. data/app/models/spree/stock_location.rb +2 -0
  36. data/app/models/spree/tax_category.rb +11 -0
  37. data/app/models/spree/taxon.rb +4 -11
  38. data/app/models/spree/taxon/paperclip_attachment.rb +21 -0
  39. data/app/models/spree/taxonomy.rb +2 -0
  40. data/app/models/spree/unit_cancel.rb +12 -1
  41. data/app/models/spree/variant.rb +1 -1
  42. data/app/models/spree/variant/pricing_options.rb +10 -0
  43. data/app/models/spree/wallet_payment_source.rb +26 -10
  44. data/app/models/spree/zone.rb +1 -1
  45. data/app/views/spree/order_mailer/inventory_cancellation_email.text.erb +3 -3
  46. data/config/locales/en.yml +26 -53
  47. data/db/default/spree/store_credit.rb +1 -0
  48. data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +1 -1
  49. data/db/migrate/20170608074534_rename_bogus_gateways.rb +9 -8
  50. data/db/migrate/20190220093635_drop_spree_store_credit_update_reasons.rb +19 -0
  51. data/lib/generators/spree/install/install_generator.rb +0 -3
  52. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +3 -0
  53. data/lib/solidus/migrations/rename_gateways.rb +2 -0
  54. data/lib/spree/app_configuration.rb +24 -0
  55. data/lib/spree/core.rb +1 -0
  56. data/lib/spree/core/controller_helpers/pricing.rb +1 -4
  57. data/lib/spree/core/controller_helpers/strong_parameters.rb +7 -21
  58. data/lib/spree/core/engine.rb +5 -0
  59. data/lib/spree/core/importer/order.rb +1 -3
  60. data/lib/spree/core/stock_configuration.rb +5 -0
  61. data/lib/spree/core/version.rb +3 -1
  62. data/lib/spree/deprecation.rb +50 -0
  63. data/lib/spree/event.rb +111 -0
  64. data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
  65. data/lib/spree/event/configuration.rb +17 -0
  66. data/lib/spree/event/processors/mailer_processor.rb +27 -0
  67. data/lib/spree/event/subscriber.rb +84 -0
  68. data/lib/spree/permitted_attributes.rb +7 -76
  69. data/lib/spree/testing_support/capybara_ext.rb +15 -0
  70. data/lib/spree/testing_support/common_rake.rb +1 -1
  71. data/lib/spree/testing_support/dummy_app.rb +3 -10
  72. data/lib/spree/testing_support/factories/promotion_factory.rb +10 -0
  73. data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
  74. data/lib/spree/testing_support/preferences.rb +62 -0
  75. data/lib/tasks/email.rake +2 -0
  76. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +4 -0
  77. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +2 -0
  78. data/lib/tasks/migrations/migrate_user_addresses.rake +3 -0
  79. data/lib/tasks/migrations/rename_gateways.rake +2 -0
  80. data/lib/tasks/order_capturing.rake +2 -0
  81. data/spec/helpers/base_helper_spec.rb +3 -3
  82. data/spec/helpers/products_helper_spec.rb +2 -2
  83. data/spec/{models → lib}/spree/app_configuration_spec.rb +11 -1
  84. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +13 -0
  85. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +1 -8
  86. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +1 -1
  87. data/spec/lib/spree/core/testing_support/preferences_spec.rb +33 -0
  88. data/spec/lib/spree/event/subscriber_spec.rb +85 -0
  89. data/spec/lib/spree/event_spec.rb +92 -0
  90. data/spec/lib/spree/money_spec.rb +3 -9
  91. data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +5 -3
  92. data/spec/mailers/order_mailer_spec.rb +1 -1
  93. data/spec/mailers/test_mailer_spec.rb +3 -1
  94. data/spec/models/spree/address_spec.rb +5 -4
  95. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  96. data/spec/models/spree/country_spec.rb +5 -5
  97. data/spec/models/spree/customer_return_spec.rb +1 -1
  98. data/spec/models/spree/order/checkout_spec.rb +3 -7
  99. data/spec/models/spree/order/finalizing_spec.rb +1 -1
  100. data/spec/models/spree/order/payment_spec.rb +3 -3
  101. data/spec/models/spree/order_inventory_spec.rb +1 -1
  102. data/spec/models/spree/order_spec.rb +67 -2
  103. data/spec/models/spree/order_updater_spec.rb +2 -2
  104. data/spec/models/spree/payment_spec.rb +12 -0
  105. data/spec/models/spree/product_spec.rb +3 -3
  106. data/spec/models/spree/promotion/rules/first_order_spec.rb +13 -3
  107. data/spec/models/spree/promotion/rules/item_total_spec.rb +15 -0
  108. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +10 -0
  109. data/spec/models/spree/promotion/rules/product_spec.rb +15 -0
  110. data/spec/models/spree/promotion/rules/taxon_spec.rb +59 -8
  111. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +5 -0
  112. data/spec/models/spree/promotion_handler/shipping_spec.rb +1 -1
  113. data/spec/models/spree/promotion_spec.rb +80 -0
  114. data/spec/models/spree/reimbursement_spec.rb +3 -2
  115. data/spec/models/spree/return_item_spec.rb +9 -0
  116. data/spec/models/spree/shipment_spec.rb +3 -3
  117. data/spec/models/spree/stock/availability_spec.rb +1 -1
  118. data/spec/models/spree/stock/estimator_spec.rb +5 -7
  119. data/spec/models/spree/stock/location_filter/active_spec.rb +22 -0
  120. data/spec/models/spree/stock/location_sorter/default_first_spec.rb +4 -2
  121. data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +3 -1
  122. data/spec/models/spree/stock/quantifier_spec.rb +1 -1
  123. data/spec/models/spree/stock/simple_coordinator_spec.rb +5 -0
  124. data/spec/models/spree/stock_item_spec.rb +3 -2
  125. data/spec/models/spree/stock_movement_spec.rb +1 -1
  126. data/spec/models/spree/store_credit_spec.rb +1 -1
  127. data/spec/models/spree/tax/order_adjuster_spec.rb +1 -1
  128. data/spec/models/spree/tax/taxation_integration_spec.rb +1 -1
  129. data/spec/models/spree/tax_category_spec.rb +21 -0
  130. data/spec/models/spree/taxon_spec.rb +28 -0
  131. data/spec/models/spree/unit_cancel_spec.rb +41 -0
  132. data/spec/models/spree/user_spec.rb +3 -3
  133. data/spec/models/spree/variant/pricing_options_spec.rb +23 -0
  134. data/spec/models/spree/variant/vat_price_generator_spec.rb +1 -1
  135. data/spec/models/spree/variant_spec.rb +11 -8
  136. data/spec/models/spree/wallet_payment_source_spec.rb +35 -6
  137. data/spec/models/spree/wallet_spec.rb +1 -1
  138. data/spec/spec_helper.rb +0 -4
  139. data/spec/support/concerns/default_price.rb +8 -0
  140. metadata +18 -5
  141. data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
@@ -117,7 +117,7 @@ module Spree
117
117
  end
118
118
  end
119
119
 
120
- Spree::Config.promotion_chooser_class = Spree::TestPromotionChooser
120
+ stub_spree_preferences(promotion_chooser_class: Spree::TestPromotionChooser)
121
121
  end
122
122
 
123
123
  it 'uses the defined promotion chooser' do
@@ -322,7 +322,7 @@ module Spree
322
322
 
323
323
  before do
324
324
  order # generate this first so we can expect it
325
- Spree::Config.tax_calculator_class = custom_calculator_class
325
+ stub_spree_preferences(tax_calculator_class: custom_calculator_class)
326
326
  end
327
327
 
328
328
  it 'uses the configured class' do
@@ -1255,4 +1255,16 @@ RSpec.describe Spree::Payment, type: :model do
1255
1255
  end
1256
1256
  end
1257
1257
  end
1258
+
1259
+ describe '::valid scope' do
1260
+ before do
1261
+ create :payment, state: :void
1262
+ create :payment, state: :failed
1263
+ create :payment, state: :invalid
1264
+ end
1265
+
1266
+ it 'does not include void, failed and invalid payments' do
1267
+ expect(described_class.valid).to be_empty
1268
+ end
1269
+ end
1258
1270
  end
@@ -153,7 +153,7 @@ RSpec.describe Spree::Product, type: :model do
153
153
  before do
154
154
  product.master.default_price.currency = 'JPY'
155
155
  product.master.default_price.save!
156
- Spree::Config[:currency] = 'JPY'
156
+ stub_spree_preferences(currency: 'JPY')
157
157
  end
158
158
 
159
159
  it "displays the currency in yen" do
@@ -514,12 +514,12 @@ RSpec.describe Spree::Product, type: :model do
514
514
 
515
515
  context '#total_on_hand' do
516
516
  it 'should be infinite if track_inventory_levels is false' do
517
- Spree::Config[:track_inventory_levels] = false
517
+ stub_spree_preferences(track_inventory_levels: false)
518
518
  expect(build(:product, variants_including_master: [build(:master_variant)]).total_on_hand).to eql(Float::INFINITY)
519
519
  end
520
520
 
521
521
  it 'should be infinite if variant is on demand' do
522
- Spree::Config[:track_inventory_levels] = true
522
+ stub_spree_preferences(track_inventory_levels: true)
523
523
  expect(build(:product, variants_including_master: [build(:on_demand_master_variant)]).total_on_hand).to eql(Float::INFINITY)
524
524
  end
525
525
 
@@ -8,11 +8,11 @@ RSpec.describe Spree::Promotion::Rules::FirstOrder, type: :model do
8
8
  let(:user) { mock_model(Spree::LegacyUser) }
9
9
 
10
10
  context "without a user or email" do
11
- it { expect(rule).not_to be_eligible(order) }
12
- it "sets an error message" do
11
+ it { expect(rule).to be_eligible(order) }
12
+ it "does not set an error message" do
13
13
  rule.eligible?(order)
14
14
  expect(rule.eligibility_errors.full_messages.first).
15
- to eq "You need to login or provide your email before applying this coupon code."
15
+ to be_nil
16
16
  end
17
17
  end
18
18
 
@@ -51,6 +51,11 @@ RSpec.describe Spree::Promotion::Rules::FirstOrder, type: :model do
51
51
  expect(rule.eligibility_errors.full_messages.first).
52
52
  to eq "This coupon code can only be applied to your first order."
53
53
  end
54
+ it "sets an error code" do
55
+ rule.eligible?(order)
56
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
57
+ to eq :not_first_order
58
+ end
54
59
  end
55
60
  end
56
61
  end
@@ -71,6 +76,11 @@ RSpec.describe Spree::Promotion::Rules::FirstOrder, type: :model do
71
76
  expect(rule.eligibility_errors.full_messages.first).
72
77
  to eq "This coupon code can only be applied to your first order."
73
78
  end
79
+ it "sets an error code" do
80
+ rule.eligible?(order)
81
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
82
+ to eq :not_first_order
83
+ end
74
84
  end
75
85
  end
76
86
  end
@@ -44,6 +44,11 @@ RSpec.describe Spree::Promotion::Rules::ItemTotal, type: :model do
44
44
  expect(rule.eligibility_errors.full_messages.first).
45
45
  to eq "This coupon code can't be applied to orders less than or equal to $50.00."
46
46
  end
47
+ it "sets an error code" do
48
+ rule.eligible?(order)
49
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
50
+ to eq :item_total_less_than_or_equal
51
+ end
47
52
  end
48
53
 
49
54
  context "when item total is lower than preferred amount" do
@@ -58,6 +63,11 @@ RSpec.describe Spree::Promotion::Rules::ItemTotal, type: :model do
58
63
  expect(rule.eligibility_errors.full_messages.first).
59
64
  to eq "This coupon code can't be applied to orders less than or equal to $50.00."
60
65
  end
66
+ it "sets an error code" do
67
+ rule.eligible?(order)
68
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
69
+ to eq :item_total_less_than_or_equal
70
+ end
61
71
  end
62
72
  end
63
73
 
@@ -108,6 +118,11 @@ RSpec.describe Spree::Promotion::Rules::ItemTotal, type: :model do
108
118
  expect(rule.eligibility_errors.full_messages.first).
109
119
  to eq "This coupon code can't be applied to orders less than $50.00."
110
120
  end
121
+ it "sets an error code" do
122
+ rule.eligible?(order)
123
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
124
+ to eq :item_total_less_than
125
+ end
111
126
  end
112
127
  end
113
128
  end
@@ -24,6 +24,11 @@ RSpec.describe Spree::Promotion::Rules::OneUsePerUser, type: :model do
24
24
  expect(rule.eligibility_errors.full_messages.first).
25
25
  to eq "This coupon code can only be used once per user."
26
26
  end
27
+ it "sets an error code" do
28
+ rule.eligible?(order)
29
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
30
+ to eq :limit_once_per_user
31
+ end
27
32
  end
28
33
 
29
34
  context 'when the user has not used this promotion before' do
@@ -39,6 +44,11 @@ RSpec.describe Spree::Promotion::Rules::OneUsePerUser, type: :model do
39
44
  expect(rule.eligibility_errors.full_messages.first).
40
45
  to eq "You need to login before applying this coupon code."
41
46
  end
47
+ it "sets an error code" do
48
+ rule.eligible?(order)
49
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
50
+ to eq :no_user_specified
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -38,6 +38,11 @@ RSpec.describe Spree::Promotion::Rules::Product, type: :model do
38
38
  expect(rule.eligibility_errors.full_messages.first).
39
39
  to eq "You need to add an applicable product before applying this coupon code."
40
40
  end
41
+ it "sets an error code" do
42
+ rule.eligible?(order)
43
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
44
+ to eq :no_applicable_products
45
+ end
41
46
  end
42
47
  end
43
48
 
@@ -61,6 +66,11 @@ RSpec.describe Spree::Promotion::Rules::Product, type: :model do
61
66
  expect(rule.eligibility_errors.full_messages.first).
62
67
  to eq "This coupon code can't be applied because you don't have all of the necessary products in your cart."
63
68
  end
69
+ it "sets an error code" do
70
+ rule.eligible?(order)
71
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
72
+ to eq :missing_product
73
+ end
64
74
  end
65
75
  end
66
76
 
@@ -84,6 +94,11 @@ RSpec.describe Spree::Promotion::Rules::Product, type: :model do
84
94
  expect(rule.eligibility_errors.full_messages.first).
85
95
  to eq "Your cart contains a product that prevents this coupon code from being applied."
86
96
  end
97
+ it "sets an error code" do
98
+ rule.eligible?(order)
99
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
100
+ to eq :has_excluded_product
101
+ end
87
102
  end
88
103
  end
89
104
 
@@ -48,6 +48,11 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
48
48
  expect(rule.eligibility_errors.full_messages.first).
49
49
  to eq "You need to add a product from an applicable category before applying this coupon code."
50
50
  end
51
+ it "sets an error code" do
52
+ rule.eligible?(order)
53
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
54
+ to eq :no_matching_taxons
55
+ end
51
56
  end
52
57
 
53
58
  context 'when a product has a taxon child of a taxon rule' do
@@ -83,6 +88,11 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
83
88
  expect(rule.eligibility_errors.full_messages.first).
84
89
  to eq "You need to add a product from all applicable categories before applying this coupon code."
85
90
  end
91
+ it "sets an error code" do
92
+ rule.eligible?(order)
93
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
94
+ to eq :missing_taxon
95
+ end
86
96
  end
87
97
 
88
98
  context 'when a product has a taxon child of a taxon rule' do
@@ -91,7 +101,6 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
91
101
  before do
92
102
  taxon.children << taxon2
93
103
  taxon.save!
94
- taxon.reload
95
104
  product.taxons = [taxon2, taxon3]
96
105
  rule.taxons = [taxon, taxon3]
97
106
  end
@@ -123,6 +132,11 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
123
132
  expect(rule.eligibility_errors.full_messages.first).
124
133
  to eq "Your cart contains a product from an excluded category that prevents this coupon code from being applied."
125
134
  end
135
+ it "sets an error code" do
136
+ rule.eligible?(order)
137
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
138
+ to eq :has_excluded_taxon
139
+ end
126
140
  end
127
141
  end
128
142
 
@@ -152,14 +166,14 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
152
166
  let(:order) { create :order_with_line_items }
153
167
  let(:taxon) { create :taxon, name: 'first' }
154
168
 
155
- before do
156
- rule.preferred_match_policy = 'invalid'
157
- rule.save!(validate: false)
158
- line_item.product.taxons << taxon
159
- rule.taxons << taxon
160
- end
161
-
162
169
  context 'with an invalid match policy' do
170
+ before do
171
+ rule.preferred_match_policy = 'invalid'
172
+ rule.save!(validate: false)
173
+ line_item.product.taxons << taxon
174
+ rule.taxons << taxon
175
+ end
176
+
163
177
  it 'logs a warning and uses "any" policy' do
164
178
  expect(Spree::Deprecation).to(
165
179
  receive(:warn).
@@ -171,5 +185,42 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
171
185
  ).to be_truthy
172
186
  end
173
187
  end
188
+
189
+ context 'when a product has a taxon of a taxon rule' do
190
+ before do
191
+ product.taxons << taxon
192
+ rule.taxons << taxon
193
+ rule.save!
194
+ end
195
+
196
+ it 'is actionable' do
197
+ expect(rule).to be_actionable(line_item)
198
+ end
199
+ end
200
+
201
+ context 'when a product has a taxon child of a taxon rule' do
202
+ before do
203
+ taxon.children << taxon2
204
+ product.taxons << taxon2
205
+ rule.taxons << taxon
206
+ rule.save!
207
+ end
208
+
209
+ it 'is actionable' do
210
+ expect(rule).to be_actionable(line_item)
211
+ end
212
+ end
213
+
214
+ context 'when a product does not have taxon or child taxon of a taxon rule' do
215
+ before do
216
+ product.taxons << taxon2
217
+ rule.taxons << taxon
218
+ rule.save!
219
+ end
220
+
221
+ it 'is not actionable' do
222
+ expect(rule).not_to be_actionable(line_item)
223
+ end
224
+ end
174
225
  end
175
226
  end
@@ -23,6 +23,11 @@ RSpec.describe Spree::Promotion::Rules::UserLoggedIn, type: :model do
23
23
  expect(rule.eligibility_errors.full_messages.first).
24
24
  to eq "You need to login before applying this coupon code."
25
25
  end
26
+ it "sets an error code" do
27
+ rule.eligible?(order)
28
+ expect(rule.eligibility_errors.details[:base].first[:error_code]).
29
+ to eq :no_user_specified
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -76,7 +76,7 @@ module Spree
76
76
  before do
77
77
  stub_const('CustomShippingAction', custom_klass)
78
78
 
79
- Spree::Config.environment.promotions.shipping_actions = ['CustomShippingAction']
79
+ allow(Spree::Config.environment.promotions).to receive(:shipping_actions) { ['CustomShippingAction'] }
80
80
 
81
81
  order.order_promotions.create!(promotion: promotion, promotion_code: promotion.codes.first)
82
82
  end
@@ -384,6 +384,86 @@ RSpec.describe Spree::Promotion, type: :model do
384
384
  end
385
385
  end
386
386
 
387
+ describe '#not_started?' do
388
+ let(:promotion) { Spree::Promotion.new(starts_at: starts_at) }
389
+ subject { promotion.not_started? }
390
+
391
+ context 'no starts_at date' do
392
+ let(:starts_at) { nil }
393
+ it { is_expected.to be_falsey }
394
+ end
395
+
396
+ context 'when starts_at date is in the past' do
397
+ let(:starts_at) { Time.current - 1.day }
398
+ it { is_expected.to be_falsey }
399
+ end
400
+
401
+ context 'when starts_at date is not already reached' do
402
+ let(:starts_at) { Time.current + 1.day }
403
+ it { is_expected.to be_truthy }
404
+ end
405
+ end
406
+
407
+ describe '#started?' do
408
+ let(:promotion) { Spree::Promotion.new(starts_at: starts_at) }
409
+ subject { promotion.started? }
410
+
411
+ context 'when no starts_at date' do
412
+ let(:starts_at) { nil }
413
+ it { is_expected.to be_truthy }
414
+ end
415
+
416
+ context 'when starts_at date is in the past' do
417
+ let(:starts_at) { Time.current - 1.day }
418
+ it { is_expected.to be_truthy }
419
+ end
420
+
421
+ context 'when starts_at date is not already reached' do
422
+ let(:starts_at) { Time.current + 1.day }
423
+ it { is_expected.to be_falsey }
424
+ end
425
+ end
426
+
427
+ describe '#expired?' do
428
+ let(:promotion) { Spree::Promotion.new(expires_at: expires_at) }
429
+ subject { promotion.expired? }
430
+
431
+ context 'when no expires_at date' do
432
+ let(:expires_at) { nil }
433
+ it { is_expected.to be_falsey }
434
+ end
435
+
436
+ context 'when expires_at date is not already reached' do
437
+ let(:expires_at) { Time.current + 1.days }
438
+ it { is_expected.to be_falsey }
439
+ end
440
+
441
+ context 'when expires_at date is in the past' do
442
+ let(:expires_at) { Time.current - 1.days }
443
+ it { is_expected.to be_truthy }
444
+ end
445
+ end
446
+
447
+ describe '#not_expired?' do
448
+ let(:promotion) { Spree::Promotion.new(expires_at: expires_at) }
449
+ subject { promotion.not_expired? }
450
+
451
+ context 'when no expired_at date' do
452
+ let(:expires_at) { nil }
453
+ it { is_expected.to be_truthy }
454
+ end
455
+
456
+ context 'when expires_at date is not already reached' do
457
+ let(:expires_at) { Time.current + 1.days }
458
+ it { is_expected.to be_truthy }
459
+ end
460
+
461
+ context 'when expires_at date is in the past' do
462
+ let(:expires_at) { Time.current - 1.days }
463
+ it { is_expected.to be_falsey }
464
+ end
465
+ end
466
+
387
467
  context "#active" do
388
468
  it "should be active" do
389
469
  expect(promotion.active?).to eq(true)
@@ -154,7 +154,8 @@ RSpec.describe Spree::Reimbursement, type: :model do
154
154
  context 'when reimbursement cannot be fully performed' do
155
155
  let!(:non_return_refund) { create(:refund, amount: 1, payment: payment) }
156
156
 
157
- it 'raises IncompleteReimbursement error' do
157
+ it 'does not send a reimbursement email and raises IncompleteReimbursement error' do
158
+ expect(Spree::ReimbursementMailer).not_to receive(:reimbursement_email)
158
159
  expect { subject }.to raise_error(Spree::Reimbursement::IncompleteReimbursementError)
159
160
  end
160
161
  end
@@ -168,7 +169,7 @@ RSpec.describe Spree::Reimbursement, type: :model do
168
169
  end
169
170
  end
170
171
 
171
- it "triggers the reimbursement mailer to be sent" do
172
+ it "triggers the reimbursement mailer to be sent via subscribed event" do
172
173
  expect(Spree::ReimbursementMailer).to receive(:reimbursement_email).with(reimbursement.id) { double(deliver_later: true) }
173
174
  subject
174
175
  end
@@ -43,6 +43,15 @@ RSpec.describe Spree::ReturnItem, type: :model do
43
43
  subject
44
44
  end
45
45
 
46
+ context 'when the `skip_customer_return_processing` flag is not set to true' do
47
+ before { return_item.skip_customer_return_processing = false }
48
+
49
+ it 'shows a deprecation warning' do
50
+ expect(Spree::Deprecation).to receive(:warn)
51
+ subject
52
+ end
53
+ end
54
+
46
55
  context 'when there is a received return item with the same inventory unit' do
47
56
  let!(:return_item_with_dupe_inventory_unit) { create(:return_item, inventory_unit: inventory_unit, reception_status: 'received') }
48
57
 
@@ -328,7 +328,7 @@ RSpec.describe Spree::Shipment, type: :model do
328
328
 
329
329
  context "when payment is not required" do
330
330
  before do
331
- Spree::Config[:require_payment_to_ship] = false
331
+ stub_spree_preferences(require_payment_to_ship: false)
332
332
  end
333
333
 
334
334
  it "should result in a 'ready' state" do
@@ -391,7 +391,7 @@ RSpec.describe Spree::Shipment, type: :model do
391
391
  end
392
392
 
393
393
  context "with inventory tracking" do
394
- before { Spree::Config.set track_inventory_levels: true }
394
+ before { stub_spree_preferences(track_inventory_levels: true) }
395
395
 
396
396
  it "should validate with inventory" do
397
397
  shipment.inventory_units = [create(:inventory_unit)]
@@ -400,7 +400,7 @@ RSpec.describe Spree::Shipment, type: :model do
400
400
  end
401
401
 
402
402
  context "without inventory tracking" do
403
- before { Spree::Config.set track_inventory_levels: false }
403
+ before { stub_spree_preferences(track_inventory_levels: false) }
404
404
 
405
405
  it "should validate with no inventory" do
406
406
  expect(shipment.valid?).to be true