solidus_core 2.0.3 → 2.1.0.beta1
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/README.md +62 -3
- data/app/assets/javascripts/spree.js.coffee.erb +4 -1
- data/app/helpers/spree/base_helper.rb +7 -48
- data/app/models/spree/address.rb +5 -1
- data/app/models/spree/adjustment.rb +3 -3
- data/app/models/spree/app_configuration.rb +13 -0
- data/app/models/spree/calculator.rb +3 -2
- data/app/models/spree/calculator/default_tax.rb +6 -10
- data/app/models/spree/calculator/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/flat_rate.rb +0 -4
- data/app/models/spree/calculator/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/free_shipping.rb +0 -3
- data/app/models/spree/calculator/percent_on_line_item.rb +0 -4
- data/app/models/spree/calculator/percent_per_item.rb +0 -4
- data/app/models/spree/calculator/price_sack.rb +0 -4
- data/app/models/spree/calculator/returns/default_refund_amount.rb +0 -3
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/shipping/flat_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/per_item.rb +0 -4
- data/app/models/spree/calculator/shipping/price_sack.rb +0 -4
- data/app/models/spree/calculator/tiered_flat_rate.rb +0 -4
- data/app/models/spree/calculator/tiered_percent.rb +0 -4
- data/app/models/spree/credit_card.rb +27 -14
- data/app/models/spree/gateway.rb +4 -0
- data/app/models/spree/inventory_unit.rb +2 -0
- data/app/models/spree/line_item.rb +31 -26
- data/app/models/spree/option_type.rb +0 -3
- data/app/models/spree/order.rb +28 -31
- data/app/models/spree/order/checkout.rb +0 -2
- data/app/models/spree/order_contents.rb +0 -45
- data/app/models/spree/order_merger.rb +6 -6
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +91 -13
- data/app/models/spree/payment.rb +9 -2
- data/app/models/spree/payment/processing.rb +15 -9
- data/app/models/spree/payment_method.rb +48 -5
- data/app/models/spree/price.rb +7 -9
- data/app/models/spree/product.rb +1 -25
- data/app/models/spree/promotion.rb +22 -14
- data/app/models/spree/promotion/actions/create_adjustment.rb +12 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +15 -1
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +5 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +14 -0
- data/app/models/spree/promotion/rules/taxon.rb +7 -2
- data/app/models/spree/promotion/rules/user_role.rb +43 -0
- data/app/models/spree/promotion_action.rb +19 -2
- data/app/models/spree/promotion_handler/coupon.rb +1 -4
- data/app/models/spree/promotion_handler/free_shipping.rb +22 -17
- data/app/models/spree/promotion_rule_role.rb +6 -0
- data/app/models/spree/property.rb +0 -3
- data/app/models/spree/return_authorization.rb +2 -0
- data/app/models/spree/shipment.rb +5 -21
- data/app/models/spree/shipping_method.rb +23 -2
- data/app/models/spree/shipping_rate.rb +3 -0
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock_location.rb +3 -0
- data/app/models/spree/store.rb +7 -0
- data/app/models/spree/tax/item_adjuster.rb +27 -12
- data/app/models/spree/tax/order_adjuster.rb +2 -5
- data/app/models/spree/tax/tax_helpers.rb +4 -8
- data/app/models/spree/tax_rate.rb +1 -15
- data/app/models/spree/taxon.rb +0 -3
- data/app/models/spree/transfer_item.rb +1 -1
- data/app/models/spree/user_class_handle.rb +14 -9
- data/app/models/spree/variant/pricing_options.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/zone.rb +20 -13
- data/config/locales/en.yml +144 -62
- data/db/migrate/20120831092320_spree_one_two.rb +0 -7
- data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +0 -2
- data/db/migrate/20160924135758_remove_is_default_from_prices.rb +5 -0
- data/db/migrate/20161009141333_remove_currency_from_line_items.rb +5 -0
- data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +28 -0
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +20 -0
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +4 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +0 -2
- data/lib/spree/core.rb +0 -5
- data/lib/spree/core/controller_helpers/pricing.rb +2 -1
- data/lib/spree/core/engine.rb +14 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/localized_number.rb +3 -2
- data/lib/spree/permission_sets/configuration_display.rb +0 -1
- data/lib/spree/permission_sets/configuration_management.rb +0 -1
- data/lib/spree/permission_sets/product_display.rb +0 -1
- data/lib/spree/permission_sets/product_management.rb +0 -1
- data/lib/spree/permission_sets/user_management.rb +2 -4
- data/lib/spree/permitted_attributes.rb +3 -2
- data/lib/spree/testing_support/capybara_ext.rb +0 -12
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +0 -1
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -1
- data/lib/spree/testing_support/factories/user_factory.rb +2 -2
- data/solidus_core.gemspec +4 -3
- data/spec/helpers/base_helper_spec.rb +0 -40
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +16 -0
- data/spec/lib/spree/core/importer/order_spec.rb +27 -18
- data/spec/lib/spree/core/price_migrator_spec.rb +3 -1
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +16 -0
- data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -2
- data/spec/lib/tasks/exchanges_spec.rb +4 -2
- data/spec/lib/tasks/migrations/create_vat_prices_spec.rb +5 -3
- data/spec/models/spree/adjustment_spec.rb +136 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +13 -7
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/free_shipping_spec.rb +6 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +9 -4
- data/spec/models/spree/calculator/percent_per_item_spec.rb +10 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +3 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +4 -1
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +3 -0
- data/spec/models/spree/credit_card_spec.rb +27 -1
- data/spec/models/spree/line_item_spec.rb +58 -65
- data/spec/models/spree/order/checkout_spec.rb +2 -1
- data/spec/models/spree/order/payment_spec.rb +9 -10
- data/spec/models/spree/order/tax_spec.rb +22 -7
- data/spec/models/spree/order/updating_spec.rb +1 -3
- data/spec/models/spree/order_cancellations_spec.rb +6 -4
- data/spec/models/spree/order_contents_spec.rb +34 -50
- data/spec/models/spree/order_inventory_spec.rb +3 -5
- data/spec/models/spree/order_merger_spec.rb +20 -0
- data/spec/models/spree/order_spec.rb +28 -64
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +251 -0
- data/spec/models/spree/payment_method_spec.rb +178 -28
- data/spec/models/spree/payment_spec.rb +35 -19
- data/spec/models/spree/permission_sets/configuration_display.rb +0 -4
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/product_display_spec.rb +0 -4
- data/spec/models/spree/permission_sets/product_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/user_management_spec.rb +9 -2
- data/spec/models/spree/price_spec.rb +16 -1
- data/spec/models/spree/product_spec.rb +0 -75
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +20 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +39 -15
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +203 -22
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +22 -3
- data/spec/models/spree/promotion/rules/taxon_spec.rb +26 -0
- data/spec/models/spree/promotion/rules/user_role_spec.rb +86 -0
- data/spec/models/spree/promotion_action_spec.rb +38 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +36 -33
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +21 -22
- data/spec/models/spree/promotion_spec.rb +46 -6
- data/spec/models/spree/reimbursement_spec.rb +1 -1
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +68 -50
- data/spec/models/spree/shipping_method_spec.rb +41 -0
- data/spec/models/spree/shipping_rate_spec.rb +9 -3
- data/spec/models/spree/stock/estimator_spec.rb +4 -2
- data/spec/models/spree/store_credit_spec.rb +3 -3
- data/spec/models/spree/tax/item_adjuster_spec.rb +31 -21
- data/spec/models/spree/tax/order_adjuster_spec.rb +6 -10
- data/spec/models/spree/tax/taxation_integration_spec.rb +19 -0
- data/spec/models/spree/tax_rate_spec.rb +5 -26
- data/spec/models/spree/transfer_item_spec.rb +11 -0
- data/spec/models/spree/variant/pricing_options_spec.rb +7 -17
- data/spec/models/spree/variant_spec.rb +2 -4
- data/spec/models/spree/zone_spec.rb +60 -20
- data/spec/shared_examples/calculator_shared_examples.rb +8 -0
- metadata +19 -24
- data/app/models/spree/item_adjustments.rb +0 -89
- data/app/models/spree/option_type_prototype.rb +0 -6
- data/app/models/spree/property_prototype.rb +0 -6
- data/app/models/spree/prototype.rb +0 -14
- data/app/models/spree/prototype_taxon.rb +0 -6
- data/app/models/spree/tracker.rb +0 -8
- data/db/migrate/20150128032538_remove_environment_from_tracker.rb +0 -6
- data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
- data/lib/spree/core/delegate_belongs_to.rb +0 -94
- data/lib/spree/testing_support/factories/prototype_factory.rb +0 -8
- data/lib/spree/testing_support/factories/tracker_factory.rb +0 -6
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -24
- data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +0 -12
- data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +0 -12
- data/spec/models/spree/item_adjustments_spec.rb +0 -306
- data/spec/models/spree/tracker_spec.rb +0 -21
@@ -49,7 +49,7 @@ describe Spree::Reimbursement, type: :model do
|
|
49
49
|
let!(:adjustments) { [] } # placeholder to ensure it gets run prior the "before" at this level
|
50
50
|
|
51
51
|
let!(:tax_rate) { nil }
|
52
|
-
let!(:tax_zone) { create :zone, :with_country
|
52
|
+
let!(:tax_zone) { create :zone, :with_country }
|
53
53
|
let(:shipping_method) { create :shipping_method, zones: [tax_zone] }
|
54
54
|
let(:variant) { create :variant }
|
55
55
|
let(:order) { create(:order_with_line_items, state: 'payment', line_items_attributes: [{ variant: variant, price: line_items_price }], shipment_cost: 0, shipping_method: shipping_method) }
|
@@ -24,7 +24,7 @@ describe Spree::ReimbursementTaxCalculator, type: :model do
|
|
24
24
|
|
25
25
|
context 'with additional tax' do
|
26
26
|
let!(:tax_rate) { create(:tax_rate, name: "Sales Tax", amount: 0.10, included_in_price: false, zone: tax_zone) }
|
27
|
-
let(:tax_zone) { create(:zone, :with_country
|
27
|
+
let(:tax_zone) { create(:zone, :with_country) }
|
28
28
|
|
29
29
|
it 'sets additional_tax_total on the return items' do
|
30
30
|
subject
|
@@ -37,7 +37,7 @@ describe Spree::ReimbursementTaxCalculator, type: :model do
|
|
37
37
|
|
38
38
|
context 'with included tax' do
|
39
39
|
let!(:tax_rate) { create(:tax_rate, name: "VAT Tax", amount: 0.1, included_in_price: true, zone: tax_zone) }
|
40
|
-
let(:tax_zone) { create(:zone, :with_country
|
40
|
+
let(:tax_zone) { create(:zone, :with_country) }
|
41
41
|
|
42
42
|
it 'sets included_tax_total on the return items' do
|
43
43
|
subject
|
@@ -118,10 +118,23 @@ describe Spree::Shipment, type: :model do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
context "#item_cost" do
|
121
|
+
let(:shipment) { order.shipments[0] }
|
122
|
+
|
123
|
+
let(:order) do
|
124
|
+
create(
|
125
|
+
:order_ready_to_ship,
|
126
|
+
line_items_attributes: [{ price: 10, variant: variant }],
|
127
|
+
ship_address: ship_address,
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
let!(:ship_address) { create(:address) }
|
132
|
+
let!(:tax_zone) { create(:global_zone) } # will include the above address
|
133
|
+
let!(:tax_rate) { create(:tax_rate, amount: 0.1, zone: tax_zone, tax_category: tax_category) }
|
134
|
+
let(:tax_category) { create(:tax_category) }
|
135
|
+
let(:variant) { create(:variant, tax_category: tax_category) }
|
136
|
+
|
121
137
|
it 'should equal line items final amount with tax' do
|
122
|
-
shipment = create(:shipment, order: create(:order_with_totals))
|
123
|
-
create :tax_adjustment, adjustable: shipment.order.line_items.first, order: shipment.order
|
124
|
-
shipment.order.update!
|
125
138
|
expect(shipment.item_cost).to eql(11.0)
|
126
139
|
end
|
127
140
|
end
|
@@ -523,66 +536,59 @@ describe Spree::Shipment, type: :model do
|
|
523
536
|
|
524
537
|
context "updates cost when selected shipping rate is present" do
|
525
538
|
let(:shipment) { create(:shipment) }
|
526
|
-
|
527
|
-
before { allow(shipment).to receive_message_chain :selected_shipping_rate, cost: 5 }
|
539
|
+
before { shipment.selected_shipping_rate.update!(cost: 5) }
|
528
540
|
|
529
541
|
it "updates shipment totals" do
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
it "factors in additional adjustments to adjustment total" do
|
535
|
-
shipment.adjustments.create!(
|
536
|
-
order: order,
|
537
|
-
label: "Additional",
|
538
|
-
amount: 5,
|
539
|
-
included: false,
|
540
|
-
finalized: true
|
541
|
-
)
|
542
|
-
shipment.update_amounts
|
543
|
-
expect(shipment.reload.adjustment_total).to eq(5)
|
544
|
-
end
|
545
|
-
|
546
|
-
it "does not factor in included adjustments to adjustment total" do
|
547
|
-
shipment.adjustments.create!(
|
548
|
-
order: order,
|
549
|
-
label: "Included",
|
550
|
-
amount: 5,
|
551
|
-
included: true,
|
552
|
-
finalized: true
|
553
|
-
)
|
554
|
-
shipment.update_amounts
|
555
|
-
expect(shipment.reload.adjustment_total).to eq(0)
|
542
|
+
expect {
|
543
|
+
shipment.update_amounts
|
544
|
+
}.to change { shipment.cost }.to(5)
|
556
545
|
end
|
557
546
|
end
|
558
547
|
|
559
548
|
context "changes shipping rate via general update" do
|
560
|
-
let(:
|
549
|
+
let!(:ship_address) { create(:address) }
|
550
|
+
let!(:tax_zone) { create(:global_zone) } # will include the above address
|
551
|
+
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_category: tax_category) }
|
552
|
+
let(:tax_category) { create(:tax_category) }
|
553
|
+
|
561
554
|
let(:order) do
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
555
|
+
create(
|
556
|
+
:order_ready_to_ship,
|
557
|
+
ship_address: ship_address,
|
558
|
+
shipment_cost: 10,
|
559
|
+
shipping_method: ten_dollar_shipping_method,
|
560
|
+
line_items_count: 1,
|
561
|
+
line_items_price: 100,
|
568
562
|
)
|
569
563
|
end
|
570
564
|
|
571
|
-
let(:
|
565
|
+
let(:ten_dollar_shipping_method) { create(:shipping_method, tax_category: tax_category, zones: [tax_zone], cost: 10) }
|
566
|
+
let(:twenty_dollar_shipping_method) { create(:shipping_method, tax_category: tax_category, zones: [tax_zone], cost: 20) }
|
572
567
|
|
573
|
-
let(:
|
574
|
-
Spree::ShippingRate.create shipment_id: shipment.id, cost: 10
|
575
|
-
end
|
568
|
+
let(:shipment) { order.shipments[0] }
|
576
569
|
|
577
|
-
|
578
|
-
shipment
|
570
|
+
let(:twenty_dollar_shipping_rate) do
|
571
|
+
create(:shipping_rate, cost: 20, shipment: shipment, shipping_method: twenty_dollar_shipping_method)
|
579
572
|
end
|
580
573
|
|
581
574
|
it "updates everything around order shipment total and state" do
|
582
|
-
expect(shipment.
|
575
|
+
expect(shipment.state).to eq 'ready'
|
576
|
+
expect(shipment.cost).to eq 10
|
577
|
+
expect(shipment.additional_tax_total).to eq 1
|
578
|
+
|
579
|
+
expect(order.shipment_total).to eq 10
|
580
|
+
expect(order.total).to eq 121 # shipment: 10 + 1 (tax) + line item: 100 + 10 (tax)
|
581
|
+
expect(order.payment_state).to eq 'paid'
|
582
|
+
|
583
|
+
shipment.update_attributes_and_order selected_shipping_rate_id: twenty_dollar_shipping_rate.id
|
584
|
+
|
583
585
|
expect(shipment.state).to eq 'pending'
|
584
|
-
expect(shipment.
|
585
|
-
expect(shipment.
|
586
|
+
expect(shipment.cost).to eq 20
|
587
|
+
expect(shipment.additional_tax_total).to eq 2
|
588
|
+
|
589
|
+
expect(order.shipment_total).to eq 20
|
590
|
+
expect(order.total).to eq 132 # shipment: 20 + 2 (tax) + line item: 100 + 10 (tax)
|
591
|
+
expect(order.payment_state).to eq 'balance_due'
|
586
592
|
end
|
587
593
|
end
|
588
594
|
|
@@ -648,9 +654,21 @@ describe Spree::Shipment, type: :model do
|
|
648
654
|
|
649
655
|
# Regression test for https://github.com/spree/spree/issues/3349
|
650
656
|
context "#destroy" do
|
651
|
-
|
652
|
-
|
653
|
-
|
657
|
+
let(:shipping_rate) do
|
658
|
+
Spree::ShippingRate.create!(
|
659
|
+
shipping_method: shipping_method,
|
660
|
+
selected: true,
|
661
|
+
taxes: [Spree::ShippingRateTax.new(amount: 20)]
|
662
|
+
)
|
663
|
+
end
|
664
|
+
it "destroys linked shipping_rates and shipping_rate_taxes" do
|
665
|
+
shipping_rate = shipment.shipping_rates.first
|
666
|
+
shipping_rate_tax = shipping_rate.taxes.first
|
667
|
+
|
668
|
+
shipment.destroy
|
669
|
+
|
670
|
+
expect{shipping_rate.reload}.to raise_error(ActiveRecord::RecordNotFound)
|
671
|
+
expect{shipping_rate_tax.reload}.to raise_error(ActiveRecord::RecordNotFound)
|
654
672
|
end
|
655
673
|
end
|
656
674
|
|
@@ -210,4 +210,45 @@ describe Spree::ShippingMethod, type: :model do
|
|
210
210
|
it { is_expected.to_not include(shipping_method) }
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
describe "display_on=" do
|
215
|
+
subject do
|
216
|
+
Spree::Deprecation.silence do
|
217
|
+
described_class.new(display_on: display_on).available_to_users
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context "with 'back_end'" do
|
222
|
+
let(:display_on) { 'back_end' }
|
223
|
+
it { should be false }
|
224
|
+
end
|
225
|
+
|
226
|
+
context "with 'both'" do
|
227
|
+
let(:display_on) { 'both' }
|
228
|
+
it { should be true }
|
229
|
+
end
|
230
|
+
|
231
|
+
context "with 'front_end'" do
|
232
|
+
let(:display_on) { 'front_end' }
|
233
|
+
it { should be true }
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "display_on" do
|
238
|
+
subject do
|
239
|
+
Spree::Deprecation.silence do
|
240
|
+
described_class.new(available_to_users: available_to_users).display_on
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when available_to_users is true" do
|
245
|
+
let(:available_to_users) { true }
|
246
|
+
it { should == 'both' }
|
247
|
+
end
|
248
|
+
|
249
|
+
context "when available_to_users is false" do
|
250
|
+
let(:available_to_users) { false }
|
251
|
+
it { should == 'back_end' }
|
252
|
+
end
|
253
|
+
end
|
213
254
|
end
|
@@ -19,8 +19,9 @@ describe Spree::ShippingRate, type: :model do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context "#display_price" do
|
22
|
-
let!(:default_zone) { create :zone, countries: [address.country], default_tax:
|
22
|
+
let!(:default_zone) { create :zone, countries: [address.country], default_tax: default_tax }
|
23
23
|
let!(:other_zone) { create :zone, countries: [foreign_address.country] }
|
24
|
+
let(:default_tax) { false }
|
24
25
|
|
25
26
|
before do
|
26
27
|
allow(order).to receive(:tax_address).and_return(order_address)
|
@@ -57,6 +58,7 @@ describe Spree::ShippingRate, type: :model do
|
|
57
58
|
end
|
58
59
|
|
59
60
|
context 'with one tax rate that will be refunded' do
|
61
|
+
let(:default_tax) { true }
|
60
62
|
let!(:tax_rate) do
|
61
63
|
create :tax_rate,
|
62
64
|
included_in_price: true,
|
@@ -68,7 +70,9 @@ describe Spree::ShippingRate, type: :model do
|
|
68
70
|
let(:order_address) { foreign_address }
|
69
71
|
|
70
72
|
before do
|
71
|
-
Spree::
|
73
|
+
Spree::Deprecation.silence do
|
74
|
+
Spree::Tax::ShippingRateTaxer.new.tax(shipping_rate)
|
75
|
+
end
|
72
76
|
end
|
73
77
|
|
74
78
|
it "shows correct tax amount" do
|
@@ -141,7 +145,9 @@ describe Spree::ShippingRate, type: :model do
|
|
141
145
|
end
|
142
146
|
|
143
147
|
it "shows correct tax amount" do
|
144
|
-
expect(shipping_rate.display_price.to_s).to
|
148
|
+
expect(shipping_rate.display_price.to_s).to match(/\$10.00 \(.*, .*\)/)
|
149
|
+
expect(shipping_rate.display_price.to_s).to include("+ $1.00 Sales Tax")
|
150
|
+
expect(shipping_rate.display_price.to_s).to include("+ $0.50 Other Sales Tax")
|
145
151
|
end
|
146
152
|
|
147
153
|
context "when cost is zero" do
|
@@ -126,7 +126,7 @@ module Spree
|
|
126
126
|
|
127
127
|
context "involves backend only shipping methods" do
|
128
128
|
before{ Spree::ShippingMethod.destroy_all }
|
129
|
-
let!(:backend_method) { create(:shipping_method,
|
129
|
+
let!(:backend_method) { create(:shipping_method, available_to_users: false, cost: 0.00) }
|
130
130
|
let!(:generic_method) { create(:shipping_method, cost: 5.00) }
|
131
131
|
|
132
132
|
it "does not return backend rates at all" do
|
@@ -140,7 +140,9 @@ module Spree
|
|
140
140
|
end
|
141
141
|
|
142
142
|
context "includes tax adjustments if applicable" do
|
143
|
-
let
|
143
|
+
let(:zone) { create(:zone, countries: [order.tax_address.country])}
|
144
|
+
|
145
|
+
let!(:tax_rate) { create(:tax_rate, zone: zone) }
|
144
146
|
|
145
147
|
before do
|
146
148
|
shipping_method.update!(tax_category: tax_rate.tax_category)
|
@@ -38,7 +38,7 @@ describe Spree::StoreCredit do
|
|
38
38
|
allow(store_credit.category).to receive(:non_expiring?).and_return(false)
|
39
39
|
end
|
40
40
|
|
41
|
-
it "sets the credit type to
|
41
|
+
it "sets the credit type to expiring" do
|
42
42
|
subject
|
43
43
|
expect(store_credit.credit_type.name).to eq "Expiring"
|
44
44
|
end
|
@@ -414,7 +414,7 @@ describe Spree::StoreCredit do
|
|
414
414
|
expect(subject).to be true
|
415
415
|
end
|
416
416
|
|
417
|
-
it "returns the
|
417
|
+
it "returns the authorized amount to the store credit" do
|
418
418
|
expect { subject }.to change{ store_credit.amount_authorized.to_f }.by(-authorized_amount)
|
419
419
|
end
|
420
420
|
|
@@ -519,7 +519,7 @@ describe Spree::StoreCredit do
|
|
519
519
|
@new_store_credit = Spree::StoreCredit.last
|
520
520
|
end
|
521
521
|
|
522
|
-
it "does not set the amount used on
|
522
|
+
it "does not set the amount used on the originating store credit" do
|
523
523
|
expect(store_credit.reload.amount_used).to eq amount_used
|
524
524
|
end
|
525
525
|
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe Spree::Tax::ItemAdjuster do
|
4
4
|
subject(:adjuster) { described_class.new(item) }
|
5
5
|
let(:order) { create(:order) }
|
6
|
-
let(:item) {
|
6
|
+
let(:item) { create(:line_item, order: order) }
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
def tax_adjustments
|
9
|
+
item.adjustments.tax.to_a
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'initialization' do
|
@@ -19,39 +19,48 @@ RSpec.describe Spree::Tax::ItemAdjuster do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
shared_examples_for 'untaxed item' do
|
23
|
+
it 'creates no adjustments' do
|
24
|
+
adjuster.adjust!
|
25
|
+
expect(tax_adjustments).to eq([])
|
25
26
|
end
|
26
27
|
|
27
|
-
context '
|
28
|
-
let(:
|
28
|
+
context 'with an existing tax adjustment' do
|
29
|
+
let!(:existing_adjustment) { create(:tax_adjustment, adjustable: item) }
|
29
30
|
|
30
|
-
|
31
|
-
allow(order).to receive(:tax_zone).and_return(nil)
|
31
|
+
it 'removes the existing adjustment' do
|
32
32
|
adjuster.adjust!
|
33
|
+
aggregate_failures do
|
34
|
+
expect(tax_adjustments).to eq([])
|
35
|
+
expect(Spree::Adjustment).to_not be_exists(existing_adjustment.id)
|
36
|
+
end
|
33
37
|
end
|
38
|
+
end
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
describe '#adjust!' do
|
42
|
+
before do
|
43
|
+
expect(order).to receive(:tax_address).at_least(:once).and_return(address)
|
38
44
|
end
|
39
45
|
|
40
|
-
context 'when the order has
|
46
|
+
context 'when the order has no tax zone' do
|
47
|
+
let(:address) { Spree::Tax::TaxLocation.new }
|
48
|
+
|
49
|
+
it_behaves_like 'untaxed item'
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when the order has a taxable address' do
|
41
53
|
let(:item) { build_stubbed :line_item, order: order }
|
42
|
-
let(:
|
54
|
+
let(:address) { order.tax_address }
|
43
55
|
|
44
56
|
before do
|
45
|
-
expect(Spree::TaxRate).to receive(:
|
46
|
-
expect(Spree::TaxRate).to receive(:for_zone).with(Spree::Zone.default_tax).and_return([])
|
57
|
+
expect(Spree::TaxRate).to receive(:for_address).with(order.tax_address).and_return(rates_for_order_zone)
|
47
58
|
end
|
48
59
|
|
49
60
|
context 'when there are no matching rates' do
|
50
61
|
let(:rates_for_order_zone) { [] }
|
51
62
|
|
52
|
-
|
53
|
-
expect(adjuster.adjust!).to eq([])
|
54
|
-
end
|
63
|
+
it_behaves_like 'untaxed item'
|
55
64
|
end
|
56
65
|
|
57
66
|
context 'when there are matching rates for the zone' do
|
@@ -64,7 +73,8 @@ RSpec.describe Spree::Tax::ItemAdjuster do
|
|
64
73
|
before { allow(item).to receive(:tax_category).and_return(item_tax_category) }
|
65
74
|
|
66
75
|
it 'creates an adjustment for every matching rate' do
|
67
|
-
|
76
|
+
adjuster.adjust!
|
77
|
+
expect(tax_adjustments.length).to eq(1)
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|
@@ -12,32 +12,28 @@ RSpec.describe Spree::Tax::OrderAdjuster do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#adjust!' do
|
15
|
-
let(:zone) { build_stubbed(:zone) }
|
16
15
|
let(:line_items) { build_stubbed_list(:line_item, 2) }
|
17
16
|
let(:order) { build_stubbed(:order, line_items: line_items) }
|
18
17
|
let(:rates_for_order_zone) { [] }
|
18
|
+
let(:rates_for_default_zone) { [] }
|
19
19
|
let(:item_adjuster) { Spree::Tax::ItemAdjuster.new(line_items.first) }
|
20
20
|
|
21
21
|
before do
|
22
|
-
expect(
|
23
|
-
expect(Spree::TaxRate).to receive(:for_zone).with(zone).and_return(rates_for_order_zone)
|
24
|
-
expect(Spree::TaxRate).to receive(:for_zone).with(Spree::Zone.default_tax).and_return([])
|
22
|
+
expect(Spree::TaxRate).to receive(:for_address).with(order.tax_address).and_return(rates_for_order_zone)
|
25
23
|
end
|
26
24
|
|
27
25
|
it 'calls the item adjuster with all line items' do
|
28
26
|
expect(Spree::Tax::ItemAdjuster).to receive(:new).
|
29
27
|
with(
|
30
28
|
line_items.first,
|
31
|
-
|
32
|
-
rates_for_default_zone:
|
33
|
-
order_tax_zone: zone,
|
29
|
+
rates_for_order: rates_for_order_zone,
|
30
|
+
rates_for_default_zone: rates_for_default_zone
|
34
31
|
).and_return(item_adjuster)
|
35
32
|
expect(Spree::Tax::ItemAdjuster).to receive(:new).
|
36
33
|
with(
|
37
34
|
line_items.second,
|
38
|
-
|
39
|
-
rates_for_default_zone:
|
40
|
-
order_tax_zone: zone,
|
35
|
+
rates_for_order: rates_for_order_zone,
|
36
|
+
rates_for_default_zone: rates_for_default_zone
|
41
37
|
).and_return(item_adjuster)
|
42
38
|
|
43
39
|
expect(item_adjuster).to receive(:adjust!).twice
|
@@ -624,6 +624,25 @@ RSpec.describe "Taxation system integration tests" do
|
|
624
624
|
federal_books_tax.destroy!
|
625
625
|
expect(line_item.adjustments.count).to eq(2)
|
626
626
|
end
|
627
|
+
|
628
|
+
context 'when tax address is later cleared' do
|
629
|
+
before do
|
630
|
+
order.ship_address = nil
|
631
|
+
order.update!
|
632
|
+
end
|
633
|
+
|
634
|
+
it 'removes all tax adjustments' do
|
635
|
+
aggregate_failures do
|
636
|
+
expect(line_item.adjustments.tax.count).to eq(0)
|
637
|
+
expect(line_item).to have_attributes(
|
638
|
+
price: 20,
|
639
|
+
total: 20,
|
640
|
+
included_tax_total: 0,
|
641
|
+
additional_tax_total: 0
|
642
|
+
)
|
643
|
+
end
|
644
|
+
end
|
645
|
+
end
|
627
646
|
end
|
628
647
|
|
629
648
|
context 'an order with a book and a shipment' do
|