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
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Spree::Order, type: :model do
|
|
4
|
-
let(:store) {
|
|
5
|
-
let(:user) {
|
|
6
|
-
let(:order) {
|
|
4
|
+
let(:store) { create(:store) }
|
|
5
|
+
let(:user) { create(:user, email: "spree@example.com") }
|
|
6
|
+
let(:order) { create(:order, user: user, store: store) }
|
|
7
|
+
let(:promotion) do
|
|
8
|
+
FactoryGirl.create(
|
|
9
|
+
:promotion,
|
|
10
|
+
:with_order_adjustment,
|
|
11
|
+
code: "discount"
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
let(:code) { promotion.codes.first }
|
|
7
15
|
|
|
8
16
|
before do
|
|
9
17
|
allow(Spree::LegacyUser).to receive_messages(current: mock_model(Spree::LegacyUser, id: 123))
|
|
@@ -171,12 +179,14 @@ describe Spree::Order, type: :model do
|
|
|
171
179
|
create(:line_item, order: order)
|
|
172
180
|
create(:shipment, order: order)
|
|
173
181
|
create(:adjustment, adjustable: order, order: order)
|
|
182
|
+
promotion.activate(order: order, promotion_code: code)
|
|
174
183
|
order.update!
|
|
175
184
|
|
|
176
185
|
# Make sure we are asserting changes
|
|
177
186
|
expect(order.line_items).not_to be_empty
|
|
178
187
|
expect(order.shipments).not_to be_empty
|
|
179
188
|
expect(order.adjustments).not_to be_empty
|
|
189
|
+
expect(order.promotions).not_to be_empty
|
|
180
190
|
expect(order.item_total).not_to eq 0
|
|
181
191
|
expect(order.item_count).not_to eq 0
|
|
182
192
|
expect(order.shipment_total).not_to eq 0
|
|
@@ -188,6 +198,7 @@ describe Spree::Order, type: :model do
|
|
|
188
198
|
expect(order.line_items).to be_empty
|
|
189
199
|
expect(order.shipments).to be_empty
|
|
190
200
|
expect(order.adjustments).to be_empty
|
|
201
|
+
expect(order.promotions).to be_empty
|
|
191
202
|
expect(order.item_total).to eq 0
|
|
192
203
|
expect(order.item_count).to eq 0
|
|
193
204
|
expect(order.shipment_total).to eq 0
|
|
@@ -195,6 +206,21 @@ describe Spree::Order, type: :model do
|
|
|
195
206
|
end
|
|
196
207
|
end
|
|
197
208
|
|
|
209
|
+
context '#outstanding_balance' do
|
|
210
|
+
let(:order) { create(:order_ready_to_ship, line_items_count: 3) }
|
|
211
|
+
let(:payment) { order.payments.first }
|
|
212
|
+
|
|
213
|
+
it "should handle refunds properly" do
|
|
214
|
+
order.cancellations.short_ship([order.inventory_units.first])
|
|
215
|
+
expect(order.outstanding_balance).to be_negative
|
|
216
|
+
expect(order.payment_state).to eq('credit_owed')
|
|
217
|
+
create(:refund, amount: order.outstanding_balance.abs, payment: payment, transaction_id: nil)
|
|
218
|
+
order.reload
|
|
219
|
+
expect(order.outstanding_balance).to eq(0)
|
|
220
|
+
expect(order.payment_state).to eq('paid')
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
198
224
|
context "#display_outstanding_balance" do
|
|
199
225
|
it "returns the value as a spree money" do
|
|
200
226
|
allow(order).to receive(:outstanding_balance) { 10.55 }
|
|
@@ -491,7 +517,9 @@ describe Spree::Order, type: :model do
|
|
|
491
517
|
order.update_column(:payment_state, 'balance_due')
|
|
492
518
|
order.payment_state = 'paid'
|
|
493
519
|
expect(order.state_changes).to be_empty
|
|
494
|
-
|
|
520
|
+
Spree::Deprecation.silence do
|
|
521
|
+
order.state_changed('payment')
|
|
522
|
+
end
|
|
495
523
|
state_change = order.state_changes.find_by(name: 'payment')
|
|
496
524
|
expect(state_change.previous_state).to eq('balance_due')
|
|
497
525
|
expect(state_change.next_state).to eq('paid')
|
|
@@ -500,7 +528,9 @@ describe Spree::Order, type: :model do
|
|
|
500
528
|
it "does not do anything if state does not change" do
|
|
501
529
|
order.update_column(:payment_state, 'balance_due')
|
|
502
530
|
expect(order.state_changes).to be_empty
|
|
503
|
-
|
|
531
|
+
Spree::Deprecation.silence do
|
|
532
|
+
order.state_changed('payment')
|
|
533
|
+
end
|
|
504
534
|
expect(order.state_changes).to be_empty
|
|
505
535
|
end
|
|
506
536
|
end
|
|
@@ -508,7 +538,7 @@ describe Spree::Order, type: :model do
|
|
|
508
538
|
# Regression test for https://github.com/spree/spree/issues/4199
|
|
509
539
|
context "#available_payment_methods" do
|
|
510
540
|
it "includes frontend payment methods" do
|
|
511
|
-
payment_method = Spree::PaymentMethod.create!({
|
|
541
|
+
payment_method = Spree::PaymentMethod::Check.create!({
|
|
512
542
|
name: "Fake",
|
|
513
543
|
active: true,
|
|
514
544
|
available_to_users: true,
|
|
@@ -518,7 +548,7 @@ describe Spree::Order, type: :model do
|
|
|
518
548
|
end
|
|
519
549
|
|
|
520
550
|
it "includes 'both' payment methods" do
|
|
521
|
-
payment_method = Spree::PaymentMethod.create!({
|
|
551
|
+
payment_method = Spree::PaymentMethod::Check.create!({
|
|
522
552
|
name: "Fake",
|
|
523
553
|
active: true,
|
|
524
554
|
available_to_users: true,
|
|
@@ -528,7 +558,7 @@ describe Spree::Order, type: :model do
|
|
|
528
558
|
end
|
|
529
559
|
|
|
530
560
|
it "does not include a payment method twice" do
|
|
531
|
-
payment_method = Spree::PaymentMethod.create!({
|
|
561
|
+
payment_method = Spree::PaymentMethod::Check.create!({
|
|
532
562
|
name: "Fake",
|
|
533
563
|
active: true,
|
|
534
564
|
available_to_users: true,
|
|
@@ -539,7 +569,7 @@ describe Spree::Order, type: :model do
|
|
|
539
569
|
end
|
|
540
570
|
|
|
541
571
|
it "does not include inactive payment methods" do
|
|
542
|
-
Spree::PaymentMethod.create!({
|
|
572
|
+
Spree::PaymentMethod::Check.create!({
|
|
543
573
|
name: "Fake",
|
|
544
574
|
active: false,
|
|
545
575
|
available_to_users: true,
|
|
@@ -675,39 +705,52 @@ describe Spree::Order, type: :model do
|
|
|
675
705
|
end
|
|
676
706
|
end
|
|
677
707
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
708
|
+
describe "#generate_order_number" do
|
|
709
|
+
let(:order) { build(:order) }
|
|
710
|
+
|
|
711
|
+
context "with default app configuration" do
|
|
712
|
+
it 'calls the default order number generator' do
|
|
713
|
+
expect_any_instance_of(Spree::Order::NumberGenerator).to receive(:generate)
|
|
714
|
+
order.generate_order_number
|
|
715
|
+
end
|
|
716
|
+
end
|
|
717
|
+
|
|
718
|
+
context "with order number generator configured" do
|
|
719
|
+
class TruthNumberGenerator
|
|
720
|
+
def initialize(options = {}); end
|
|
682
721
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
722
|
+
def generate
|
|
723
|
+
'42'
|
|
724
|
+
end
|
|
686
725
|
end
|
|
687
726
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
727
|
+
before do
|
|
728
|
+
expect(Spree::Config).to receive(:order_number_generator) do
|
|
729
|
+
TruthNumberGenerator.new
|
|
730
|
+
end
|
|
691
731
|
end
|
|
692
|
-
it { is_expected.to match /^#{Spree::Order::ORDER_NUMBER_PREFIX}/ }
|
|
693
|
-
end
|
|
694
732
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
expect(order.generate_order_number(length: 5).length).to eq option_length
|
|
733
|
+
it 'calls the configured order number generator' do
|
|
734
|
+
order.generate_order_number
|
|
735
|
+
expect(order.number).to eq '42'
|
|
699
736
|
end
|
|
700
737
|
end
|
|
701
738
|
|
|
702
|
-
context "
|
|
703
|
-
|
|
704
|
-
|
|
739
|
+
context "with number already present" do
|
|
740
|
+
before do
|
|
741
|
+
order.number = '123'
|
|
742
|
+
end
|
|
743
|
+
|
|
744
|
+
it 'does not generate new number' do
|
|
745
|
+
order.generate_order_number
|
|
746
|
+
expect(order.number).to eq '123'
|
|
705
747
|
end
|
|
706
748
|
end
|
|
707
749
|
|
|
708
|
-
context "
|
|
709
|
-
it
|
|
710
|
-
expect(
|
|
750
|
+
context "passing options" do
|
|
751
|
+
it 'is deprecated' do
|
|
752
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
753
|
+
order.generate_order_number(length: 2)
|
|
711
754
|
end
|
|
712
755
|
end
|
|
713
756
|
end
|
|
@@ -768,6 +811,88 @@ describe Spree::Order, type: :model do
|
|
|
768
811
|
end
|
|
769
812
|
end
|
|
770
813
|
|
|
814
|
+
context "#assign_default_user_addresses" do
|
|
815
|
+
let(:order) { Spree::Order.new }
|
|
816
|
+
|
|
817
|
+
subject { order.assign_default_user_addresses }
|
|
818
|
+
|
|
819
|
+
context "when no user is associated to the order" do
|
|
820
|
+
it "does not associate any bill address" do
|
|
821
|
+
expect { subject }.not_to change { order.bill_address }.from(nil)
|
|
822
|
+
end
|
|
823
|
+
|
|
824
|
+
it "does not associate any ship address" do
|
|
825
|
+
expect { subject }.not_to change { order.ship_address }.from(nil)
|
|
826
|
+
end
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
context "when user is associated to the order" do
|
|
830
|
+
let(:user) { build_stubbed(:user) }
|
|
831
|
+
let(:bill_address) { nil }
|
|
832
|
+
let(:ship_address) { nil }
|
|
833
|
+
|
|
834
|
+
before do
|
|
835
|
+
order.associate_user!(user)
|
|
836
|
+
user.bill_address = bill_address
|
|
837
|
+
user.ship_address = ship_address
|
|
838
|
+
end
|
|
839
|
+
|
|
840
|
+
context "but has no bill address associated" do
|
|
841
|
+
it "does not associate any bill address" do
|
|
842
|
+
expect { subject }.not_to change { order.bill_address }.from(nil)
|
|
843
|
+
end
|
|
844
|
+
end
|
|
845
|
+
|
|
846
|
+
context "and has an invalid bill address associated " do
|
|
847
|
+
let(:bill_address) { build(:address, firstname: nil) } # invalid address
|
|
848
|
+
|
|
849
|
+
it "does not associate any bill address" do
|
|
850
|
+
expect { subject }.not_to change { order.bill_address }.from(nil)
|
|
851
|
+
end
|
|
852
|
+
end
|
|
853
|
+
|
|
854
|
+
context "and has a valid address associated " do
|
|
855
|
+
let(:bill_address) { build(:address) }
|
|
856
|
+
|
|
857
|
+
it "does associate user bill address" do
|
|
858
|
+
expect { subject }.to change { order.bill_address }.from(nil).to(bill_address)
|
|
859
|
+
end
|
|
860
|
+
end
|
|
861
|
+
|
|
862
|
+
context "but has no ship address associated" do
|
|
863
|
+
it "does not associate any ship address" do
|
|
864
|
+
expect { subject }.not_to change { order.ship_address }.from(nil)
|
|
865
|
+
end
|
|
866
|
+
end
|
|
867
|
+
|
|
868
|
+
context "and has an invalid ship address associated " do
|
|
869
|
+
let(:ship_address) { build(:address, firstname: nil) } # invalid address
|
|
870
|
+
|
|
871
|
+
it "does not associate any ship address" do
|
|
872
|
+
expect { subject }.not_to change { order.ship_address }.from(nil)
|
|
873
|
+
end
|
|
874
|
+
end
|
|
875
|
+
|
|
876
|
+
context "and has a valid ship address associated" do
|
|
877
|
+
let(:ship_address) { build(:address) }
|
|
878
|
+
|
|
879
|
+
it "does associate user ship address" do
|
|
880
|
+
expect { subject }.to change { order.ship_address }.from(nil).to(ship_address)
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
context 'when checkout step does not include delivery' do
|
|
884
|
+
before do
|
|
885
|
+
expect(order).to receive(:checkout_steps) { %w[some step] }
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
it "does not associate any ship address" do
|
|
889
|
+
expect { subject }.not_to change { order.ship_address }.from(nil)
|
|
890
|
+
end
|
|
891
|
+
end
|
|
892
|
+
end
|
|
893
|
+
end
|
|
894
|
+
end
|
|
895
|
+
|
|
771
896
|
context "#can_ship?" do
|
|
772
897
|
let(:order) { Spree::Order.create }
|
|
773
898
|
|
|
@@ -1409,56 +1534,4 @@ describe Spree::Order, type: :model do
|
|
|
1409
1534
|
end
|
|
1410
1535
|
end
|
|
1411
1536
|
end
|
|
1412
|
-
|
|
1413
|
-
describe "#validate_payments_attributes" do
|
|
1414
|
-
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
|
1415
|
-
subject do
|
|
1416
|
-
order.validate_payments_attributes(attributes)
|
|
1417
|
-
end
|
|
1418
|
-
|
|
1419
|
-
context "with empty array" do
|
|
1420
|
-
let(:attributes) { [] }
|
|
1421
|
-
it "doesn't error" do
|
|
1422
|
-
subject
|
|
1423
|
-
end
|
|
1424
|
-
end
|
|
1425
|
-
|
|
1426
|
-
context "with no payment method specified" do
|
|
1427
|
-
let(:attributes) { [ActionController::Parameters.new({})] }
|
|
1428
|
-
it "doesn't error" do
|
|
1429
|
-
subject
|
|
1430
|
-
end
|
|
1431
|
-
end
|
|
1432
|
-
|
|
1433
|
-
context "with valid payment method" do
|
|
1434
|
-
let(:payment_method) { create(:check_payment_method) }
|
|
1435
|
-
it "doesn't error" do
|
|
1436
|
-
subject
|
|
1437
|
-
end
|
|
1438
|
-
end
|
|
1439
|
-
|
|
1440
|
-
context "with inactive payment method" do
|
|
1441
|
-
let(:payment_method) { create(:check_payment_method, active: false) }
|
|
1442
|
-
|
|
1443
|
-
it "raises RecordNotFound" do
|
|
1444
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1445
|
-
end
|
|
1446
|
-
end
|
|
1447
|
-
|
|
1448
|
-
context "with unavailable payment method" do
|
|
1449
|
-
let(:payment_method) { create(:check_payment_method, available_to_users: false) }
|
|
1450
|
-
|
|
1451
|
-
it "raises RecordNotFound" do
|
|
1452
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1453
|
-
end
|
|
1454
|
-
end
|
|
1455
|
-
|
|
1456
|
-
context "with soft-deleted payment method" do
|
|
1457
|
-
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
|
1458
|
-
|
|
1459
|
-
it "raises RecordNotFound" do
|
|
1460
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1461
|
-
end
|
|
1462
|
-
end
|
|
1463
|
-
end
|
|
1464
1537
|
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Spree::OrderTaxation do
|
|
4
|
+
let(:shipping_address) { FactoryGirl.create(:address, state: new_york) }
|
|
5
|
+
let(:order) { FactoryGirl.create(:order, ship_address: shipping_address, state: "delivery") }
|
|
6
|
+
|
|
7
|
+
let(:new_york) { FactoryGirl.create(:state, state_code: "NY") }
|
|
8
|
+
let(:new_york_zone) { FactoryGirl.create(:zone, states: [new_york]) }
|
|
9
|
+
|
|
10
|
+
let(:books_category) { FactoryGirl.create(:tax_category, name: "Books") }
|
|
11
|
+
let(:book_tax_rate) do
|
|
12
|
+
FactoryGirl.create(
|
|
13
|
+
:tax_rate,
|
|
14
|
+
name: "New York Sales Tax",
|
|
15
|
+
tax_categories: [books_category],
|
|
16
|
+
zone: new_york_zone,
|
|
17
|
+
included_in_price: false,
|
|
18
|
+
amount: 0.05
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:book) do
|
|
23
|
+
FactoryGirl.create(
|
|
24
|
+
:product,
|
|
25
|
+
price: 20,
|
|
26
|
+
name: "Book",
|
|
27
|
+
tax_category: books_category,
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
let(:taxation) { described_class.new(order) }
|
|
32
|
+
|
|
33
|
+
describe "#apply" do
|
|
34
|
+
let(:line_item) { order.contents.add(book.master) }
|
|
35
|
+
|
|
36
|
+
let(:line_item_tax) do
|
|
37
|
+
Spree::Tax::ItemTax.new(
|
|
38
|
+
item_id: line_item.id,
|
|
39
|
+
label: "Tax!",
|
|
40
|
+
tax_rate: book_tax_rate,
|
|
41
|
+
amount: 5,
|
|
42
|
+
included_in_price: false
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
let(:taxes) do
|
|
47
|
+
Spree::Tax::OrderTax.new(
|
|
48
|
+
order_id: order.id,
|
|
49
|
+
line_item_taxes: [line_item_tax],
|
|
50
|
+
shipment_taxes: []
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
before { taxation.apply(taxes) }
|
|
55
|
+
|
|
56
|
+
it "creates a new tax adjustment", aggregate_failures: true do
|
|
57
|
+
expect(line_item.adjustments.count).to eq 1
|
|
58
|
+
|
|
59
|
+
tax_adjustment = line_item.adjustments.first
|
|
60
|
+
expect(tax_adjustment.label).to eq "Tax!"
|
|
61
|
+
expect(tax_adjustment.source).to eq book_tax_rate
|
|
62
|
+
expect(tax_adjustment.amount).to eq 5
|
|
63
|
+
expect(tax_adjustment.included).to be false
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "when new taxes are applied" do
|
|
67
|
+
let(:new_line_item_tax) do
|
|
68
|
+
Spree::Tax::ItemTax.new(
|
|
69
|
+
item_id: line_item.id,
|
|
70
|
+
label: "Tax!",
|
|
71
|
+
tax_rate: book_tax_rate,
|
|
72
|
+
amount: 10,
|
|
73
|
+
included_in_price: false
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
let(:new_taxes) do
|
|
78
|
+
Spree::Tax::OrderTax.new(
|
|
79
|
+
order_id: order.id,
|
|
80
|
+
line_item_taxes: [new_line_item_tax],
|
|
81
|
+
shipment_taxes: []
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "updates the existing tax amount", aggregate_failures: true do
|
|
86
|
+
expect {
|
|
87
|
+
taxation.apply(new_taxes)
|
|
88
|
+
}.to change {
|
|
89
|
+
line_item.adjustments.first.amount
|
|
90
|
+
}.from(5).to(10)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context "and the adjustment is finalized" do
|
|
94
|
+
before do
|
|
95
|
+
line_item.adjustments.first.finalize!
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "does not update the tax amount", aggregate_failures: true do
|
|
99
|
+
expect {
|
|
100
|
+
taxation.apply(new_taxes)
|
|
101
|
+
}.to change {
|
|
102
|
+
line_item.adjustments.first.amount
|
|
103
|
+
}.from(5).to(10)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "when taxes are removed" do
|
|
109
|
+
let(:new_taxes) do
|
|
110
|
+
Spree::Tax::OrderTax.new(
|
|
111
|
+
order_id: order.id,
|
|
112
|
+
line_item_taxes: [],
|
|
113
|
+
shipment_taxes: []
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "removes the tax adjustment" do
|
|
118
|
+
expect {
|
|
119
|
+
taxation.apply(new_taxes)
|
|
120
|
+
}.to change {
|
|
121
|
+
line_item.adjustments.count
|
|
122
|
+
}.from(1).to(0)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
|
3
3
|
module Spree
|
|
4
4
|
RSpec.describe OrderUpdateAttributes do
|
|
5
5
|
let(:order) { create(:order) }
|
|
6
|
-
let(:payment_method) { create(:payment_method) }
|
|
7
6
|
let(:request_env) { nil }
|
|
8
7
|
let(:update) { described_class.new(order, attributes, request_env: request_env) }
|
|
9
8
|
|
|
@@ -26,10 +25,7 @@ module Spree
|
|
|
26
25
|
let(:attributes) do
|
|
27
26
|
{
|
|
28
27
|
payments_attributes: [
|
|
29
|
-
{
|
|
30
|
-
payment_method_id: payment_method.id,
|
|
31
|
-
source_attributes: attributes_for(:credit_card)
|
|
32
|
-
}
|
|
28
|
+
{ source_attributes: attributes_for(:credit_card) }
|
|
33
29
|
]
|
|
34
30
|
}
|
|
35
31
|
end
|
|
@@ -34,6 +34,17 @@ module Spree
|
|
|
34
34
|
}.to change { order.shipment_total }.to 10
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
context 'with a source-less line item adjustment' do
|
|
38
|
+
let(:line_item) { create(:line_item, order: order, price: 10) }
|
|
39
|
+
before do
|
|
40
|
+
create(:adjustment, source: nil, adjustable: line_item, order: order, amount: -5)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "updates the line item total" do
|
|
44
|
+
expect { updater.update }.to change { line_item.reload.adjustment_total }.from(0).to(-5)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
37
48
|
context 'with order promotion followed by line item addition' do
|
|
38
49
|
let(:promotion) { Spree::Promotion.create!(name: "10% off") }
|
|
39
50
|
let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
|
|
@@ -273,7 +284,7 @@ module Spree
|
|
|
273
284
|
describe 'tax recalculation' do
|
|
274
285
|
let!(:ship_address) { create(:address) }
|
|
275
286
|
let!(:tax_zone) { create(:global_zone) } # will include the above address
|
|
276
|
-
let!(:tax_rate) { create(:tax_rate, zone: tax_zone,
|
|
287
|
+
let!(:tax_rate) { create(:tax_rate, zone: tax_zone, tax_categories: [tax_category]) }
|
|
277
288
|
|
|
278
289
|
let(:order) do
|
|
279
290
|
create(
|
|
@@ -301,18 +312,20 @@ module Spree
|
|
|
301
312
|
end
|
|
302
313
|
end
|
|
303
314
|
|
|
304
|
-
context 'with a custom
|
|
305
|
-
let(:
|
|
306
|
-
let(:
|
|
315
|
+
context 'with a custom tax_calculator_class' do
|
|
316
|
+
let(:custom_calculator_class) { double }
|
|
317
|
+
let(:custom_calculator_instance) { double }
|
|
307
318
|
|
|
308
319
|
before do
|
|
309
320
|
order # generate this first so we can expect it
|
|
310
|
-
Spree::Config.
|
|
321
|
+
Spree::Config.tax_calculator_class = custom_calculator_class
|
|
311
322
|
end
|
|
312
323
|
|
|
313
324
|
it 'uses the configured class' do
|
|
314
|
-
expect(
|
|
315
|
-
expect(
|
|
325
|
+
expect(custom_calculator_class).to receive(:new).with(order).at_least(:once).and_return(custom_calculator_instance)
|
|
326
|
+
expect(custom_calculator_instance).to receive(:calculate).at_least(:once).and_return(
|
|
327
|
+
Spree::Tax::OrderTax.new(order_id: order.id, line_item_taxes: [], shipment_taxes: [])
|
|
328
|
+
)
|
|
316
329
|
|
|
317
330
|
order.update!
|
|
318
331
|
end
|
|
@@ -452,20 +465,6 @@ module Spree
|
|
|
452
465
|
end
|
|
453
466
|
end
|
|
454
467
|
|
|
455
|
-
it "state change" do
|
|
456
|
-
order.shipment_state = 'shipped'
|
|
457
|
-
state_changes = double
|
|
458
|
-
allow(order).to receive_messages state_changes: state_changes
|
|
459
|
-
expect(state_changes).to receive(:create).with(
|
|
460
|
-
previous_state: nil,
|
|
461
|
-
next_state: 'shipped',
|
|
462
|
-
name: 'shipment',
|
|
463
|
-
user_id: nil
|
|
464
|
-
)
|
|
465
|
-
|
|
466
|
-
order.state_changed('shipment')
|
|
467
|
-
end
|
|
468
|
-
|
|
469
468
|
context "completed order" do
|
|
470
469
|
before { allow(order).to receive_messages completed?: true }
|
|
471
470
|
|
|
@@ -154,12 +154,20 @@ module Spree
|
|
|
154
154
|
context "unpermitted" do
|
|
155
155
|
let(:attributes) { ActionController::Parameters.new(valid_attributes) }
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
if Rails.gem_version < Gem::Version.new('5.1')
|
|
158
|
+
it "ignores all attributes" do
|
|
159
|
+
expect(new_payment).to have_attributes(
|
|
160
|
+
amount: 0,
|
|
161
|
+
payment_method: nil,
|
|
162
|
+
source: nil
|
|
163
|
+
)
|
|
164
|
+
end
|
|
165
|
+
else
|
|
166
|
+
it "raises an exception" do
|
|
167
|
+
expect {
|
|
168
|
+
new_payment
|
|
169
|
+
}.to raise_exception(ActionController::UnfilteredParameters)
|
|
170
|
+
end
|
|
163
171
|
end
|
|
164
172
|
end
|
|
165
173
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
describe PaymentMethod::BogusCreditCard, type: :model do
|
|
5
|
+
let(:bogus) { create(:credit_card_payment_method) }
|
|
6
|
+
let!(:cc) { create(:credit_card, payment_method: bogus, gateway_customer_profile_id: "BGS-RERTERT") }
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::PaymentMethod::Check do
|
|
4
|
+
let(:order) { create(:order) }
|
|
5
|
+
subject { described_class.new }
|
|
6
|
+
|
|
7
|
+
context "#can_capture?" do
|
|
8
|
+
let(:payment) { create(:payment, order: order, state: state) }
|
|
9
|
+
|
|
10
|
+
context "with payment in state checkout" do
|
|
11
|
+
let(:state) { "checkout" }
|
|
12
|
+
|
|
13
|
+
it "returns true" do
|
|
14
|
+
expect(subject.can_capture?(payment)).to be_truthy
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "with payment in state pending" do
|
|
19
|
+
let(:state) { "pending" }
|
|
20
|
+
|
|
21
|
+
it "returns true" do
|
|
22
|
+
expect(subject.can_capture?(payment)).to be_truthy
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "with payment in state failed" do
|
|
27
|
+
let(:state) { "failed" }
|
|
28
|
+
|
|
29
|
+
it "returns false" do
|
|
30
|
+
expect(subject.can_capture?(payment)).to be_falsy
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "#can_void?" do
|
|
36
|
+
let(:payment) { create(:payment, order: order, state: state) }
|
|
37
|
+
|
|
38
|
+
context "with payment in state checkout" do
|
|
39
|
+
let(:state) { "checkout" }
|
|
40
|
+
|
|
41
|
+
it "returns true" do
|
|
42
|
+
expect(subject.can_void?(payment)).to be_truthy
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "with payment in state void" do
|
|
47
|
+
let(:state) { "void" }
|
|
48
|
+
|
|
49
|
+
it "returns false" do
|
|
50
|
+
expect(subject.can_void?(payment)).to be_falsy
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "#capture" do
|
|
56
|
+
it "succeds" do
|
|
57
|
+
expect(subject.capture).to be_success
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "#cancel" do
|
|
62
|
+
it "returns nil" do
|
|
63
|
+
expect(subject.cancel).to be_nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "#void" do
|
|
68
|
+
it "succeds" do
|
|
69
|
+
expect(subject.void).to be_success
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "#credit" do
|
|
74
|
+
it "succeds" do
|
|
75
|
+
expect(subject.credit).to be_success
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|