solidus_core 2.2.2 → 2.3.0.beta1
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/README.md +4 -7
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +3 -4
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/adjustment.rb +3 -1
- data/app/models/spree/app_configuration.rb +43 -0
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +3 -1
- data/app/models/spree/calculator/distributed_amount.rb +24 -0
- data/app/models/spree/calculator/free_shipping.rb +0 -1
- data/app/models/spree/calculator/tiered_flat_rate.rb +17 -3
- data/app/models/spree/calculator/tiered_percent.rb +18 -3
- data/app/models/spree/distributed_amounts_handler.rb +43 -0
- data/app/models/spree/gateway/bogus.rb +7 -83
- data/app/models/spree/gateway/bogus_simple.rb +7 -20
- data/app/models/spree/gateway.rb +8 -58
- data/app/models/spree/image.rb +1 -1
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order/checkout.rb +1 -4
- data/app/models/spree/order/number_generator.rb +43 -0
- data/app/models/spree/order.rb +33 -38
- data/app/models/spree/order_contents.rb +1 -1
- data/app/models/spree/order_taxation.rb +79 -0
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +55 -33
- data/app/models/spree/payment.rb +0 -1
- data/app/models/spree/payment_method/bogus_credit_card.rb +87 -0
- data/app/models/spree/payment_method/check.rb +14 -6
- data/app/models/spree/payment_method/credit_card.rb +41 -0
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +24 -0
- data/app/models/spree/payment_method/store_credit.rb +5 -13
- data/app/models/spree/payment_method.rb +126 -40
- data/app/models/spree/preferences/preferable.rb +5 -1
- data/app/models/spree/preferences/store.rb +2 -2
- data/app/models/spree/product/scopes.rb +14 -1
- data/app/models/spree/product.rb +10 -4
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code/batch_builder.rb +3 -2
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/role.rb +2 -0
- data/app/models/spree/role_user.rb +2 -0
- data/app/models/spree/shipment.rb +4 -2
- data/app/models/spree/shipping_method.rb +3 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/state.rb +10 -2
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/store.rb +5 -0
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/store_credit_event.rb +1 -1
- data/app/models/spree/store_selector/by_server_name.rb +30 -0
- data/app/models/spree/store_selector/legacy.rb +48 -0
- data/app/models/spree/tax/item_tax.rb +20 -0
- data/app/models/spree/tax/order_adjuster.rb +2 -14
- data/app/models/spree/tax/order_tax.rb +18 -0
- data/app/models/spree/tax/shipping_rate_taxer.rb +4 -13
- data/app/models/spree/tax/tax_helpers.rb +5 -3
- data/app/models/spree/tax_calculator/default.rb +83 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +46 -0
- data/app/models/spree/tax_category.rb +9 -1
- data/app/models/spree/tax_rate.rb +31 -7
- data/app/models/spree/tax_rate_tax_category.rb +6 -0
- data/app/models/spree/taxon.rb +1 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/views/spree/{shipment_mailer → carton_mailer}/shipped_email.html.erb +3 -3
- data/app/views/spree/order_mailer/cancel_email.html.erb +3 -3
- data/app/views/spree/order_mailer/confirm_email.html.erb +2 -2
- data/app/views/spree/order_mailer/inventory_cancellation_email.html.erb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +2 -2
- data/app/views/spree/test_mailer/test_email.html.erb +2 -2
- data/config/locales/en.yml +66 -57
- data/db/default/spree/refund_reasons.rb +1 -0
- data/db/default/spree/shipping_categories.rb +1 -0
- data/db/default/spree/stock_locations.rb +2 -0
- data/db/default/spree/stores.rb +3 -4
- data/db/migrate/20170412103617_transform_tax_rate_category_relation.rb +48 -0
- data/db/migrate/20170422134804_add_roles_unique_constraints.rb +6 -0
- data/db/migrate/20170522143442_add_time_range_to_tax_rate.rb +6 -0
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +13 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -1
- data/lib/generators/spree/dummy/dummy_generator.rb +10 -4
- data/lib/generators/spree/dummy/templates/rails/database.yml +12 -12
- data/lib/generators/spree/install/install_generator.rb +5 -5
- data/lib/generators/spree/install/templates/config/initializers/{spree.rb → solidus.rb} +0 -0
- data/lib/solidus/migrations/rename_gateways.rb +39 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +10 -5
- data/lib/spree/core/controller_helpers/store.rb +1 -9
- data/lib/spree/core/current_store.rb +6 -14
- data/lib/spree/core/engine.rb +4 -3
- data/lib/spree/core/importer/order.rb +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +0 -1
- data/lib/spree/localized_number.rb +2 -1
- data/lib/spree/permitted_attributes.rb +12 -6
- data/lib/spree/testing_support/capybara_ext.rb +0 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +5 -1
- data/lib/spree/testing_support/factories/order_factory.rb +26 -24
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -3
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +3 -1
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -4
- data/lib/tasks/migrations/migrate_user_addresses.rake +2 -2
- data/lib/tasks/migrations/rename_gateways.rake +19 -0
- data/solidus_core.gemspec +2 -3
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +32 -6
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -1
- data/spec/lib/spree/core/current_store_spec.rb +6 -11
- data/spec/lib/spree/core/price_migrator_spec.rb +4 -4
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +199 -91
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +18 -0
- data/spec/lib/spree/localized_number_spec.rb +6 -0
- data/spec/mailers/carton_mailer_spec.rb +3 -3
- data/spec/models/spree/address_spec.rb +3 -3
- data/spec/models/spree/adjustment_spec.rb +71 -27
- data/spec/models/spree/calculator/default_tax_spec.rb +72 -1
- data/spec/models/spree/calculator/distributed_amount_spec.rb +32 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +20 -1
- data/spec/models/spree/calculator/tiered_percent_spec.rb +20 -1
- data/spec/models/spree/distributed_amounts_handler_spec.rb +79 -0
- data/spec/models/spree/gateway/bogus_simple.rb +7 -13
- data/spec/models/spree/gateway/bogus_spec.rb +8 -4
- data/spec/models/spree/gateway_spec.rb +6 -105
- data/spec/models/spree/image_spec.rb +23 -0
- data/spec/models/spree/order/checkout_spec.rb +3 -18
- data/spec/models/spree/order/number_generator_spec.rb +45 -0
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +135 -0
- data/spec/models/spree/order/payment_spec.rb +7 -2
- data/spec/models/spree/order/state_machine_spec.rb +4 -2
- data/spec/models/spree/order_capturing_spec.rb +8 -8
- data/spec/models/spree/order_contents_spec.rb +8 -1
- data/spec/models/spree/order_shipping_spec.rb +5 -1
- data/spec/models/spree/order_spec.rb +156 -83
- data/spec/models/spree/order_taxation_spec.rb +126 -0
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +20 -21
- data/spec/models/spree/payment_create_spec.rb +14 -6
- data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +8 -0
- data/spec/models/spree/payment_method/check_spec.rb +78 -0
- data/spec/models/spree/payment_method/credit_card_spec.rb +66 -0
- data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +18 -0
- data/spec/models/spree/payment_method_spec.rb +47 -2
- data/spec/models/spree/payment_spec.rb +6 -8
- data/spec/models/spree/preference_spec.rb +1 -1
- data/spec/models/spree/price_spec.rb +1 -1
- data/spec/models/spree/product/scopes_spec.rb +46 -0
- data/spec/models/spree/promotion_action_spec.rb +4 -0
- data/spec/models/spree/promotion_code/batch_builder_spec.rb +25 -3
- data/spec/models/spree/promotion_code_batch_spec.rb +0 -6
- data/spec/models/spree/promotion_handler/coupon_spec.rb +1 -1
- data/spec/models/spree/promotion_rule_spec.rb +5 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +24 -3
- data/spec/models/spree/shipping_rate_spec.rb +5 -5
- data/spec/models/spree/state_spec.rb +31 -4
- data/spec/models/spree/stock/coordinator_spec.rb +24 -0
- data/spec/models/spree/stock/estimator_spec.rb +1 -1
- data/spec/models/spree/store_selector/by_server_name_spec.rb +26 -0
- data/spec/models/spree/store_selector/legacy_spec.rb +44 -0
- data/spec/models/spree/store_spec.rb +10 -2
- data/spec/models/spree/tax/order_adjuster_spec.rb +11 -21
- data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +10 -3
- data/spec/models/spree/tax/taxation_integration_spec.rb +43 -8
- data/spec/models/spree/tax_calculator/default_spec.rb +54 -0
- data/spec/models/spree/tax_rate_spec.rb +92 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +4 -4
- data/spec/models/spree/variant_spec.rb +8 -2
- data/spec/spec_helper.rb +2 -1
- data/spec/support/test_gateway.rb +1 -1
- metadata +45 -24
- data/app/models/spree/tax/item_adjuster.rb +0 -51
- data/spec/models/spree/tax/item_adjuster_spec.rb +0 -82
|
@@ -147,7 +147,8 @@ describe Spree::Order, type: :model do
|
|
|
147
147
|
it_behaves_like "it references the user's the default address" do
|
|
148
148
|
let(:address_kind) { :bill }
|
|
149
149
|
before do
|
|
150
|
-
order.user = FactoryGirl.create(:user
|
|
150
|
+
order.user = FactoryGirl.create(:user)
|
|
151
|
+
order.user.default_address = default_address
|
|
151
152
|
order.next!
|
|
152
153
|
order.reload
|
|
153
154
|
end
|
|
@@ -184,7 +185,7 @@ describe Spree::Order, type: :model do
|
|
|
184
185
|
|
|
185
186
|
it "recalculates tax and updates totals" do
|
|
186
187
|
zone = create(:zone, countries: [order.tax_address.country])
|
|
187
|
-
create(:tax_rate,
|
|
188
|
+
create(:tax_rate, tax_categories: [line_item.tax_category], amount: 0.05, zone: zone)
|
|
188
189
|
order.next!
|
|
189
190
|
expect(order).to have_attributes(
|
|
190
191
|
adjustment_total: 0.5,
|
|
@@ -589,22 +590,6 @@ describe Spree::Order, type: :model do
|
|
|
589
590
|
end
|
|
590
591
|
end
|
|
591
592
|
|
|
592
|
-
context 'a shipment has no shipping rates' do
|
|
593
|
-
let(:order) { create(:order_with_line_items, state: 'confirm') }
|
|
594
|
-
let(:shipment) { order.shipments.first }
|
|
595
|
-
|
|
596
|
-
before do
|
|
597
|
-
shipment.shipping_rates.destroy_all
|
|
598
|
-
end
|
|
599
|
-
|
|
600
|
-
it 'clears the shipments and fails the transition' do
|
|
601
|
-
expect(order.complete).to eq(false)
|
|
602
|
-
expect(order.errors[:base]).to include(Spree.t(:items_cannot_be_shipped))
|
|
603
|
-
expect(order.shipments.count).to eq(0)
|
|
604
|
-
expect(Spree::InventoryUnit.where(shipment_id: shipment.id).count).to eq(0)
|
|
605
|
-
end
|
|
606
|
-
end
|
|
607
|
-
|
|
608
593
|
context 'the order is already paid' do
|
|
609
594
|
let(:order) { create(:order_with_line_items) }
|
|
610
595
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Spree::Order::NumberGenerator do
|
|
4
|
+
subject { described_class.new.generate }
|
|
5
|
+
|
|
6
|
+
it { is_expected.to be_a(String) }
|
|
7
|
+
|
|
8
|
+
describe 'length' do
|
|
9
|
+
let(:default_length) do
|
|
10
|
+
Spree::Order::ORDER_NUMBER_LENGTH + Spree::Order::ORDER_NUMBER_PREFIX.length
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it { expect(subject.length).to eq default_length }
|
|
14
|
+
|
|
15
|
+
context "when length option is 5" do
|
|
16
|
+
let(:option_length) { 5 + Spree::Order::ORDER_NUMBER_PREFIX.length }
|
|
17
|
+
|
|
18
|
+
subject { described_class.new(length: 5).generate }
|
|
19
|
+
|
|
20
|
+
it "should be 5 plus default prefix length" do
|
|
21
|
+
expect(subject.length).to eq option_length
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "when letters option is true" do
|
|
27
|
+
subject { described_class.new(letters: true).generate }
|
|
28
|
+
|
|
29
|
+
it "generates order number including letters" do
|
|
30
|
+
is_expected.to match /[A-Z]/
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'prefix' do
|
|
35
|
+
it { is_expected.to match /^#{Spree::Order::ORDER_NUMBER_PREFIX}/ }
|
|
36
|
+
|
|
37
|
+
context "when prefix option is 'P'" do
|
|
38
|
+
subject { described_class.new(prefix: 'P').generate }
|
|
39
|
+
|
|
40
|
+
it "generates order number prefixed with 'P'" do
|
|
41
|
+
is_expected.to match /^P/
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# This method in particular has been difficult to get right.
|
|
4
|
+
# Many things will affect this amount
|
|
5
|
+
#
|
|
6
|
+
# See also:
|
|
7
|
+
# https://github.com/solidusio/solidus/issues/1254
|
|
8
|
+
# https://github.com/spree/spree/issues/6229
|
|
9
|
+
# https://github.com/solidusio/solidus/issues/1107
|
|
10
|
+
# https://github.com/solidusio/solidus/pull/1557
|
|
11
|
+
# https://github.com/solidusio/solidus/pull/1536
|
|
12
|
+
|
|
13
|
+
RSpec.describe "Outstanding balance integration tests" do
|
|
14
|
+
let!(:order) { create(:order_with_line_items, line_items_count: 2, line_items_price: 3, shipment_cost: 13) }
|
|
15
|
+
let(:item_1) { order.line_items[0] }
|
|
16
|
+
let(:item_2) { order.line_items[1] }
|
|
17
|
+
before { order.update_attributes!(state: 'complete', completed_at: Time.now) }
|
|
18
|
+
|
|
19
|
+
subject do
|
|
20
|
+
order.reload
|
|
21
|
+
order.update!
|
|
22
|
+
order.outstanding_balance
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'when the order is unpaid' do
|
|
26
|
+
it { should eq order.total }
|
|
27
|
+
it { should eq 19 }
|
|
28
|
+
|
|
29
|
+
context 'when the order is cancelled' do
|
|
30
|
+
before { order.cancel! }
|
|
31
|
+
it { should eq 0 }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when the order is fully paid' do
|
|
36
|
+
let!(:payment) { create(:payment, :completed, order: order, amount: order.total) }
|
|
37
|
+
it { should eq 0 }
|
|
38
|
+
|
|
39
|
+
context 'and there is a full refund' do
|
|
40
|
+
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) }
|
|
41
|
+
it { should eq 19 }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'when the order is cancelled' do
|
|
45
|
+
before { order.update_attributes!(state: "canceled") }
|
|
46
|
+
it { should eq(-19) }
|
|
47
|
+
|
|
48
|
+
context 'and the payment is voided' do
|
|
49
|
+
before { payment.update_attributes!(state: "void") }
|
|
50
|
+
it { should eq 0 }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'and there is a full refund' do
|
|
54
|
+
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) }
|
|
55
|
+
it { should eq 0 }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'and there is a partial refund' do
|
|
59
|
+
let!(:refund) { create(:refund, payment: payment, amount: 6) }
|
|
60
|
+
it { should eq(-13) }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'with a removed item' do
|
|
65
|
+
before do
|
|
66
|
+
item_amount = item_1.final_amount
|
|
67
|
+
order.contents.remove(item_1.variant)
|
|
68
|
+
create(:refund, payment: payment, amount: item_amount)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it { should eq(0) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context 'when the order is adjusted downward by an admin' do
|
|
75
|
+
let!(:adjustment) { create(:adjustment, order: order, adjustable: item_1, amount: -1, source: nil) }
|
|
76
|
+
let!(:refund) { create(:refund, payment: payment, amount: 1) }
|
|
77
|
+
|
|
78
|
+
it { should eq(0) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'with a cancelled item' do
|
|
82
|
+
let(:cancelations) { Spree::OrderCancellations.new(order) }
|
|
83
|
+
let(:cancelled_item) { item_1 }
|
|
84
|
+
|
|
85
|
+
before do
|
|
86
|
+
# Required to refund
|
|
87
|
+
Spree::RefundReason.create!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
|
|
88
|
+
|
|
89
|
+
cancelations.cancel_unit(cancelled_item.inventory_units.first)
|
|
90
|
+
cancelations.reimburse_units(cancelled_item.inventory_units)
|
|
91
|
+
|
|
92
|
+
order.reload
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'discounts the cancelled item amount' do
|
|
96
|
+
expect(order.refund_total).to eq(3)
|
|
97
|
+
expect(order.reimbursement_total).to eq(3)
|
|
98
|
+
expect(order.payment_total).to eq(16)
|
|
99
|
+
expect(order.outstanding_balance).to eq(0)
|
|
100
|
+
|
|
101
|
+
expect(order.total).to eq(19)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'when the order is partly paid' do
|
|
107
|
+
let!(:payment) { create(:payment, :completed, order: order, amount: 10) }
|
|
108
|
+
it { should eq 9 }
|
|
109
|
+
|
|
110
|
+
context 'and there is a full refund' do
|
|
111
|
+
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) }
|
|
112
|
+
it { should eq 19 }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context 'when the order is cancelled' do
|
|
116
|
+
before { order.update_attributes!(state: "canceled") }
|
|
117
|
+
it { should eq(-10) }
|
|
118
|
+
|
|
119
|
+
context 'and the payment is voided' do
|
|
120
|
+
before { payment.update_attributes!(state: "void") }
|
|
121
|
+
it { should eq 0 }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'and there is a full refund' do
|
|
125
|
+
let!(:refund) { create(:refund, payment: payment, amount: payment.amount) }
|
|
126
|
+
it { should eq 0 }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context 'and there is a partial refund' do
|
|
130
|
+
let!(:refund) { create(:refund, payment: payment, amount: 6) }
|
|
131
|
+
it { should eq(-4) }
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -182,8 +182,13 @@ module Spree
|
|
|
182
182
|
context "for canceled orders" do
|
|
183
183
|
before { order.update_attributes(state: 'canceled') }
|
|
184
184
|
|
|
185
|
-
it "it should be
|
|
186
|
-
expect(order.
|
|
185
|
+
it "it should be zero" do
|
|
186
|
+
expect(order.total).to eq(110)
|
|
187
|
+
expect(order.payments.sum(:amount)).to eq(10)
|
|
188
|
+
expect(order.refund_total).to eq(10)
|
|
189
|
+
expect(order.reimbursement_total).to eq(10)
|
|
190
|
+
expect(order.payment_total).to eq(0)
|
|
191
|
+
expect(order.outstanding_balance).to eq(0)
|
|
187
192
|
end
|
|
188
193
|
end
|
|
189
194
|
|
|
@@ -43,7 +43,7 @@ describe Spree::Order, type: :model do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "adjusts tax rates when transitioning to delivery" do
|
|
46
|
-
expect(Spree::
|
|
46
|
+
expect(Spree::TaxCalculator::Default).to receive(:new).once.with(order).and_call_original
|
|
47
47
|
order.next!
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -82,7 +82,9 @@ describe Spree::Order, type: :model do
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it "should send a cancel email" do
|
|
85
|
-
|
|
85
|
+
perform_enqueued_jobs do
|
|
86
|
+
order.cancel!
|
|
87
|
+
end
|
|
86
88
|
|
|
87
89
|
mail = ActionMailer::Base.deliveries.last
|
|
88
90
|
expect(mail.subject).to include "Cancellation"
|
|
@@ -38,7 +38,7 @@ describe Spree::OrderCapturing do
|
|
|
38
38
|
|
|
39
39
|
let!(:product) { create(:product, price: 10.00) }
|
|
40
40
|
let!(:variant) do
|
|
41
|
-
create(:variant, price: 10, product: product, track_inventory: false, tax_category: tax_rate.
|
|
41
|
+
create(:variant, price: 10, product: product, track_inventory: false, tax_category: tax_rate.tax_categories.first)
|
|
42
42
|
end
|
|
43
43
|
let!(:shipping_method) { create(:free_shipping_method) }
|
|
44
44
|
let(:tax_rate) { create(:tax_rate, amount: 0.1, zone: create(:global_zone, name: "Some Tax Zone")) }
|
|
@@ -58,10 +58,10 @@ describe Spree::OrderCapturing do
|
|
|
58
58
|
context "payment method ordering" do
|
|
59
59
|
let(:secondary_payment_method) { SecondaryBogusPaymentMethod }
|
|
60
60
|
|
|
61
|
-
class SecondaryBogusPaymentMethod < Spree::
|
|
61
|
+
class SecondaryBogusPaymentMethod < Spree::PaymentMethod::BogusCreditCard; end
|
|
62
62
|
|
|
63
63
|
context "SecondaryBogusPaymentMethod payments are prioritized" do
|
|
64
|
-
let(:payment_methods) { [SecondaryBogusPaymentMethod, Spree::
|
|
64
|
+
let(:payment_methods) { [SecondaryBogusPaymentMethod, Spree::PaymentMethod::BogusCreditCard] }
|
|
65
65
|
|
|
66
66
|
it "captures SecondaryBogusPaymentMethod payments first" do
|
|
67
67
|
@bogus_payment.update!(amount: bogus_total + 100)
|
|
@@ -72,7 +72,7 @@ describe Spree::OrderCapturing do
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
context "Bogus payments are prioritized" do
|
|
75
|
-
let(:payment_methods) { [Spree::
|
|
75
|
+
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, SecondaryBogusPaymentMethod] }
|
|
76
76
|
|
|
77
77
|
it "captures Bogus payments first" do
|
|
78
78
|
@secondary_bogus_payment.update!(amount: secondary_total + 100)
|
|
@@ -89,7 +89,7 @@ describe Spree::OrderCapturing do
|
|
|
89
89
|
|
|
90
90
|
before do
|
|
91
91
|
allow(Spree::OrderCapturing).to receive(:sorted_payment_method_classes).and_return(
|
|
92
|
-
[SecondaryBogusPaymentMethod, Spree::
|
|
92
|
+
[SecondaryBogusPaymentMethod, Spree::PaymentMethod::BogusCreditCard]
|
|
93
93
|
)
|
|
94
94
|
end
|
|
95
95
|
|
|
@@ -103,7 +103,7 @@ describe Spree::OrderCapturing do
|
|
|
103
103
|
|
|
104
104
|
context "when a payment is not needed to capture the entire order" do
|
|
105
105
|
let(:secondary_payment_method) { SecondaryBogusPaymentMethod }
|
|
106
|
-
let(:payment_methods) { [Spree::
|
|
106
|
+
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, SecondaryBogusPaymentMethod] }
|
|
107
107
|
|
|
108
108
|
before do
|
|
109
109
|
@bogus_payment.update!(amount: order.total)
|
|
@@ -132,9 +132,9 @@ describe Spree::OrderCapturing do
|
|
|
132
132
|
let(:secondary_payment_method) { ExceptionallyBogusPaymentMethod }
|
|
133
133
|
let(:bogus_total) { order.total - 1 }
|
|
134
134
|
let(:secondary_total) { 1 }
|
|
135
|
-
let(:payment_methods) { [Spree::
|
|
135
|
+
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, ExceptionallyBogusPaymentMethod] }
|
|
136
136
|
|
|
137
|
-
class ExceptionallyBogusPaymentMethod < Spree::
|
|
137
|
+
class ExceptionallyBogusPaymentMethod < Spree::PaymentMethod::BogusCreditCard
|
|
138
138
|
def capture(*_args)
|
|
139
139
|
raise ActiveMerchant::ConnectionError.new("foo", nil)
|
|
140
140
|
end
|
|
@@ -123,7 +123,7 @@ describe Spree::OrderContents, type: :model do
|
|
|
123
123
|
describe 'tax calculations' do
|
|
124
124
|
let!(:zone) { create(:global_zone) }
|
|
125
125
|
let!(:tax_rate) do
|
|
126
|
-
create(:tax_rate, zone: zone,
|
|
126
|
+
create(:tax_rate, zone: zone, tax_categories: [variant.tax_category])
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
context 'when the order has a taxable address' do
|
|
@@ -203,6 +203,13 @@ describe Spree::OrderContents, type: :model do
|
|
|
203
203
|
expect(order.reload.find_line_item_by_variant(variant)).to be_nil
|
|
204
204
|
end
|
|
205
205
|
|
|
206
|
+
it 'should remove line_item if quantity is greater than line_item quantity' do
|
|
207
|
+
subject.add(variant, 1)
|
|
208
|
+
subject.remove(variant, 2)
|
|
209
|
+
|
|
210
|
+
expect(order.reload.find_line_item_by_variant(variant)).to be_nil
|
|
211
|
+
end
|
|
212
|
+
|
|
206
213
|
it "should update order totals" do
|
|
207
214
|
expect(order.item_total.to_f).to eq(0.00)
|
|
208
215
|
expect(order.total.to_f).to eq(0.00)
|
|
@@ -19,7 +19,11 @@ describe Spree::OrderShipping do
|
|
|
19
19
|
|
|
20
20
|
describe "shipment email" do
|
|
21
21
|
it "should send a shipment email" do
|
|
22
|
-
expect {
|
|
22
|
+
expect {
|
|
23
|
+
perform_enqueued_jobs {
|
|
24
|
+
subject
|
|
25
|
+
}
|
|
26
|
+
}.to change { emails.size }.by(1)
|
|
23
27
|
expect(emails.last.subject).to eq("#{order.store.name} Shipment Notification ##{order.number}")
|
|
24
28
|
end
|
|
25
29
|
end
|