solidus_core 2.8.6 → 2.9.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/app/assets/images/logo/solidus.svg +1 -18
- data/app/assets/images/logo/solidus_logo.png +0 -0
- data/app/mailers/spree/test_mailer.rb +2 -0
- data/app/models/concerns/spree/default_price.rb +1 -1
- data/app/models/concerns/spree/ransackable_attributes.rb +1 -1
- data/app/models/concerns/spree/user_reporting.rb +1 -1
- data/app/models/spree/billing_integration.rb +7 -2
- data/app/models/spree/country.rb +2 -0
- data/app/models/spree/customer_return.rb +1 -1
- data/app/models/spree/image/paperclip_attachment.rb +55 -0
- data/app/models/spree/image.rb +2 -44
- data/app/models/spree/inventory_unit.rb +0 -1
- data/app/models/spree/option_type.rb +2 -0
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order.rb +8 -13
- data/app/models/spree/payment.rb +1 -1
- data/app/models/spree/payment_method.rb +8 -4
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/promotion/rules/first_order.rb +1 -3
- data/app/models/spree/promotion/rules/item_total.rb +9 -1
- data/app/models/spree/promotion/rules/one_use_per_user.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion/rules/taxon.rb +5 -8
- data/app/models/spree/promotion/rules/user_logged_in.rb +1 -1
- data/app/models/spree/promotion.rb +18 -11
- data/app/models/spree/promotion_handler/coupon.rb +19 -3
- data/app/models/spree/property.rb +2 -0
- data/app/models/spree/reimbursement.rb +5 -5
- data/app/models/spree/return_item.rb +6 -2
- data/app/models/spree/state.rb +6 -0
- data/app/models/spree/stock/location_filter/active.rb +14 -0
- data/app/models/spree/stock/location_filter/base.rb +43 -0
- data/app/models/spree/stock/simple_coordinator.rb +4 -1
- data/app/models/spree/stock_location.rb +2 -0
- data/app/models/spree/tax_category.rb +11 -0
- data/app/models/spree/taxon/paperclip_attachment.rb +21 -0
- data/app/models/spree/taxon.rb +4 -11
- data/app/models/spree/taxonomy.rb +2 -0
- data/app/models/spree/unit_cancel.rb +12 -1
- data/app/models/spree/variant/pricing_options.rb +10 -0
- data/app/models/spree/variant.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +26 -10
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +25 -0
- data/app/views/spree/order_mailer/inventory_cancellation_email.text.erb +3 -3
- data/config/locales/en.yml +26 -53
- data/db/default/spree/store_credit.rb +1 -0
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +1 -1
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +9 -8
- data/db/migrate/20190220093635_drop_spree_store_credit_update_reasons.rb +19 -0
- data/lib/generators/spree/install/install_generator.rb +21 -19
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +29 -1
- data/lib/solidus/migrations/rename_gateways.rb +2 -0
- data/lib/spree/app_configuration.rb +69 -47
- data/lib/spree/core/class_constantizer.rb +6 -0
- data/lib/spree/core/controller_helpers/pricing.rb +1 -4
- data/lib/spree/core/controller_helpers/strong_parameters.rb +7 -21
- data/lib/spree/core/engine.rb +11 -0
- data/lib/spree/core/environment/promotions.rb +15 -0
- data/lib/spree/core/environment.rb +1 -1
- data/lib/spree/core/environment_extension.rb +0 -4
- data/lib/spree/core/importer/order.rb +1 -3
- data/lib/spree/core/stock_configuration.rb +5 -0
- data/lib/spree/core/version.rb +3 -1
- data/lib/spree/core.rb +2 -0
- data/lib/spree/deprecation.rb +50 -0
- data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
- data/lib/spree/event/configuration.rb +25 -0
- data/lib/spree/event/subscriber.rb +84 -0
- data/lib/spree/event.rb +117 -0
- data/lib/spree/permitted_attributes.rb +7 -76
- data/lib/spree/promo/environment.rb +6 -7
- data/lib/spree/testing_support/capybara_ext.rb +15 -0
- data/lib/spree/testing_support/common_rake.rb +1 -1
- data/lib/spree/testing_support/dummy_app.rb +3 -10
- data/lib/spree/testing_support/factories/promotion_factory.rb +10 -0
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
- data/lib/spree/testing_support/preferences.rb +62 -0
- data/lib/tasks/email.rake +2 -0
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +4 -0
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +2 -0
- data/lib/tasks/migrations/migrate_user_addresses.rake +3 -0
- data/lib/tasks/migrations/rename_gateways.rake +2 -0
- data/lib/tasks/order_capturing.rake +2 -0
- data/spec/helpers/base_helper_spec.rb +3 -3
- data/spec/helpers/products_helper_spec.rb +2 -2
- data/spec/lib/spree/app_configuration_spec.rb +140 -0
- data/spec/lib/spree/core/class_constantizer_spec.rb +20 -0
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +13 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +1 -8
- data/spec/lib/spree/core/environment_extension_spec.rb +22 -23
- data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +1 -1
- data/spec/lib/spree/core/testing_support/preferences_spec.rb +33 -0
- data/spec/lib/spree/event/subscriber_spec.rb +85 -0
- data/spec/lib/spree/event_spec.rb +118 -0
- data/spec/lib/spree/money_spec.rb +3 -9
- data/spec/lib/spree/promo/environment_spec.rb +53 -0
- data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +5 -3
- data/spec/mailers/order_mailer_spec.rb +1 -1
- data/spec/mailers/test_mailer_spec.rb +3 -1
- data/spec/models/spree/address_spec.rb +5 -4
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/country_spec.rb +5 -5
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +3 -7
- data/spec/models/spree/order/finalizing_spec.rb +1 -1
- data/spec/models/spree/order/payment_spec.rb +3 -3
- data/spec/models/spree/order_inventory_spec.rb +1 -1
- data/spec/models/spree/order_spec.rb +67 -2
- data/spec/models/spree/order_updater_spec.rb +2 -2
- data/spec/models/spree/payment_spec.rb +12 -0
- data/spec/models/spree/product_spec.rb +3 -3
- data/spec/models/spree/promotion/rules/first_order_spec.rb +13 -3
- data/spec/models/spree/promotion/rules/item_total_spec.rb +15 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +10 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +15 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +59 -8
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +5 -0
- data/spec/models/spree/promotion_handler/shipping_spec.rb +1 -1
- data/spec/models/spree/promotion_spec.rb +80 -0
- data/spec/models/spree/reimbursement_spec.rb +3 -2
- data/spec/models/spree/return_item_spec.rb +9 -0
- data/spec/models/spree/shipment_spec.rb +3 -3
- data/spec/models/spree/stock/availability_spec.rb +1 -1
- data/spec/models/spree/stock/estimator_spec.rb +5 -7
- data/spec/models/spree/stock/location_filter/active_spec.rb +22 -0
- data/spec/models/spree/stock/location_sorter/default_first_spec.rb +4 -2
- data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +3 -1
- data/spec/models/spree/stock/quantifier_spec.rb +1 -1
- data/spec/models/spree/stock/simple_coordinator_spec.rb +5 -0
- data/spec/models/spree/stock_item_spec.rb +3 -2
- data/spec/models/spree/stock_movement_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +1 -1
- data/spec/models/spree/tax/order_adjuster_spec.rb +1 -1
- data/spec/models/spree/tax/taxation_integration_spec.rb +1 -1
- data/spec/models/spree/tax_category_spec.rb +21 -0
- data/spec/models/spree/taxon_spec.rb +28 -0
- data/spec/models/spree/unit_cancel_spec.rb +41 -0
- data/spec/models/spree/user_spec.rb +3 -3
- data/spec/models/spree/variant/pricing_options_spec.rb +23 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +1 -1
- data/spec/models/spree/variant_spec.rb +11 -8
- data/spec/models/spree/wallet_payment_source_spec.rb +35 -6
- data/spec/models/spree/wallet_spec.rb +1 -1
- data/spec/rails_helper.rb +1 -0
- data/spec/spec_helper.rb +0 -4
- data/spec/support/concerns/default_price.rb +8 -0
- metadata +21 -6
- data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
- data/spec/models/spree/app_configuration_spec.rb +0 -55
- /data/{spec/support/shared_contexts → lib/spree/testing_support}/rake.rb +0 -0
|
@@ -256,7 +256,7 @@ module Spree
|
|
|
256
256
|
|
|
257
257
|
context "when automatic_default_address preference is at a default of true" do
|
|
258
258
|
before do
|
|
259
|
-
|
|
259
|
+
stub_spree_preferences(automatic_default_address: true)
|
|
260
260
|
expect(user).to receive(:save_in_address_book).with(kind_of(Hash), true)
|
|
261
261
|
expect(user).to receive(:save_in_address_book).with(kind_of(Hash), false)
|
|
262
262
|
end
|
|
@@ -269,7 +269,7 @@ module Spree
|
|
|
269
269
|
|
|
270
270
|
context "when automatic_default_address preference is false" do
|
|
271
271
|
before do
|
|
272
|
-
|
|
272
|
+
stub_spree_preferences(automatic_default_address: false)
|
|
273
273
|
expect(user).to receive(:save_in_address_book).with(kind_of(Hash), false).twice
|
|
274
274
|
# and not the optional 2nd argument
|
|
275
275
|
end
|
|
@@ -283,7 +283,7 @@ module Spree
|
|
|
283
283
|
context "when address is nil" do
|
|
284
284
|
context "when automatic_default_address preference is at a default of true" do
|
|
285
285
|
before do
|
|
286
|
-
|
|
286
|
+
stub_spree_preferences(automatic_default_address: true)
|
|
287
287
|
expect(user).to receive(:save_in_address_book).with(kind_of(Hash), true).once
|
|
288
288
|
end
|
|
289
289
|
|
|
@@ -305,7 +305,7 @@ module Spree
|
|
|
305
305
|
|
|
306
306
|
context "when automatic_default_address preference is false" do
|
|
307
307
|
before do
|
|
308
|
-
|
|
308
|
+
stub_spree_preferences(automatic_default_address: false)
|
|
309
309
|
expect(user).to receive(:save_in_address_book).with(kind_of(Hash), false).once
|
|
310
310
|
end
|
|
311
311
|
|
|
@@ -13,7 +13,7 @@ RSpec.describe Spree::Country, type: :model do
|
|
|
13
13
|
|
|
14
14
|
context 'with the configuration setting an existing legacy default country ID' do
|
|
15
15
|
before do
|
|
16
|
-
|
|
16
|
+
stub_spree_preferences(default_country_id: 2)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
subject(:default_country) do
|
|
@@ -32,7 +32,7 @@ RSpec.describe Spree::Country, type: :model do
|
|
|
32
32
|
|
|
33
33
|
context 'with the configuration setting a non-existing legacy default country ID' do
|
|
34
34
|
before do
|
|
35
|
-
|
|
35
|
+
stub_spree_preferences(default_country_id: 0)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
subject(:default_country) do
|
|
@@ -52,7 +52,7 @@ RSpec.describe Spree::Country, type: :model do
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
context 'with the configuration setting an non-existing ISO code' do
|
|
55
|
-
before {
|
|
55
|
+
before { stub_spree_preferences(default_country_iso: "ZZ") }
|
|
56
56
|
|
|
57
57
|
it 'raises a Record not Found error' do
|
|
58
58
|
expect { described_class.default }.to raise_error(ActiveRecord::RecordNotFound)
|
|
@@ -71,7 +71,7 @@ RSpec.describe Spree::Country, type: :model do
|
|
|
71
71
|
let!(:checkout_zone) { create(:zone, name: 'Checkout Zone', countries: [united_states, canada]) }
|
|
72
72
|
|
|
73
73
|
before do
|
|
74
|
-
|
|
74
|
+
stub_spree_preferences(checkout_zone: checkout_zone.name)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
context 'with no arguments' do
|
|
@@ -104,7 +104,7 @@ RSpec.describe Spree::Country, type: :model do
|
|
|
104
104
|
let!(:checkout_zone) { create(:zone, name: 'Checkout Zone', states: [state]) }
|
|
105
105
|
|
|
106
106
|
before do
|
|
107
|
-
|
|
107
|
+
stub_spree_preferences(checkout_zone: checkout_zone.name)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
context 'with no arguments' do
|
|
@@ -189,7 +189,7 @@ RSpec.describe Spree::CustomerReturn, type: :model do
|
|
|
189
189
|
|
|
190
190
|
context 'with Config.track_inventory_levels == false' do
|
|
191
191
|
before do
|
|
192
|
-
|
|
192
|
+
stub_spree_preferences(track_inventory_levels: false)
|
|
193
193
|
expect(Spree::StockItem).not_to receive(:find_by)
|
|
194
194
|
expect(Spree::StockMovement).not_to receive(:create!)
|
|
195
195
|
end
|
|
@@ -359,6 +359,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
359
359
|
|
|
360
360
|
before do
|
|
361
361
|
user = create(:user, email: 'spree@example.org', bill_address: user_bill_address)
|
|
362
|
+
default_credit_card.update(user: user)
|
|
362
363
|
wallet_payment_source = user.wallet.add(default_credit_card)
|
|
363
364
|
user.wallet.default_wallet_payment_source = wallet_payment_source
|
|
364
365
|
order.user = user
|
|
@@ -497,12 +498,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
497
498
|
|
|
498
499
|
context "with a payment in the pending state" do
|
|
499
500
|
let(:order) { create :order_ready_to_complete }
|
|
500
|
-
let(:payment) { create :payment, state: "pending", amount: order.total }
|
|
501
|
-
|
|
502
|
-
before do
|
|
503
|
-
order.payments = [payment]
|
|
504
|
-
order.save!
|
|
505
|
-
end
|
|
501
|
+
let(:payment) { create :payment, order: order, state: "pending", amount: order.total }
|
|
506
502
|
|
|
507
503
|
it "allows the order to complete" do
|
|
508
504
|
expect { order.complete! }.
|
|
@@ -542,7 +538,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
542
538
|
order.user = FactoryBot.create(:user)
|
|
543
539
|
order.store = FactoryBot.create(:store)
|
|
544
540
|
order.email = 'spree@example.org'
|
|
545
|
-
order.payments << FactoryBot.create(:payment)
|
|
541
|
+
order.payments << FactoryBot.create(:payment, order: order)
|
|
546
542
|
|
|
547
543
|
# make sure we will actually capture a payment
|
|
548
544
|
allow(order).to receive_messages(payment_required?: true)
|
|
@@ -44,7 +44,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "should not send duplicate confirmation emails" do
|
|
47
|
-
|
|
47
|
+
order.update(confirmation_delivered: true)
|
|
48
48
|
expect(Spree::OrderMailer).not_to receive(:confirm_email)
|
|
49
49
|
order.finalize!
|
|
50
50
|
end
|
|
@@ -12,7 +12,7 @@ module Spree
|
|
|
12
12
|
|
|
13
13
|
before do
|
|
14
14
|
# So that Payment#purchase! is called during processing
|
|
15
|
-
|
|
15
|
+
stub_spree_preferences(auto_capture: true)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
let(:payment_method) { create(:credit_card_payment_method) }
|
|
@@ -147,12 +147,12 @@ module Spree
|
|
|
147
147
|
before { expect(payment).to receive(:process!).and_raise(Spree::Core::GatewayError) }
|
|
148
148
|
|
|
149
149
|
it "should return true when configured to allow checkout on gateway failures" do
|
|
150
|
-
|
|
150
|
+
stub_spree_preferences(allow_checkout_on_gateway_error: true)
|
|
151
151
|
expect(order.process_payments!).to be true
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "should return false when not configured to allow checkout on gateway failures" do
|
|
155
|
-
|
|
155
|
+
stub_spree_preferences(allow_checkout_on_gateway_error: false)
|
|
156
156
|
expect(order.process_payments!).to be false
|
|
157
157
|
end
|
|
158
158
|
end
|
|
@@ -72,7 +72,7 @@ RSpec.describe Spree::OrderInventory, type: :model do
|
|
|
72
72
|
context "store doesnt track inventory" do
|
|
73
73
|
let(:new_quantity) { 1 }
|
|
74
74
|
|
|
75
|
-
before {
|
|
75
|
+
before { stub_spree_preferences(track_inventory_levels: false) }
|
|
76
76
|
|
|
77
77
|
it "creates on hand inventory units" do
|
|
78
78
|
variant.stock_items.each(&:really_destroy!)
|
|
@@ -15,6 +15,53 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
15
15
|
end
|
|
16
16
|
let(:code) { promotion.codes.first }
|
|
17
17
|
|
|
18
|
+
describe '#finalize!' do
|
|
19
|
+
context 'with event notifications' do
|
|
20
|
+
it 'sends an email' do
|
|
21
|
+
expect(Spree::Config.order_mailer_class).to receive(:confirm_email).and_call_original
|
|
22
|
+
order.finalize!
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'marks the order as confirmation_delivered' do
|
|
26
|
+
expect do
|
|
27
|
+
order.finalize!
|
|
28
|
+
end.to change(order, :confirmation_delivered).to true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# These specs show how notifications can be removed, one at a time or
|
|
32
|
+
# all the ones set by MailerSubscriber module
|
|
33
|
+
context 'when removing the default email notification subscription' do
|
|
34
|
+
before do
|
|
35
|
+
Spree::Event.unsubscribe Spree::MailerSubscriber.order_finalized_handler
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
after do
|
|
39
|
+
Spree::MailerSubscriber.subscribe!
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'does not send the email' do
|
|
43
|
+
expect(Spree::Config.order_mailer_class).not_to receive(:confirm_email)
|
|
44
|
+
order.finalize!
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context 'when removing all the email notification subscriptions' do
|
|
49
|
+
before do
|
|
50
|
+
Spree::MailerSubscriber.unsubscribe!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
after do
|
|
54
|
+
Spree::MailerSubscriber.subscribe!
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'does not send the email' do
|
|
58
|
+
expect(Spree::Config.order_mailer_class).not_to receive(:confirm_email)
|
|
59
|
+
order.finalize!
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
18
65
|
context '#store' do
|
|
19
66
|
it { is_expected.to respond_to(:store) }
|
|
20
67
|
|
|
@@ -135,7 +182,6 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
135
182
|
before { allow(order).to receive_messages shipments: [shipment] }
|
|
136
183
|
|
|
137
184
|
it "update and persist totals" do
|
|
138
|
-
expect(shipment).to receive :update_amounts
|
|
139
185
|
expect(order.updater).to receive :update
|
|
140
186
|
|
|
141
187
|
Spree::Deprecation.silence do
|
|
@@ -462,7 +508,7 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
462
508
|
let(:order) { build(:order, ship_address: ship_address, bill_address: bill_address, store: store) }
|
|
463
509
|
let(:store) { build(:store) }
|
|
464
510
|
|
|
465
|
-
before {
|
|
511
|
+
before { stub_spree_preferences(tax_using_ship_address: tax_using_ship_address) }
|
|
466
512
|
subject { order.tax_address }
|
|
467
513
|
|
|
468
514
|
context "when the order has no addresses" do
|
|
@@ -1470,6 +1516,25 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
1470
1516
|
end
|
|
1471
1517
|
end
|
|
1472
1518
|
|
|
1519
|
+
describe "#record_ip_address" do
|
|
1520
|
+
let(:ip_address) { "127.0.0.1" }
|
|
1521
|
+
|
|
1522
|
+
subject { -> { order.record_ip_address(ip_address) } }
|
|
1523
|
+
|
|
1524
|
+
it "updates the last used IP address" do
|
|
1525
|
+
expect(subject).to change(order, :last_ip_address).to(ip_address)
|
|
1526
|
+
end
|
|
1527
|
+
|
|
1528
|
+
# IP address tracking should not raise validation exceptions
|
|
1529
|
+
context "with an invalid order" do
|
|
1530
|
+
before { allow(order).to receive(:valid?).and_return(false) }
|
|
1531
|
+
|
|
1532
|
+
it "updates the IP address" do
|
|
1533
|
+
expect(subject).to change(order, :last_ip_address).to(ip_address)
|
|
1534
|
+
end
|
|
1535
|
+
end
|
|
1536
|
+
end
|
|
1537
|
+
|
|
1473
1538
|
describe "#display_order_total_after_store_credit" do
|
|
1474
1539
|
let(:order_total_after_store_credit) { 10.00 }
|
|
1475
1540
|
|
|
@@ -117,7 +117,7 @@ module Spree
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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).
|
|
12
|
-
it "
|
|
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
|
|
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
|
|
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)
|