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.
- 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.rb +2 -44
- data/app/models/spree/image/paperclip_attachment.rb +55 -0
- 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.rb +18 -11
- 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_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.rb +4 -11
- data/app/models/spree/taxon/paperclip_attachment.rb +21 -0
- data/app/models/spree/taxonomy.rb +2 -0
- data/app/models/spree/unit_cancel.rb +12 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/models/spree/variant/pricing_options.rb +10 -0
- data/app/models/spree/wallet_payment_source.rb +26 -10
- data/app/models/spree/zone.rb +1 -1
- 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 +0 -3
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +3 -0
- data/lib/solidus/migrations/rename_gateways.rb +2 -0
- data/lib/spree/app_configuration.rb +24 -0
- data/lib/spree/core.rb +1 -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 +5 -0
- 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/deprecation.rb +50 -0
- data/lib/spree/event.rb +111 -0
- data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
- data/lib/spree/event/configuration.rb +17 -0
- data/lib/spree/event/processors/mailer_processor.rb +27 -0
- data/lib/spree/event/subscriber.rb +84 -0
- data/lib/spree/permitted_attributes.rb +7 -76
- 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/{models → lib}/spree/app_configuration_spec.rb +11 -1
- 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/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 +92 -0
- data/spec/lib/spree/money_spec.rb +3 -9
- 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/spec_helper.rb +0 -4
- data/spec/support/concerns/default_price.rb +8 -0
- metadata +18 -5
- data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/event'
|
5
|
+
|
6
|
+
RSpec.describe Spree::Event do
|
7
|
+
let(:subscription_name) { 'foo_bar' }
|
8
|
+
let(:item) { spy('object') }
|
9
|
+
let(:notifier) { ActiveSupport::Notifications.notifier }
|
10
|
+
|
11
|
+
subject { described_class }
|
12
|
+
|
13
|
+
it 'has default adapter' do
|
14
|
+
expect(subject.adapter).to eql Spree::Event::Adapters::ActiveSupportNotifications
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
# ActiveSupport::Notifications does not provide an interface to clean all
|
19
|
+
# subscribers at once, so some low level brittle code is required
|
20
|
+
@old_subscribers = notifier.instance_variable_get('@subscribers').dup
|
21
|
+
@old_listeners = notifier.instance_variable_get('@listeners_for').dup
|
22
|
+
notifier.instance_variable_get('@subscribers').clear
|
23
|
+
notifier.instance_variable_get('@listeners_for').clear
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
notifier.instance_variable_set '@subscribers', @old_subscribers
|
28
|
+
notifier.instance_variable_set '@listeners_for', @old_listeners
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with the default adapter' do
|
32
|
+
describe '#listeners' do
|
33
|
+
context 'when there is no subscription' do
|
34
|
+
it { expect(subject.listeners).to be_empty }
|
35
|
+
|
36
|
+
context 'after adding a subscription' do
|
37
|
+
before do
|
38
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'includes the new subscription with custom suffix' do
|
42
|
+
expect(subject.listeners).to be_present
|
43
|
+
subscription_listeners = subject.listeners["#{subscription_name}.spree"]
|
44
|
+
expect(subscription_listeners).to be_a Array
|
45
|
+
expect(subscription_listeners.first).to be_a ActiveSupport::Notifications::Fanout::Subscribers::Timed
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'subscriptions' do
|
52
|
+
describe '#subscribe' do
|
53
|
+
it 'can subscribe to events' do
|
54
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
55
|
+
Spree::Event.fire subscription_name
|
56
|
+
expect(item).to have_received :do_something
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#unsubscribe' do
|
61
|
+
context 'when unsubscribing using a subscription object as reference' do
|
62
|
+
let!(:subscription) { Spree::Event.subscribe(subscription_name) { item.do_something } }
|
63
|
+
|
64
|
+
before do
|
65
|
+
Spree::Event.subscribe(subscription_name) { item.do_something_else }
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'can unsubscribe from single event by object' do
|
69
|
+
subject.unsubscribe subscription
|
70
|
+
Spree::Event.fire subscription_name
|
71
|
+
expect(item).not_to have_received :do_something
|
72
|
+
expect(item).to have_received :do_something_else
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when unsubscribing using a string as reference' do
|
77
|
+
before do
|
78
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
79
|
+
Spree::Event.subscribe(subscription_name) { item.do_something_else }
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can unsubscribe from multiple events with the same name' do
|
83
|
+
subject.unsubscribe subscription_name
|
84
|
+
Spree::Event.fire subscription_name
|
85
|
+
expect(item).not_to have_received :do_something
|
86
|
+
expect(item).not_to have_received :do_something_else
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -4,9 +4,7 @@ require 'rails_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Spree::Money do
|
6
6
|
before do
|
7
|
-
|
8
|
-
config.currency = "USD"
|
9
|
-
end
|
7
|
+
stub_spree_preferences(currency: "USD")
|
10
8
|
end
|
11
9
|
|
12
10
|
describe '#initialize' do
|
@@ -155,9 +153,7 @@ RSpec.describe Spree::Money do
|
|
155
153
|
|
156
154
|
context "JPY" do
|
157
155
|
before do
|
158
|
-
|
159
|
-
config.currency = "JPY"
|
160
|
-
end
|
156
|
+
stub_spree_preferences(currency: "JPY")
|
161
157
|
end
|
162
158
|
|
163
159
|
it "formats correctly" do
|
@@ -168,9 +164,7 @@ RSpec.describe Spree::Money do
|
|
168
164
|
|
169
165
|
context "EUR" do
|
170
166
|
before do
|
171
|
-
|
172
|
-
config.currency = "EUR"
|
173
|
-
end
|
167
|
+
stub_spree_preferences(currency: "EUR")
|
174
168
|
end
|
175
169
|
|
176
170
|
# Regression test for https://github.com/spree/spree/issues/2634
|
@@ -11,9 +11,11 @@ RSpec.describe 'solidus:migrations:migrate_shipping_rate_taxes' do
|
|
11
11
|
)
|
12
12
|
|
13
13
|
it 'runs' do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
Spree::Deprecation.silence do
|
15
|
+
expect { task.invoke }.to output(
|
16
|
+
"Adding persisted tax notes to historic shipping rates ... Success.\n"
|
17
|
+
).to_stdout
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -109,7 +109,7 @@ RSpec.describe Spree::OrderMailer, type: :mailer do
|
|
109
109
|
|
110
110
|
context "with preference :send_core_emails set to false" do
|
111
111
|
it "sends no email" do
|
112
|
-
|
112
|
+
stub_spree_preferences(send_core_emails: false)
|
113
113
|
message = Spree::OrderMailer.confirm_email(order)
|
114
114
|
expect(message.body).to be_blank
|
115
115
|
end
|
@@ -6,6 +6,8 @@ RSpec.describe Spree::TestMailer, type: :mailer do
|
|
6
6
|
let(:user) { create(:user) }
|
7
7
|
|
8
8
|
it "confirm_email accepts a user id as an alternative to a User object" do
|
9
|
-
Spree::
|
9
|
+
Spree::Deprecation.silence do
|
10
|
+
Spree::TestMailer.test_email('test@example.com')
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
@@ -28,8 +28,9 @@ RSpec.describe Spree::Address, type: :model do
|
|
28
28
|
|
29
29
|
context 'address does not require state' do
|
30
30
|
before do
|
31
|
-
|
31
|
+
stub_spree_preferences(address_requires_state: false)
|
32
32
|
end
|
33
|
+
|
33
34
|
it "address_requires_state preference is false" do
|
34
35
|
address.state = nil
|
35
36
|
address.state_name = nil
|
@@ -39,7 +40,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
39
40
|
|
40
41
|
context 'address requires state' do
|
41
42
|
before do
|
42
|
-
|
43
|
+
stub_spree_preferences(address_requires_state: true)
|
43
44
|
end
|
44
45
|
|
45
46
|
it "state_name is not nil and country does not have any states" do
|
@@ -145,7 +146,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
145
146
|
|
146
147
|
context 'has a default country' do
|
147
148
|
before do
|
148
|
-
|
149
|
+
stub_spree_preferences(default_country_iso: default_country.iso)
|
149
150
|
end
|
150
151
|
|
151
152
|
it "sets up a new record with Spree::Config[:default_country_iso]" do
|
@@ -155,7 +156,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
155
156
|
|
156
157
|
# Regression test for https://github.com/spree/spree/issues/1142
|
157
158
|
it "raises ActiveRecord::RecordNotFound if :default_country_iso is set to an invalid value" do
|
158
|
-
|
159
|
+
stub_spree_preferences(default_country_iso: "00")
|
159
160
|
expect {
|
160
161
|
Spree::Address.build_default.country
|
161
162
|
}.to raise_error(ActiveRecord::RecordNotFound)
|
@@ -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 MailerProcessor module
|
33
|
+
context 'when removing the default email notification subscription' do
|
34
|
+
before do
|
35
|
+
Spree::Event.unsubscribe Spree::Event::Processors::MailerProcessor.order_finalized_handler
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
Spree::Event::Processors::MailerProcessor.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::Event::Processors::MailerProcessor.unsubscribe!
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
Spree::Event::Processors::MailerProcessor.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
|
|