solidus_core 1.1.0 → 1.1.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/Gemfile +3 -0
- data/Rakefile +16 -0
- data/script/rails +9 -0
- data/solidus_core.gemspec +48 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +173 -0
- data/spec/helpers/order_helper_spec.rb +12 -0
- data/spec/helpers/products_helper_spec.rb +208 -0
- data/spec/helpers/taxons_helper_spec.rb +17 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +106 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/search/variant_spec.rb +112 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +66 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +92 -0
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +80 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/current_store_spec.rb +36 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +24 -0
- data/spec/lib/spree/core/importer/order_spec.rb +431 -0
- data/spec/lib/spree/core/role_configuration_spec.rb +156 -0
- data/spec/lib/spree/core/unreturned_item_charger_spec.rb +130 -0
- data/spec/lib/spree/core/validators/email_spec.rb +48 -0
- data/spec/lib/spree/localized_number_spec.rb +38 -0
- data/spec/lib/spree/migrations_spec.rb +36 -0
- data/spec/lib/spree/money_spec.rb +127 -0
- data/spec/lib/tasks/exchanges_spec.rb +231 -0
- data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +115 -0
- data/spec/lib/tasks/order_capturing_spec.rb +56 -0
- data/spec/mailers/carton_mailer_spec.rb +55 -0
- data/spec/mailers/order_mailer_spec.rb +135 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +40 -0
- data/spec/mailers/test_mailer_spec.rb +15 -0
- data/spec/models/spree/ability_spec.rb +276 -0
- data/spec/models/spree/address_spec.rb +376 -0
- data/spec/models/spree/adjustment_reason_spec.rb +13 -0
- data/spec/models/spree/adjustment_spec.rb +169 -0
- data/spec/models/spree/app_configuration_spec.rb +24 -0
- data/spec/models/spree/asset_spec.rb +24 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +60 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +36 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +47 -0
- data/spec/models/spree/calculator_spec.rb +36 -0
- data/spec/models/spree/carton_spec.rb +133 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/concerns/ordered_property_value_list_spec.rb +25 -0
- data/spec/models/spree/concerns/user_address_book_spec.rb +332 -0
- data/spec/models/spree/concerns/user_methods_spec.rb +41 -0
- data/spec/models/spree/credit_card_spec.rb +341 -0
- data/spec/models/spree/customer_return_spec.rb +276 -0
- data/spec/models/spree/exchange_spec.rb +79 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +104 -0
- data/spec/models/spree/inventory_unit_spec.rb +307 -0
- data/spec/models/spree/item_adjustments_spec.rb +275 -0
- data/spec/models/spree/line_item_spec.rb +199 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +45 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +27 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +884 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +110 -0
- data/spec/models/spree/order/payment_spec.rb +243 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +68 -0
- data/spec/models/spree/order/state_machine_spec.rb +209 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_cancellations_spec.rb +120 -0
- data/spec/models/spree/order_capturing_spec.rb +150 -0
- data/spec/models/spree/order_contents_spec.rb +307 -0
- data/spec/models/spree/order_inventory_spec.rb +228 -0
- data/spec/models/spree/order_mutex_spec.rb +85 -0
- data/spec/models/spree/order_promotion_spec.rb +31 -0
- data/spec/models/spree/order_shipping_spec.rb +241 -0
- data/spec/models/spree/order_spec.rb +1482 -0
- data/spec/models/spree/order_stock_location_spec.rb +18 -0
- data/spec/models/spree/order_updater_spec.rb +283 -0
- data/spec/models/spree/payment_method/store_credit_spec.rb +294 -0
- data/spec/models/spree/payment_method_spec.rb +147 -0
- data/spec/models/spree/payment_spec.rb +1087 -0
- data/spec/models/spree/permission_sets/base_spec.rb +12 -0
- data/spec/models/spree/permission_sets/configuration_display.rb +82 -0
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +50 -0
- data/spec/models/spree/permission_sets/dashboard_display_spec.rb +22 -0
- data/spec/models/spree/permission_sets/order_display_spec.rb +55 -0
- data/spec/models/spree/permission_sets/order_management_spec.rb +42 -0
- data/spec/models/spree/permission_sets/product_display_spec.rb +60 -0
- data/spec/models/spree/permission_sets/product_management_spec.rb +40 -0
- data/spec/models/spree/permission_sets/promotion_display_spec.rb +40 -0
- data/spec/models/spree/permission_sets/promotion_management_spec.rb +26 -0
- data/spec/models/spree/permission_sets/report_display_spec.rb +24 -0
- data/spec/models/spree/permission_sets/restricted_stock_display_spec.rb +41 -0
- data/spec/models/spree/permission_sets/restricted_stock_management_spec.rb +41 -0
- data/spec/models/spree/permission_sets/restricted_stock_transfer_display_spec.rb +50 -0
- data/spec/models/spree/permission_sets/restricted_stock_transfer_management_spec.rb +160 -0
- data/spec/models/spree/permission_sets/stock_display_spec.rb +24 -0
- data/spec/models/spree/permission_sets/stock_management_spec.rb +22 -0
- data/spec/models/spree/permission_sets/stock_transfer_display_spec.rb +24 -0
- data/spec/models/spree/permission_sets/stock_transfer_management_spec.rb +25 -0
- data/spec/models/spree/permission_sets/user_display_spec.rb +38 -0
- data/spec/models/spree/permission_sets/user_management_spec.rb +48 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +294 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +60 -0
- data/spec/models/spree/preferences/static_model_preferences_spec.rb +78 -0
- data/spec/models/spree/preferences/statically_configurable_spec.rb +60 -0
- data/spec/models/spree/preferences/store_spec.rb +39 -0
- data/spec/models/spree/price_spec.rb +42 -0
- data/spec/models/spree/product/scopes_spec.rb +116 -0
- data/spec/models/spree/product_duplicator_spec.rb +103 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_property_spec.rb +18 -0
- data/spec/models/spree/product_spec.rb +504 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +96 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +165 -0
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +115 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +40 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +69 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +67 -0
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +70 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +94 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
- data/spec/models/spree/promotion_builder_spec.rb +118 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_code/code_builder_spec.rb +79 -0
- data/spec/models/spree/promotion_code_spec.rb +187 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +130 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +335 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +47 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +28 -0
- data/spec/models/spree/promotion_spec.rb +776 -0
- data/spec/models/spree/refund_spec.rb +192 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +231 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +107 -0
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +97 -0
- data/spec/models/spree/return_authorization_spec.rb +290 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +85 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +776 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/shipment_spec.rb +753 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_manifest_spec.rb +94 -0
- data/spec/models/spree/shipping_method_spec.rb +88 -0
- data/spec/models/spree/shipping_rate_spec.rb +142 -0
- data/spec/models/spree/state_spec.rb +14 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +83 -0
- data/spec/models/spree/stock/coordinator_spec.rb +116 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +146 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
- data/spec/models/spree/stock/package_spec.rb +163 -0
- data/spec/models/spree/stock/packer_spec.rb +91 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +115 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +50 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +29 -0
- data/spec/models/spree/stock_item_spec.rb +444 -0
- data/spec/models/spree/stock_location_spec.rb +279 -0
- data/spec/models/spree/stock_movement_spec.rb +56 -0
- data/spec/models/spree/stock_transfer_spec.rb +290 -0
- data/spec/models/spree/store_credit_category_spec.rb +17 -0
- data/spec/models/spree/store_credit_event_spec.rb +314 -0
- data/spec/models/spree/store_credit_spec.rb +876 -0
- data/spec/models/spree/store_spec.rb +55 -0
- data/spec/models/spree/tax_category_spec.rb +27 -0
- data/spec/models/spree/tax_rate_spec.rb +378 -0
- data/spec/models/spree/taxon_spec.rb +74 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/transfer_item_spec.rb +264 -0
- data/spec/models/spree/unit_cancel_spec.rb +149 -0
- data/spec/models/spree/user_spec.rb +246 -0
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +23 -0
- data/spec/models/spree/variant/scopes_spec.rb +55 -0
- data/spec/models/spree/variant_property_rule_condition_spec.rb +15 -0
- data/spec/models/spree/variant_property_rule_spec.rb +83 -0
- data/spec/models/spree/variant_property_rule_value_spec.rb +18 -0
- data/spec/models/spree/variant_spec.rb +601 -0
- data/spec/models/spree/zone_spec.rb +305 -0
- data/spec/spec_helper.rb +80 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/default_price.rb +34 -0
- data/spec/support/dummy_ability.rb +4 -0
- data/spec/support/test_gateway.rb +2 -0
- metadata +242 -2
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order, :type => :model do
|
4
|
+
let(:order) { Spree::Order.new }
|
5
|
+
before do
|
6
|
+
# Ensure state machine has been re-defined correctly
|
7
|
+
Spree::Order.define_state_machine!
|
8
|
+
# We don't care about this validation here
|
9
|
+
allow(order).to receive(:require_email)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#next!" do
|
13
|
+
context "when current state is confirm" do
|
14
|
+
before do
|
15
|
+
order.state = "confirm"
|
16
|
+
order.run_callbacks(:create)
|
17
|
+
allow(order).to receive_messages :payment_required? => true
|
18
|
+
allow(order).to receive_messages :process_payments! => true
|
19
|
+
allow(order).to receive_messages :ensure_available_shipping_rates => true
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when payment processing succeeds" do
|
23
|
+
before do
|
24
|
+
order.payments << FactoryGirl.create(:payment, state: 'checkout', order: order)
|
25
|
+
allow(order).to receive_messages process_payments: true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should finalize order when transitioning to complete state" do
|
29
|
+
expect(order).to receive(:finalize!)
|
30
|
+
order.complete!
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when credit card processing fails" do
|
34
|
+
before { allow(order).to receive_messages :process_payments! => false }
|
35
|
+
|
36
|
+
it "should not complete the order" do
|
37
|
+
order.next
|
38
|
+
expect(order.state).to eq("confirm")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when payment processing fails" do
|
44
|
+
before { allow(order).to receive_messages :process_payments! => false }
|
45
|
+
|
46
|
+
it "cannot transition to complete" do
|
47
|
+
order.next
|
48
|
+
expect(order.state).to eq("confirm")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when current state is delivery" do
|
54
|
+
before do
|
55
|
+
allow(order).to receive_messages :payment_required? => true
|
56
|
+
allow(order).to receive :apply_free_shipping_promotions
|
57
|
+
order.state = "delivery"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "adjusts tax rates when transitioning to delivery" do
|
61
|
+
# Once for the line items
|
62
|
+
expect(Spree::TaxRate).to receive(:adjust).once
|
63
|
+
allow(order).to receive :set_shipments_cost
|
64
|
+
order.next!
|
65
|
+
end
|
66
|
+
|
67
|
+
it "adjusts tax rates twice if there are any shipments" do
|
68
|
+
# Once for the line items, once for the shipments
|
69
|
+
order.shipments.build
|
70
|
+
expect(Spree::TaxRate).to receive(:adjust).twice
|
71
|
+
allow(order).to receive :set_shipments_cost
|
72
|
+
order.next!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "#can_cancel?" do
|
78
|
+
states = [:pending, :backorder, :ready]
|
79
|
+
|
80
|
+
states.each do |shipment_state|
|
81
|
+
it "should be true if shipment_state is #{shipment_state}" do
|
82
|
+
allow(order).to receive_messages :completed? => true
|
83
|
+
order.shipment_state = shipment_state
|
84
|
+
expect(order.can_cancel?).to be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
(Spree::Shipment.state_machine.states.keys - states).each do |shipment_state|
|
89
|
+
it "should be false if shipment_state is #{shipment_state}" do
|
90
|
+
allow(order).to receive_messages :completed? => true
|
91
|
+
order.shipment_state = shipment_state
|
92
|
+
expect(order.can_cancel?).to be false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
context "#cancel" do
|
99
|
+
let!(:variant) { stub_model(Spree::Variant) }
|
100
|
+
let!(:inventory_units) { [stub_model(Spree::InventoryUnit, :variant => variant),
|
101
|
+
stub_model(Spree::InventoryUnit, :variant => variant) ]}
|
102
|
+
let!(:shipment) do
|
103
|
+
shipment = stub_model(Spree::Shipment)
|
104
|
+
allow(shipment).to receive_messages :inventory_units => inventory_units, :order => order
|
105
|
+
allow(order).to receive_messages :shipments => [shipment]
|
106
|
+
shipment
|
107
|
+
end
|
108
|
+
|
109
|
+
before do
|
110
|
+
|
111
|
+
2.times do
|
112
|
+
create(:line_item, :order => order, price: 10)
|
113
|
+
end
|
114
|
+
|
115
|
+
allow(order.line_items).to receive_messages :find_by_variant_id => order.line_items.first
|
116
|
+
|
117
|
+
allow(order).to receive_messages :completed? => true
|
118
|
+
allow(order).to receive_messages :allow_cancel? => true
|
119
|
+
|
120
|
+
shipments = [shipment]
|
121
|
+
allow(order).to receive_messages :shipments => shipments
|
122
|
+
allow(shipments).to receive_messages :states => []
|
123
|
+
allow(shipments).to receive_messages :ready => []
|
124
|
+
allow(shipments).to receive_messages :pending => []
|
125
|
+
allow(shipments).to receive_messages :shipped => []
|
126
|
+
|
127
|
+
allow_any_instance_of(Spree::OrderUpdater).to receive(:update_adjustment_total) { 10 }
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should send a cancel email" do
|
131
|
+
|
132
|
+
# Stub methods that cause side-effects in this test
|
133
|
+
allow(shipment).to receive(:cancel!)
|
134
|
+
allow(order).to receive :restock_items!
|
135
|
+
expect(Spree::OrderMailer).to receive(:cancel_email).with(order).and_return(mail_message = double)
|
136
|
+
expect(mail_message).to receive :deliver_later
|
137
|
+
order.cancel!
|
138
|
+
end
|
139
|
+
|
140
|
+
context "restocking inventory" do
|
141
|
+
before do
|
142
|
+
allow(shipment).to receive(:ensure_correct_adjustment)
|
143
|
+
allow(shipment).to receive(:update_order)
|
144
|
+
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
|
145
|
+
allow(mail_message).to receive :deliver_later
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "resets payment state" do
|
151
|
+
|
152
|
+
let(:payment) { create(:payment, amount: order.total) }
|
153
|
+
|
154
|
+
before do
|
155
|
+
# TODO: This is ugly :(
|
156
|
+
# Stubs methods that cause unwanted side effects in this test
|
157
|
+
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
|
158
|
+
allow(mail_message).to receive :deliver_later
|
159
|
+
allow(order).to receive :restock_items!
|
160
|
+
allow(shipment).to receive(:cancel!)
|
161
|
+
allow(payment).to receive(:cancel!)
|
162
|
+
allow(order).to receive_message_chain(:payments, :valid, :size).and_return(1)
|
163
|
+
allow(order).to receive_message_chain(:payments, :completed).and_return([payment])
|
164
|
+
allow(order).to receive_message_chain(:payments, :completed, :includes).and_return([payment])
|
165
|
+
allow(order).to receive_message_chain(:payments, :last).and_return(payment)
|
166
|
+
allow(order).to receive_message_chain(:payments, :store_credits, :pending).and_return([payment])
|
167
|
+
allow(order).to receive(:refund_total).and_return(0)
|
168
|
+
end
|
169
|
+
|
170
|
+
context "without shipped items" do
|
171
|
+
it "should set payment state to 'void'" do
|
172
|
+
expect { order.cancel! }.to change{ order.reload.payment_state }.to("void")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with shipped items" do
|
177
|
+
before do
|
178
|
+
allow(order).to receive_messages shipment_state: 'partial'
|
179
|
+
allow(order).to receive_messages outstanding_balance?: false
|
180
|
+
allow(order).to receive_messages payment_state: "paid"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should not alter the payment state" do
|
184
|
+
order.cancel!
|
185
|
+
expect(order.payment_state).to eql "paid"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "with payments" do
|
190
|
+
let(:payment) { create(:payment) }
|
191
|
+
|
192
|
+
it "should automatically refund all payments" do
|
193
|
+
expect(payment).to receive(:cancel!)
|
194
|
+
order.cancel!
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
# Another regression test for #729
|
202
|
+
context "#resume" do
|
203
|
+
before do
|
204
|
+
allow(order).to receive_messages email: "user@spreecommerce.com"
|
205
|
+
allow(order).to receive_messages state: "canceled"
|
206
|
+
allow(order).to receive_messages allow_resume?: true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Spree::Order, :type => :model do
|
5
|
+
let(:order) { stub_model(Spree::Order) }
|
6
|
+
|
7
|
+
context "#tax_zone" do
|
8
|
+
let(:bill_address) { create :address }
|
9
|
+
let(:ship_address) { create :address }
|
10
|
+
let(:order) { Spree::Order.create(:ship_address => ship_address, :bill_address => bill_address) }
|
11
|
+
let(:zone) { create :zone }
|
12
|
+
|
13
|
+
context "when no zones exist" do
|
14
|
+
it "should return nil" do
|
15
|
+
expect(order.tax_zone).to be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when :tax_using_ship_address => true" do
|
20
|
+
before { Spree::Config.set(:tax_using_ship_address => true) }
|
21
|
+
|
22
|
+
it "should calculate using ship_address" do
|
23
|
+
expect(Spree::Zone).to receive(:match).at_least(:once).with(ship_address)
|
24
|
+
expect(Spree::Zone).not_to receive(:match).with(bill_address)
|
25
|
+
order.tax_zone
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when :tax_using_ship_address => false" do
|
30
|
+
before { Spree::Config.set(:tax_using_ship_address => false) }
|
31
|
+
|
32
|
+
it "should calculate using bill_address" do
|
33
|
+
expect(Spree::Zone).to receive(:match).at_least(:once).with(bill_address)
|
34
|
+
expect(Spree::Zone).not_to receive(:match).with(ship_address)
|
35
|
+
order.tax_zone
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when there is a default tax zone" do
|
40
|
+
before do
|
41
|
+
@default_zone = create(:zone, :name => "foo_zone")
|
42
|
+
allow(Spree::Zone).to receive_messages :default_tax => @default_zone
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when there is a matching zone" do
|
46
|
+
before { allow(Spree::Zone).to receive_messages(:match => zone) }
|
47
|
+
|
48
|
+
it "should return the matching zone" do
|
49
|
+
expect(order.tax_zone).to eq(zone)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when there is no matching zone" do
|
54
|
+
before { allow(Spree::Zone).to receive_messages(:match => nil) }
|
55
|
+
|
56
|
+
it "should return the default tax zone" do
|
57
|
+
expect(order.tax_zone).to eq(@default_zone)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when no default tax zone" do
|
63
|
+
before { allow(Spree::Zone).to receive_messages :default_tax => nil }
|
64
|
+
|
65
|
+
context "when there is a matching zone" do
|
66
|
+
before { allow(Spree::Zone).to receive_messages(:match => zone) }
|
67
|
+
|
68
|
+
it "should return the matching zone" do
|
69
|
+
expect(order.tax_zone).to eq(zone)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when there is no matching zone" do
|
74
|
+
before { allow(Spree::Zone).to receive_messages(:match => nil) }
|
75
|
+
|
76
|
+
it "should return nil" do
|
77
|
+
expect(order.tax_zone).to be_nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Order, :type => :model do
|
5
|
+
let(:order) { Order.create }
|
6
|
+
let(:shirt) { create(:variant) }
|
7
|
+
|
8
|
+
context "adds item to cart and activates promo" do
|
9
|
+
let(:promotion) { Promotion.create name: 'Huhu', apply_automatically: true }
|
10
|
+
let(:calculator) { Calculator::FlatPercentItemTotal.new(:preferred_flat_percent => 10) }
|
11
|
+
let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
|
12
|
+
|
13
|
+
before { order.contents.add(shirt, 1) }
|
14
|
+
|
15
|
+
context "item quantity changes" do
|
16
|
+
it "recalculates order adjustments" do
|
17
|
+
expect {
|
18
|
+
order.contents.add(shirt, 3)
|
19
|
+
}.to change { order.adjustments.eligible.pluck(:amount) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order, :type => :model do
|
4
|
+
let(:order) { stub_model(Spree::Order) }
|
5
|
+
|
6
|
+
context "#update!" do
|
7
|
+
let(:line_items) { [mock_model(Spree::LineItem, :amount => 5) ]}
|
8
|
+
|
9
|
+
context "when there are update hooks" do
|
10
|
+
before { Spree::Order.register_update_hook :foo }
|
11
|
+
after { Spree::Order.update_hooks.clear }
|
12
|
+
it "should call each of the update hooks" do
|
13
|
+
expect(order).to receive :foo
|
14
|
+
order.update!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Spree::Order, :type => :model do
|
5
|
+
context "validations" do
|
6
|
+
# Regression test for #2214
|
7
|
+
it "does not return two error messages when email is blank" do
|
8
|
+
order = Spree::Order.new
|
9
|
+
allow(order).to receive_messages(:require_email => true)
|
10
|
+
order.valid?
|
11
|
+
expect(order.errors[:email]).to eq(["can't be blank"])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::OrderCancellations do
|
4
|
+
describe "#short_ship" do
|
5
|
+
subject { Spree::OrderCancellations.new(order).short_ship([inventory_unit]) }
|
6
|
+
|
7
|
+
let(:order) { create(:order_ready_to_ship, line_items_count: 1) }
|
8
|
+
let(:inventory_unit) { order.inventory_units.first }
|
9
|
+
let(:shipment) { inventory_unit.shipment }
|
10
|
+
|
11
|
+
it "creates a UnitCancel record" do
|
12
|
+
expect { subject }.to change { Spree::UnitCancel.count }.by(1)
|
13
|
+
|
14
|
+
unit_cancel = Spree::UnitCancel.last
|
15
|
+
expect(unit_cancel.inventory_unit).to eq inventory_unit
|
16
|
+
expect(unit_cancel.reason).to eq Spree::UnitCancel::SHORT_SHIP
|
17
|
+
end
|
18
|
+
|
19
|
+
it "cancels the inventory unit" do
|
20
|
+
expect { subject }.to change { inventory_unit.state }.to "canceled"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "updates the shipment.state" do
|
24
|
+
expect { subject }.to change { shipment.reload.state }.from('ready').to('shipped')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "updates the order.shipment_state" do
|
28
|
+
expect { subject }.to change { order.shipment_state }.from('ready').to('shipped')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "adjusts the order" do
|
32
|
+
expect { subject }.to change { order.total }.by(-10.0)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sends a cancellation email" do
|
36
|
+
mail_double = double
|
37
|
+
expect(Spree::OrderMailer).to receive(:inventory_cancellation_email).with(order, [inventory_unit]).and_return(mail_double)
|
38
|
+
expect(mail_double).to receive(:deliver_later)
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when send_cancellation_mailer is false" do
|
43
|
+
subject { Spree::OrderCancellations.new(order).short_ship([inventory_unit]) }
|
44
|
+
|
45
|
+
before do
|
46
|
+
@original_send_boolean = Spree::OrderCancellations.send_cancellation_mailer
|
47
|
+
Spree::OrderCancellations.send_cancellation_mailer = false
|
48
|
+
end
|
49
|
+
|
50
|
+
after { Spree::OrderCancellations.send_cancellation_mailer = @original_send_boolean }
|
51
|
+
|
52
|
+
it "does not send a cancellation email" do
|
53
|
+
expect(Spree::OrderMailer).not_to receive(:inventory_cancellation_email)
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a who" do
|
59
|
+
subject { order.cancellations.short_ship([inventory_unit], whodunnit: 'some automated system') }
|
60
|
+
|
61
|
+
let(:user) { order.user }
|
62
|
+
|
63
|
+
it "sets the user on the UnitCancel" do
|
64
|
+
expect { subject }.to change { Spree::UnitCancel.count }.by(1)
|
65
|
+
expect(Spree::UnitCancel.last.created_by).to eq("some automated system")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when rounding is required" do
|
70
|
+
let(:order) { create(:order_ready_to_ship, line_items_count: 1, line_items_price: 0.83) }
|
71
|
+
let(:line_item) { order.line_items.first }
|
72
|
+
let(:inventory_unit_1) { line_item.inventory_units[0] }
|
73
|
+
let(:inventory_unit_2) { line_item.inventory_units[1] }
|
74
|
+
|
75
|
+
before do
|
76
|
+
order.contents.add(line_item.variant)
|
77
|
+
line_item.reload
|
78
|
+
|
79
|
+
# make the total $1.67 so it divides unevenly
|
80
|
+
Spree::Adjustment.tax.create!(
|
81
|
+
order: order,
|
82
|
+
adjustable: line_item,
|
83
|
+
amount: 0.01,
|
84
|
+
label: 'some fake tax',
|
85
|
+
finalized: true
|
86
|
+
)
|
87
|
+
order.update!
|
88
|
+
end
|
89
|
+
|
90
|
+
it "generates the correct total amount" do
|
91
|
+
order.cancellations.short_ship([inventory_unit_1])
|
92
|
+
order.cancellations.short_ship([inventory_unit_2])
|
93
|
+
expect(line_item.adjustments.non_tax.sum(:amount)).to eq -1.67
|
94
|
+
expect(line_item.total).to eq 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'short_ship_tax_notifier' do
|
99
|
+
context 'when present' do
|
100
|
+
let(:short_ship_tax_notifier) { double }
|
101
|
+
|
102
|
+
before do
|
103
|
+
@old_notifier = Spree::OrderCancellations.short_ship_tax_notifier
|
104
|
+
Spree::OrderCancellations.short_ship_tax_notifier = short_ship_tax_notifier
|
105
|
+
end
|
106
|
+
after do
|
107
|
+
Spree::OrderCancellations.short_ship_tax_notifier = @old_notifier
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'calls the short_ship_tax_notifier' do
|
111
|
+
expect(short_ship_tax_notifier).to receive(:call) do |unit_cancels|
|
112
|
+
expect(unit_cancels.map(&:inventory_unit)).to match_array([inventory_unit])
|
113
|
+
end
|
114
|
+
|
115
|
+
order.cancellations.short_ship([inventory_unit])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|