spree_core 3.2.1 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +3 -206
- data/spec/fixtures/microdata.html +0 -22
- data/spec/fixtures/microdata_itemref.html +0 -15
- data/spec/fixtures/microdata_no_itemscope.html +0 -20
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -200
- data/spec/helpers/products_helper_spec.rb +0 -289
- data/spec/lib/calculated_adjustments_spec.rb +0 -7
- data/spec/lib/i18n_spec.rb +0 -123
- data/spec/lib/search/base_spec.rb +0 -86
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
- data/spec/lib/spree/core/importer/order_spec.rb +0 -605
- data/spec/lib/spree/core/number_generator_spec.rb +0 -175
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -53
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -48
- data/spec/lib/spree/migrations_spec.rb +0 -36
- data/spec/lib/spree/money_spec.rb +0 -122
- data/spec/lib/tasks/exchanges_spec.rb +0 -136
- data/spec/mailers/order_mailer_spec.rb +0 -122
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- data/spec/models/option_type_prototype_spec.rb +0 -9
- data/spec/models/spree/ability_spec.rb +0 -251
- data/spec/models/spree/address_spec.rb +0 -402
- data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
- data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
- data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
- data/spec/models/spree/adjustment_spec.rb +0 -189
- data/spec/models/spree/app_configuration_spec.rb +0 -26
- data/spec/models/spree/asset_spec.rb +0 -28
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
- data/spec/models/spree/calculator/shipping.rb +0 -8
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
- data/spec/models/spree/calculator_spec.rb +0 -69
- data/spec/models/spree/classification_spec.rb +0 -93
- data/spec/models/spree/concerns/display_money_spec.rb +0 -43
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
- data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
- data/spec/models/spree/country_spec.rb +0 -55
- data/spec/models/spree/credit_card_spec.rb +0 -328
- data/spec/models/spree/customer_return_spec.rb +0 -240
- data/spec/models/spree/exchange_spec.rb +0 -75
- data/spec/models/spree/gateway/bogus_simple.rb +0 -20
- data/spec/models/spree/gateway/bogus_spec.rb +0 -13
- data/spec/models/spree/gateway_spec.rb +0 -61
- data/spec/models/spree/image_spec.rb +0 -8
- data/spec/models/spree/inventory_unit_spec.rb +0 -256
- data/spec/models/spree/line_item_spec.rb +0 -346
- data/spec/models/spree/option_type_spec.rb +0 -14
- data/spec/models/spree/option_value_spec.rb +0 -18
- data/spec/models/spree/order/address_spec.rb +0 -50
- data/spec/models/spree/order/adjustments_spec.rb +0 -29
- data/spec/models/spree/order/callbacks_spec.rb +0 -42
- data/spec/models/spree/order/checkout_spec.rb +0 -770
- data/spec/models/spree/order/currency_updater_spec.rb +0 -32
- data/spec/models/spree/order/finalizing_spec.rb +0 -114
- data/spec/models/spree/order/helpers_spec.rb +0 -5
- data/spec/models/spree/order/payment_spec.rb +0 -214
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
- data/spec/models/spree/order/shipments_spec.rb +0 -43
- data/spec/models/spree/order/state_machine_spec.rb +0 -212
- data/spec/models/spree/order/store_credit_spec.rb +0 -426
- data/spec/models/spree/order/tax_spec.rb +0 -84
- data/spec/models/spree/order/totals_spec.rb +0 -24
- data/spec/models/spree/order/updating_spec.rb +0 -18
- data/spec/models/spree/order/validations_spec.rb +0 -15
- data/spec/models/spree/order_contents_spec.rb +0 -297
- data/spec/models/spree/order_inventory_spec.rb +0 -239
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1046
- data/spec/models/spree/order_updater_spec.rb +0 -305
- data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
- data/spec/models/spree/payment/store_credit_spec.rb +0 -60
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
- data/spec/models/spree/payment_method_spec.rb +0 -103
- data/spec/models/spree/payment_spec.rb +0 -919
- data/spec/models/spree/preference_spec.rb +0 -80
- data/spec/models/spree/preferences/configuration_spec.rb +0 -30
- data/spec/models/spree/preferences/preferable_spec.rb +0 -344
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
- data/spec/models/spree/preferences/store_spec.rb +0 -46
- data/spec/models/spree/price_spec.rb +0 -128
- data/spec/models/spree/product/scopes_spec.rb +0 -183
- data/spec/models/spree/product_duplicator_spec.rb +0 -103
- data/spec/models/spree/product_filter_spec.rb +0 -26
- data/spec/models/spree/product_option_type_spec.rb +0 -9
- data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
- data/spec/models/spree/product_property_spec.rb +0 -26
- data/spec/models/spree/product_spec.rb +0 -629
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
- data/spec/models/spree/promotion_action_spec.rb +0 -10
- data/spec/models/spree/promotion_category_spec.rb +0 -17
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
- data/spec/models/spree/promotion_rule_spec.rb +0 -29
- data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
- data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
- data/spec/models/spree/promotion_spec.rb +0 -679
- data/spec/models/spree/property_prototype_spec.rb +0 -9
- data/spec/models/spree/property_spec.rb +0 -5
- data/spec/models/spree/prototype_spec.rb +0 -5
- data/spec/models/spree/prototype_taxon_spec.rb +0 -9
- data/spec/models/spree/refund_reason_spec.rb +0 -20
- data/spec/models/spree/refund_spec.rb +0 -195
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
- data/spec/models/spree/reimbursement_spec.rb +0 -188
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
- data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
- data/spec/models/spree/return_authorization_spec.rb +0 -230
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -731
- data/spec/models/spree/returns_calculator_spec.rb +0 -14
- data/spec/models/spree/role_spec.rb +0 -7
- data/spec/models/spree/shipment_spec.rb +0 -742
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_category_spec.rb +0 -19
- data/spec/models/spree/shipping_method_spec.rb +0 -95
- data/spec/models/spree/shipping_rate_spec.rb +0 -140
- data/spec/models/spree/state_spec.rb +0 -29
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
- data/spec/models/spree/stock/content_item_spec.rb +0 -31
- data/spec/models/spree/stock/coordinator_spec.rb +0 -61
- data/spec/models/spree/stock/differentiator_spec.rb +0 -39
- data/spec/models/spree/stock/estimator_spec.rb +0 -202
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
- data/spec/models/spree/stock/package_spec.rb +0 -182
- data/spec/models/spree/stock/packer_spec.rb +0 -70
- data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
- data/spec/models/spree/stock/quantifier_spec.rb +0 -126
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
- data/spec/models/spree/stock_item_spec.rb +0 -432
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -120
- data/spec/models/spree/stock_transfer_spec.rb +0 -50
- data/spec/models/spree/store_credit_event_spec.rb +0 -101
- data/spec/models/spree/store_credit_spec.rb +0 -786
- data/spec/models/spree/store_spec.rb +0 -78
- data/spec/models/spree/tax_category_spec.rb +0 -32
- data/spec/models/spree/tax_rate_spec.rb +0 -561
- data/spec/models/spree/taxon_spec.rb +0 -85
- data/spec/models/spree/taxonomy_spec.rb +0 -18
- data/spec/models/spree/tracker_spec.rb +0 -21
- data/spec/models/spree/user_spec.rb +0 -203
- data/spec/models/spree/variant_spec.rb +0 -818
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -472
- data/spec/spec_helper.rb +0 -79
- data/spec/support/big_decimal.rb +0 -5
- data/spec/support/concerns/adjustment_source.rb +0 -23
- data/spec/support/concerns/default_price.rb +0 -37
- data/spec/support/rake.rb +0 -13
- data/spec/support/test_gateway.rb +0 -2
@@ -1,43 +0,0 @@
|
|
1
|
-
describe Spree::Order, type: :model do
|
2
|
-
let(:order) { create(:order_with_totals) }
|
3
|
-
|
4
|
-
context "ensure shipments will be updated" do
|
5
|
-
before { Spree::Shipment.create!(order: order, stock_location: create(:stock_location)) }
|
6
|
-
|
7
|
-
it "destroys current shipments" do
|
8
|
-
order.ensure_updated_shipments
|
9
|
-
expect(order.shipments).to be_empty
|
10
|
-
end
|
11
|
-
|
12
|
-
it "puts order back in address state" do
|
13
|
-
order.ensure_updated_shipments
|
14
|
-
expect(order.state).to eq 'address'
|
15
|
-
end
|
16
|
-
|
17
|
-
it "resets shipment_total" do
|
18
|
-
order.update_column(:shipment_total, 5)
|
19
|
-
order.ensure_updated_shipments
|
20
|
-
expect(order.shipment_total).to eq(0)
|
21
|
-
end
|
22
|
-
|
23
|
-
context "except when order is completed, that's OrderInventory job" do
|
24
|
-
it "doesn't touch anything" do
|
25
|
-
allow(order).to receive_messages completed?: true
|
26
|
-
order.update_column(:shipment_total, 5)
|
27
|
-
order.shipments.create!(stock_location: create(:stock_location))
|
28
|
-
|
29
|
-
expect {
|
30
|
-
order.ensure_updated_shipments
|
31
|
-
}.not_to change { order.shipment_total }
|
32
|
-
|
33
|
-
expect {
|
34
|
-
order.ensure_updated_shipments
|
35
|
-
}.not_to change { order.shipments }
|
36
|
-
|
37
|
-
expect {
|
38
|
-
order.ensure_updated_shipments
|
39
|
-
}.not_to change { order.state }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,212 +0,0 @@
|
|
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
|
-
end
|
20
|
-
|
21
|
-
context "when payment processing succeeds" do
|
22
|
-
before do
|
23
|
-
order.payments << FactoryGirl.create(:payment, state: 'checkout', order: order)
|
24
|
-
allow(order).to receive_messages process_payments: true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should finalize order when transitioning to complete state" do
|
28
|
-
expect(order).to receive(:finalize!)
|
29
|
-
order.next!
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when credit card processing fails" do
|
33
|
-
before { allow(order).to receive_messages process_payments!: false }
|
34
|
-
|
35
|
-
it "should not complete the order" do
|
36
|
-
order.next
|
37
|
-
expect(order.state).to eq("confirm")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when payment processing fails" do
|
43
|
-
before { allow(order).to receive_messages process_payments!: false }
|
44
|
-
|
45
|
-
it "cannot transition to complete" do
|
46
|
-
order.next
|
47
|
-
expect(order.state).to eq("confirm")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when current state is delivery" do
|
53
|
-
before do
|
54
|
-
allow(order).to receive_messages payment_required?: true
|
55
|
-
allow(order).to receive :apply_free_shipping_promotions
|
56
|
-
order.state = "delivery"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "adjusts tax rates when transitioning to delivery" do
|
60
|
-
# Once for the line items
|
61
|
-
expect(Spree::TaxRate).to receive(:adjust).once
|
62
|
-
allow(order).to receive :set_shipments_cost
|
63
|
-
order.next!
|
64
|
-
end
|
65
|
-
|
66
|
-
it "adjusts tax rates twice if there are any shipments" do
|
67
|
-
# Once for the line items, once for the shipments
|
68
|
-
order.shipments.build stock_location: create(:stock_location)
|
69
|
-
expect(Spree::TaxRate).to receive(:adjust).twice
|
70
|
-
allow(order).to receive :set_shipments_cost
|
71
|
-
order.next!
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "#can_cancel?" do
|
77
|
-
%w(pending backorder ready).each do |shipment_state|
|
78
|
-
it "should be true if shipment_state is #{shipment_state}" do
|
79
|
-
allow(order).to receive_messages completed?: true
|
80
|
-
order.shipment_state = shipment_state
|
81
|
-
expect(order.can_cancel?).to be true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
(Spree::Shipment.state_machine.states.keys - [:pending, :backorder, :ready]).each do |shipment_state|
|
86
|
-
it "should be false if shipment_state is #{shipment_state}" do
|
87
|
-
allow(order).to receive_messages completed?: true
|
88
|
-
order.shipment_state = shipment_state
|
89
|
-
expect(order.can_cancel?).to be false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "#cancel" do
|
95
|
-
let!(:variant) { stub_model(Spree::Variant) }
|
96
|
-
let!(:inventory_units) { [stub_model(Spree::InventoryUnit, variant: variant),
|
97
|
-
stub_model(Spree::InventoryUnit, variant: variant)] }
|
98
|
-
let!(:shipment) do
|
99
|
-
shipment = stub_model(Spree::Shipment)
|
100
|
-
allow(shipment).to receive_messages inventory_units: inventory_units, order: order
|
101
|
-
allow(order).to receive_messages shipments: [shipment]
|
102
|
-
shipment
|
103
|
-
end
|
104
|
-
|
105
|
-
before do
|
106
|
-
2.times do
|
107
|
-
create(:line_item, order: order, price: 10)
|
108
|
-
end
|
109
|
-
|
110
|
-
allow(order.line_items).to receive_messages find_by_variant_id: order.line_items.first
|
111
|
-
|
112
|
-
allow(order).to receive_messages completed?: true
|
113
|
-
allow(order).to receive_messages allow_cancel?: true
|
114
|
-
|
115
|
-
shipments = [shipment]
|
116
|
-
allow(order).to receive_messages shipments: shipments
|
117
|
-
allow(shipments).to receive_messages states: []
|
118
|
-
allow(shipments).to receive_messages ready: []
|
119
|
-
allow(shipments).to receive_messages pending: []
|
120
|
-
allow(shipments).to receive_messages shipped: []
|
121
|
-
allow(shipments).to receive(:sum).with(:cost).and_return(shipment.cost)
|
122
|
-
|
123
|
-
allow_any_instance_of(Spree::OrderUpdater).to receive(:update_adjustment_total) { 10 }
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should send a cancel email" do
|
127
|
-
# Stub methods that cause side-effects in this test
|
128
|
-
allow(shipment).to receive(:cancel!)
|
129
|
-
allow(order).to receive :restock_items!
|
130
|
-
mail_message = double "Mail::Message"
|
131
|
-
order_id = nil
|
132
|
-
expect(Spree::OrderMailer).to receive(:cancel_email) { |*args|
|
133
|
-
order_id = args[0]
|
134
|
-
mail_message
|
135
|
-
}
|
136
|
-
expect(mail_message).to receive :deliver_later
|
137
|
-
order.cancel!
|
138
|
-
expect(order_id).to eq(order.id)
|
139
|
-
end
|
140
|
-
|
141
|
-
context "restocking inventory" do
|
142
|
-
before do
|
143
|
-
allow(shipment).to receive(:ensure_correct_adjustment)
|
144
|
-
allow(shipment).to receive(:update_order)
|
145
|
-
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
|
146
|
-
allow(mail_message).to receive :deliver_later
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
context "resets payment state" do
|
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([])
|
167
|
-
end
|
168
|
-
|
169
|
-
context "without shipped items" do
|
170
|
-
it "should set payment state to 'void'" do
|
171
|
-
expect { order.cancel! }.to change{ order.reload.payment_state }.to("void")
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "with shipped items" do
|
176
|
-
before do
|
177
|
-
allow(order).to receive_messages shipment_state: 'partial'
|
178
|
-
allow(order).to receive_messages outstanding_balance?: false
|
179
|
-
allow(order).to receive_messages payment_state: "paid"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should not alter the payment state" do
|
183
|
-
order.cancel!
|
184
|
-
expect(order.payment_state).to eql "paid"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context "with payments" do
|
189
|
-
let(:payment) { create(:payment) }
|
190
|
-
|
191
|
-
it "should automatically refund all payments" do
|
192
|
-
allow(order).to receive_message_chain(:payments, :valid, :size).and_return(1)
|
193
|
-
allow(order).to receive_message_chain(:payments, :completed).and_return([payment])
|
194
|
-
allow(order).to receive_message_chain(:payments, :completed, :includes).and_return([payment])
|
195
|
-
allow(order).to receive_message_chain(:payments, :last).and_return(payment)
|
196
|
-
expect(payment).to receive(:cancel!)
|
197
|
-
order.cancel!
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# Another regression test for #729
|
204
|
-
context "#resume" do
|
205
|
-
before do
|
206
|
-
allow(order).to receive_messages email: "user@spreecommerce.org"
|
207
|
-
allow(order).to receive_messages state: "canceled"
|
208
|
-
allow(order).to receive_messages allow_resume?: true
|
209
|
-
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
@@ -1,426 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples "check total store credit from payments" do
|
4
|
-
context 'with valid payments' do
|
5
|
-
let(:order) { payment.order }
|
6
|
-
let!(:payment) { create(:store_credit_payment) }
|
7
|
-
let!(:second_payment) { create(:store_credit_payment, order: order) }
|
8
|
-
|
9
|
-
subject { order }
|
10
|
-
|
11
|
-
it 'returns the sum of the payment amounts' do
|
12
|
-
expect(subject.total_applicable_store_credit).to eq (payment.amount + second_payment.amount)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'without valid payments' do
|
17
|
-
let(:order) { create(:order) }
|
18
|
-
|
19
|
-
subject { order }
|
20
|
-
|
21
|
-
it 'returns 0' do
|
22
|
-
expect(subject.total_applicable_store_credit).to be_zero
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'Order' do
|
28
|
-
describe '#add_store_credit_payments' do
|
29
|
-
let(:order_total) { 500.00 }
|
30
|
-
|
31
|
-
before { create(:store_credit_payment_method) }
|
32
|
-
|
33
|
-
subject { order.add_store_credit_payments }
|
34
|
-
|
35
|
-
context 'there is no store credit' do
|
36
|
-
let(:order) { create(:store_credits_order_without_user, total: order_total) }
|
37
|
-
|
38
|
-
before do
|
39
|
-
# callbacks recalculate total based on line items
|
40
|
-
# this ensures the total is what we expect
|
41
|
-
order.update_column(:total, order_total)
|
42
|
-
subject
|
43
|
-
order.reload
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'does not create a store credit payment' do
|
47
|
-
expect(order.payments.count).to eq 0
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'there is enough store credit to pay for the entire order' do
|
52
|
-
let(:store_credit) { create(:store_credit, amount: order_total) }
|
53
|
-
let(:order) { create(:order, user: store_credit.user, total: order_total) }
|
54
|
-
|
55
|
-
before do
|
56
|
-
subject
|
57
|
-
order.reload
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'creates a store credit payment for the full amount' do
|
61
|
-
expect(order.payments.count).to eq 1
|
62
|
-
expect(order.payments.first).to be_store_credit
|
63
|
-
expect(order.payments.first.amount).to eq order_total
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'the available store credit is not enough to pay for the entire order' do
|
68
|
-
let(:expected_cc_total) { 100.0 }
|
69
|
-
let(:store_credit_total) { order_total - expected_cc_total }
|
70
|
-
let(:store_credit) { create(:store_credit, amount: store_credit_total) }
|
71
|
-
let(:order) { create(:order, user: store_credit.user, total: order_total) }
|
72
|
-
|
73
|
-
before do
|
74
|
-
# callbacks recalculate total based on line items
|
75
|
-
# this ensures the total is what we expect
|
76
|
-
order.update_column(:total, order_total)
|
77
|
-
subject
|
78
|
-
order.reload
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'creates a store credit payment for the available amount' do
|
82
|
-
expect(order.payments.count).to eq 1
|
83
|
-
expect(order.payments.first).to be_store_credit
|
84
|
-
expect(order.payments.first.amount).to eq store_credit_total
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'there are multiple store credits' do
|
89
|
-
context 'they have different credit type priorities' do
|
90
|
-
let(:amount_difference) { 100 }
|
91
|
-
let!(:primary_store_credit) { create(:store_credit, amount: (order_total - amount_difference)) }
|
92
|
-
let!(:secondary_store_credit) do
|
93
|
-
create(:store_credit, amount: order_total, user: primary_store_credit.user,
|
94
|
-
credit_type: create(:secondary_credit_type))
|
95
|
-
end
|
96
|
-
let(:order) { create(:order, user: primary_store_credit.user, total: order_total) }
|
97
|
-
|
98
|
-
before do
|
99
|
-
Timecop.scale(3600)
|
100
|
-
subject
|
101
|
-
order.reload
|
102
|
-
end
|
103
|
-
|
104
|
-
after { Timecop.return }
|
105
|
-
|
106
|
-
it 'uses the primary store credit type over the secondary' do
|
107
|
-
primary_payment = order.payments.first
|
108
|
-
secondary_payment = order.payments.last
|
109
|
-
|
110
|
-
expect(order.payments.size).to eq 2
|
111
|
-
expect(primary_payment.source).to eq primary_store_credit
|
112
|
-
expect(secondary_payment.source).to eq secondary_store_credit
|
113
|
-
expect(primary_payment.amount).to eq(order_total - amount_difference)
|
114
|
-
expect(secondary_payment.amount).to eq(amount_difference)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe '#covered_by_store_credit' do
|
121
|
-
context "order doesn't have an associated user" do
|
122
|
-
subject { create(:store_credits_order_without_user) }
|
123
|
-
|
124
|
-
it 'returns false' do
|
125
|
-
expect(subject.covered_by_store_credit).to be false
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'order has an associated user' do
|
130
|
-
let(:user) { create(:user) }
|
131
|
-
|
132
|
-
subject { create(:order, user: user) }
|
133
|
-
|
134
|
-
context 'user has enough store credit to pay for the order' do
|
135
|
-
before do
|
136
|
-
allow(user).to receive(:total_available_store_credit).and_return(10.0)
|
137
|
-
allow(subject).to receive(:total).and_return(5.0)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'returns true' do
|
141
|
-
expect(subject.covered_by_store_credit).to be true
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'user does not have enough store credit to pay for the order' do
|
146
|
-
before do
|
147
|
-
allow(user).to receive(:total_available_store_credit).and_return(0.0)
|
148
|
-
allow(subject).to receive(:total).and_return(5.0)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'returns false' do
|
152
|
-
expect(subject.covered_by_store_credit).to be false
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe '#total_available_store_credit' do
|
159
|
-
context 'order does not have an associated user' do
|
160
|
-
subject { create(:store_credits_order_without_user) }
|
161
|
-
|
162
|
-
it 'returns 0' do
|
163
|
-
expect(subject.total_available_store_credit).to be_zero
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'order has an associated user' do
|
168
|
-
let(:user) { create(:user) }
|
169
|
-
let(:available_store_credit) { 25.0 }
|
170
|
-
|
171
|
-
subject { create(:order, user: user) }
|
172
|
-
|
173
|
-
before do
|
174
|
-
allow(user).to receive(:total_available_store_credit).and_return(available_store_credit)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "returns the user's available store credit" do
|
178
|
-
expect(subject.total_available_store_credit).to eq available_store_credit
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe '#could_use_store_credit?' do
|
184
|
-
context 'order does not have an associated user' do
|
185
|
-
subject { create(:store_credits_order_without_user) }
|
186
|
-
|
187
|
-
it { expect(subject.could_use_store_credit?).to be false }
|
188
|
-
end
|
189
|
-
|
190
|
-
context 'order has an associated user' do
|
191
|
-
let(:user) { create(:user) }
|
192
|
-
|
193
|
-
subject { create(:order, user: user) }
|
194
|
-
|
195
|
-
context 'without store credit' do
|
196
|
-
it { expect(subject.could_use_store_credit?).to be false }
|
197
|
-
end
|
198
|
-
|
199
|
-
context 'with store credit' do
|
200
|
-
let(:available_store_credit) { 25.0 }
|
201
|
-
|
202
|
-
before do
|
203
|
-
allow(user).to receive(:total_available_store_credit).and_return(available_store_credit)
|
204
|
-
end
|
205
|
-
|
206
|
-
it { expect(subject.could_use_store_credit?).to be true }
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe '#order_total_after_store_credit' do
|
212
|
-
let(:order_total) { 100.0 }
|
213
|
-
|
214
|
-
subject { create(:order, total: order_total) }
|
215
|
-
|
216
|
-
before do
|
217
|
-
allow(subject).to receive(:total_applicable_store_credit).and_return(applicable_store_credit)
|
218
|
-
end
|
219
|
-
|
220
|
-
context "order's user has store credits" do
|
221
|
-
let(:applicable_store_credit) { 10.0 }
|
222
|
-
|
223
|
-
it 'deducts the applicable store credit' do
|
224
|
-
expect(subject.order_total_after_store_credit).to eq (order_total - applicable_store_credit)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "order's user does not have any store credits" do
|
229
|
-
let(:applicable_store_credit) { 0.0 }
|
230
|
-
|
231
|
-
it 'returns the order total' do
|
232
|
-
expect(subject.order_total_after_store_credit).to eq order_total
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe '#total_applicable_store_credit' do
|
238
|
-
context 'order is in the confirm state' do
|
239
|
-
before { order.update_attributes(state: 'confirm') }
|
240
|
-
include_examples 'check total store credit from payments'
|
241
|
-
end
|
242
|
-
|
243
|
-
context 'order is completed' do
|
244
|
-
before { order.update_attributes(state: 'complete') }
|
245
|
-
include_examples 'check total store credit from payments'
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'order is in any state other than confirm or complete' do
|
249
|
-
context 'the associated user has store credits' do
|
250
|
-
let(:store_credit) { create(:store_credit) }
|
251
|
-
let(:order) { create(:order, user: store_credit.user) }
|
252
|
-
|
253
|
-
subject { order }
|
254
|
-
|
255
|
-
context 'the store credit is more than the order total' do
|
256
|
-
let(:order_total) { store_credit.amount - 1 }
|
257
|
-
|
258
|
-
before { order.update_attributes(total: order_total) }
|
259
|
-
|
260
|
-
it 'returns the order total' do
|
261
|
-
expect(subject.total_applicable_store_credit).to eq order_total
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
context 'the store credit is less than the order total' do
|
266
|
-
let(:order_total) { store_credit.amount * 10 }
|
267
|
-
|
268
|
-
before { order.update_attributes(total: order_total) }
|
269
|
-
|
270
|
-
it 'returns the store credit amount' do
|
271
|
-
expect(subject.total_applicable_store_credit).to eq store_credit.amount
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context 'the associated user does not have store credits' do
|
277
|
-
let(:order) { create(:order) }
|
278
|
-
|
279
|
-
subject { order }
|
280
|
-
|
281
|
-
it 'returns 0' do
|
282
|
-
expect(subject.total_applicable_store_credit).to be_zero
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context 'the order does not have an associated user' do
|
287
|
-
subject { create(:store_credits_order_without_user) }
|
288
|
-
|
289
|
-
it 'returns 0' do
|
290
|
-
expect(subject.total_applicable_store_credit).to be_zero
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe '#total_applied_store_credit' do
|
297
|
-
context 'with valid payments' do
|
298
|
-
let(:order) { payment.order }
|
299
|
-
let!(:payment) { create(:store_credit_payment) }
|
300
|
-
let!(:second_payment) { create(:store_credit_payment, order: order) }
|
301
|
-
|
302
|
-
subject { order }
|
303
|
-
|
304
|
-
it 'returns the sum of the payment amounts' do
|
305
|
-
expect(subject.total_applied_store_credit).to eq (payment.amount + second_payment.amount)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
context 'without valid payments' do
|
310
|
-
let(:order) { create(:order) }
|
311
|
-
|
312
|
-
subject { order }
|
313
|
-
|
314
|
-
it 'returns 0' do
|
315
|
-
expect(subject.total_applied_store_credit).to be_zero
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
describe '#using_store_credit?' do
|
321
|
-
subject { create(:order) }
|
322
|
-
|
323
|
-
context 'order has store credit payment' do
|
324
|
-
before { allow(subject).to receive(:total_applied_store_credit).and_return(10.0) }
|
325
|
-
it { expect(subject.using_store_credit?).to be true }
|
326
|
-
end
|
327
|
-
|
328
|
-
context 'order has no store credit payments' do
|
329
|
-
before { allow(subject).to receive(:total_applied_store_credit).and_return(0.0) }
|
330
|
-
it { expect(subject.using_store_credit?).to be false }
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
describe '#display_total_applicable_store_credit' do
|
335
|
-
let(:total_applicable_store_credit) { 10.00 }
|
336
|
-
|
337
|
-
subject { create(:order) }
|
338
|
-
|
339
|
-
before do
|
340
|
-
allow(subject).to receive(:total_applicable_store_credit).and_return(total_applicable_store_credit)
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'returns a money instance' do
|
344
|
-
expect(subject.display_total_applicable_store_credit).to be_a(Spree::Money)
|
345
|
-
end
|
346
|
-
|
347
|
-
it 'returns a negative amount' do
|
348
|
-
expect(subject.display_total_applicable_store_credit.money.cents).to eq (total_applicable_store_credit * -100.0)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe '#display_total_applied_store_credit' do
|
353
|
-
let(:total_applied_store_credit) { 10.00 }
|
354
|
-
|
355
|
-
subject { create(:order) }
|
356
|
-
|
357
|
-
before do
|
358
|
-
allow(subject).to receive(:total_applied_store_credit).and_return(total_applied_store_credit)
|
359
|
-
end
|
360
|
-
|
361
|
-
it 'returns a money instance' do
|
362
|
-
expect(subject.display_total_applied_store_credit).to be_a(Spree::Money)
|
363
|
-
end
|
364
|
-
|
365
|
-
it 'returns a negative amount' do
|
366
|
-
expect(subject.display_total_applied_store_credit.money.cents).to eq (total_applied_store_credit * -100.0)
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
describe '#display_order_total_after_store_credit' do
|
371
|
-
let(:order_total_after_store_credit) { 10.00 }
|
372
|
-
|
373
|
-
subject { create(:order) }
|
374
|
-
|
375
|
-
before do
|
376
|
-
allow(subject).to receive(:order_total_after_store_credit).and_return(order_total_after_store_credit)
|
377
|
-
end
|
378
|
-
|
379
|
-
it 'returns a money instance' do
|
380
|
-
expect(subject.display_order_total_after_store_credit).to be_a(Spree::Money)
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'returns the order_total_after_store_credit amount' do
|
384
|
-
expect(subject.display_order_total_after_store_credit.money.cents).to eq (order_total_after_store_credit * 100.0)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
describe '#display_total_available_store_credit' do
|
389
|
-
let(:total_available_store_credit) { 10.00 }
|
390
|
-
|
391
|
-
subject { create(:order) }
|
392
|
-
|
393
|
-
before do
|
394
|
-
allow(subject).to receive(:total_available_store_credit).and_return(total_available_store_credit)
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'returns a money instance' do
|
398
|
-
expect(subject.display_total_available_store_credit).to be_a(Spree::Money)
|
399
|
-
end
|
400
|
-
|
401
|
-
it 'returns the total_available_store_credit amount' do
|
402
|
-
expect(subject.display_total_available_store_credit.money.cents).to eq (total_available_store_credit * 100.0)
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
describe '#display_store_credit_remaining_after_capture' do
|
407
|
-
let(:total_available_store_credit) { 10.00 }
|
408
|
-
let(:total_applicable_store_credit) { 5.00 }
|
409
|
-
|
410
|
-
subject { create(:order) }
|
411
|
-
|
412
|
-
before do
|
413
|
-
allow(subject).to receive(:total_available_store_credit).and_return(total_available_store_credit)
|
414
|
-
allow(subject).to receive(:total_applicable_store_credit).and_return(total_applicable_store_credit)
|
415
|
-
end
|
416
|
-
|
417
|
-
it 'returns a money instance' do
|
418
|
-
expect(subject.display_store_credit_remaining_after_capture).to be_a(Spree::Money)
|
419
|
-
end
|
420
|
-
|
421
|
-
it "returns all of the user's available store credit minus what's applied to the order amount" do
|
422
|
-
amount_remaining = total_available_store_credit - total_applicable_store_credit
|
423
|
-
expect(subject.display_store_credit_remaining_after_capture.money.cents).to eq (amount_remaining * 100.0)
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|