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,135 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Regression tests for #2179
|
4
|
-
module Spree
|
5
|
-
describe OrderMerger, type: :model do
|
6
|
-
let(:variant) { create(:variant) }
|
7
|
-
let(:order_1) { Spree::Order.create }
|
8
|
-
let(:order_2) { Spree::Order.create }
|
9
|
-
let(:user) { stub_model(Spree::LegacyUser, email: "spree@example.com") }
|
10
|
-
let(:subject) { Spree::OrderMerger.new(order_1) }
|
11
|
-
|
12
|
-
it "destroys the other order" do
|
13
|
-
subject.merge!(order_2)
|
14
|
-
expect { order_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "persist the merge" do
|
18
|
-
expect(subject).to receive(:persist_merge)
|
19
|
-
subject.merge!(order_2)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "user is provided" do
|
23
|
-
it "assigns user to new order" do
|
24
|
-
subject.merge!(order_2, user)
|
25
|
-
expect(order_1.user).to eq user
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "merging together two orders with line items for the same variant" do
|
30
|
-
before do
|
31
|
-
order_1.contents.add(variant, 1)
|
32
|
-
order_2.contents.add(variant, 1)
|
33
|
-
end
|
34
|
-
|
35
|
-
specify do
|
36
|
-
subject.merge!(order_2, user)
|
37
|
-
expect(order_1.line_items.count).to eq(1)
|
38
|
-
|
39
|
-
line_item = order_1.line_items.first
|
40
|
-
expect(line_item.quantity).to eq(2)
|
41
|
-
expect(line_item.variant_id).to eq(variant.id)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "merging using extension-specific line_item_comparison_hooks" do
|
46
|
-
before do
|
47
|
-
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
48
|
-
allow(Spree::Variant).to receive(:price_modifier_amount).and_return(0.00)
|
49
|
-
end
|
50
|
-
|
51
|
-
after do
|
52
|
-
# reset to avoid test pollution
|
53
|
-
Spree::Order.line_item_comparison_hooks = Set.new
|
54
|
-
end
|
55
|
-
|
56
|
-
context "2 equal line items" do
|
57
|
-
before do
|
58
|
-
@line_item_1 = order_1.contents.add(variant, 1, foos: {})
|
59
|
-
@line_item_2 = order_2.contents.add(variant, 1, foos: {})
|
60
|
-
end
|
61
|
-
|
62
|
-
specify do
|
63
|
-
expect(order_1).to receive(:foos_match).with(@line_item_1, kind_of(Hash)).and_return(true)
|
64
|
-
subject.merge!(order_2)
|
65
|
-
expect(order_1.line_items.count).to eq(1)
|
66
|
-
|
67
|
-
line_item = order_1.line_items.first
|
68
|
-
expect(line_item.quantity).to eq(2)
|
69
|
-
expect(line_item.variant_id).to eq(variant.id)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "2 different line items" do
|
74
|
-
before do
|
75
|
-
allow(order_1).to receive(:foos_match).and_return(false)
|
76
|
-
|
77
|
-
order_1.contents.add(variant, 1, foos: {})
|
78
|
-
order_2.contents.add(variant, 1, foos: { bar: :zoo })
|
79
|
-
end
|
80
|
-
|
81
|
-
specify do
|
82
|
-
subject.merge!(order_2)
|
83
|
-
expect(order_1.line_items.count).to eq(2)
|
84
|
-
|
85
|
-
line_item = order_1.line_items.first
|
86
|
-
expect(line_item.quantity).to eq(1)
|
87
|
-
expect(line_item.variant_id).to eq(variant.id)
|
88
|
-
|
89
|
-
line_item = order_1.line_items.last
|
90
|
-
expect(line_item.quantity).to eq(1)
|
91
|
-
expect(line_item.variant_id).to eq(variant.id)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "merging together two orders with different line items" do
|
97
|
-
let(:variant_2) { create(:variant) }
|
98
|
-
|
99
|
-
before do
|
100
|
-
order_1.contents.add(variant, 1)
|
101
|
-
order_2.contents.add(variant_2, 1)
|
102
|
-
end
|
103
|
-
|
104
|
-
specify do
|
105
|
-
subject.merge!(order_2)
|
106
|
-
line_items = order_1.line_items.reload
|
107
|
-
expect(line_items.count).to eq(2)
|
108
|
-
|
109
|
-
expect(order_1.item_count).to eq 2
|
110
|
-
expect(order_1.item_total).to eq line_items.map(&:amount).sum
|
111
|
-
|
112
|
-
# No guarantee on ordering of line items, so we do this:
|
113
|
-
expect(line_items.pluck(:quantity)).to match_array([1, 1])
|
114
|
-
expect(line_items.pluck(:variant_id)).to match_array([variant.id, variant_2.id])
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "merging together orders with invalid line items" do
|
119
|
-
let(:variant_2) { create(:variant) }
|
120
|
-
|
121
|
-
before do
|
122
|
-
order_1.contents.add(variant, 1)
|
123
|
-
order_2.contents.add(variant_2, 1)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should create errors with invalid line items" do
|
127
|
-
# we cannot use .destroy here as it will be halted by
|
128
|
-
# :ensure_no_line_items callback
|
129
|
-
variant_2.really_destroy!
|
130
|
-
subject.merge!(order_2)
|
131
|
-
expect(order_1.errors.full_messages).not_to be_empty
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,1046 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class FakeCalculator < Spree::Calculator
|
4
|
-
def compute(computable)
|
5
|
-
5
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Spree::Order, type: :model do
|
10
|
-
let(:user) { stub_model(Spree::LegacyUser, email: "spree@example.com") }
|
11
|
-
let(:order) { stub_model(Spree::Order, user: user) }
|
12
|
-
|
13
|
-
before do
|
14
|
-
create(:store)
|
15
|
-
allow(Spree::LegacyUser).to receive_messages(current: mock_model(Spree::LegacyUser, id: 123))
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.scopes' do
|
19
|
-
let!(:user) { FactoryGirl.create(:user) }
|
20
|
-
let!(:completed_order) { FactoryGirl.create(:order, user: user, completed_at: Time.current) }
|
21
|
-
let!(:incompleted_order) { FactoryGirl.create(:order, user: user, completed_at: nil) }
|
22
|
-
|
23
|
-
describe '.complete' do
|
24
|
-
it { expect(Spree::Order.complete).to include completed_order }
|
25
|
-
it { expect(Spree::Order.complete).not_to include incompleted_order }
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '.incomplete' do
|
29
|
-
it { expect(Spree::Order.incomplete).to include incompleted_order }
|
30
|
-
it { expect(Spree::Order.incomplete).not_to include completed_order }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#update_with_updater!' do
|
35
|
-
let(:updater) { Spree::OrderUpdater.new(order) }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow(order).to receive(:updater).and_return(updater)
|
39
|
-
allow(updater).to receive(:update).and_return(true)
|
40
|
-
end
|
41
|
-
|
42
|
-
after { order.update_with_updater! }
|
43
|
-
|
44
|
-
it 'expects to update order with order updater' do
|
45
|
-
expect(updater).to receive(:update).and_return(true)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "#cancel" do
|
50
|
-
let(:order) { create(:completed_order_with_totals) }
|
51
|
-
let!(:payment) do
|
52
|
-
create(
|
53
|
-
:payment,
|
54
|
-
order: order,
|
55
|
-
amount: order.total,
|
56
|
-
state: "completed"
|
57
|
-
)
|
58
|
-
end
|
59
|
-
let(:payment_method) { double }
|
60
|
-
|
61
|
-
it "should mark the payments as void" do
|
62
|
-
allow_any_instance_of(Spree::Shipment).to receive(:refresh_rates).and_return(true)
|
63
|
-
order.cancel
|
64
|
-
order.reload
|
65
|
-
|
66
|
-
expect(order.payments.first).to be_void
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "#canceled_by" do
|
71
|
-
let(:admin_user) { create :admin_user }
|
72
|
-
let(:order) { create :order }
|
73
|
-
|
74
|
-
before do
|
75
|
-
allow(order).to receive(:cancel!)
|
76
|
-
end
|
77
|
-
|
78
|
-
subject { order.canceled_by(admin_user) }
|
79
|
-
|
80
|
-
it 'should cancel the order' do
|
81
|
-
expect(order).to receive(:cancel!)
|
82
|
-
subject
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'should save canceler_id' do
|
86
|
-
subject
|
87
|
-
expect(order.reload.canceler_id).to eq(admin_user.id)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should save canceled_at' do
|
91
|
-
subject
|
92
|
-
expect(order.reload.canceled_at).to_not be_nil
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should have canceler' do
|
96
|
-
subject
|
97
|
-
expect(order.reload.canceler).to eq(admin_user)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context '#create' do
|
102
|
-
let(:order) { Spree::Order.create }
|
103
|
-
|
104
|
-
it 'should assign an order number' do
|
105
|
-
expect(order.number).not_to be_nil
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should create a randomized 35 character token' do
|
109
|
-
expect(order.guest_token.size).to eq(35)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "creates shipments cost" do
|
114
|
-
let(:shipment) { double }
|
115
|
-
|
116
|
-
before { allow(order).to receive_messages shipments: [shipment] }
|
117
|
-
|
118
|
-
it "update and persist totals" do
|
119
|
-
expect(shipment).to receive :update_amounts
|
120
|
-
expect(order.updater).to receive :update_shipment_total
|
121
|
-
expect(order.updater).to receive :persist_totals
|
122
|
-
|
123
|
-
order.set_shipments_cost
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "#finalize!" do
|
128
|
-
let(:order) { Spree::Order.create(email: 'test@example.com') }
|
129
|
-
|
130
|
-
before do
|
131
|
-
order.update_column :state, 'complete'
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should set completed_at" do
|
135
|
-
expect(order).to receive(:touch).with(:completed_at)
|
136
|
-
order.finalize!
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should sell inventory units" do
|
140
|
-
order.shipments.each do |shipment|
|
141
|
-
expect(shipment).to receive(:update!)
|
142
|
-
expect(shipment).to receive(:finalize!)
|
143
|
-
end
|
144
|
-
order.finalize!
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should decrease the stock for each variant in the shipment" do
|
148
|
-
order.shipments.each do |shipment|
|
149
|
-
expect(shipment.stock_location).to receive(:decrease_stock_for_variant)
|
150
|
-
end
|
151
|
-
order.finalize!
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should change the shipment state to ready if order is paid" do
|
155
|
-
Spree::Shipment.create(order: order, stock_location: create(:stock_location))
|
156
|
-
order.shipments.reload
|
157
|
-
|
158
|
-
allow(order).to receive_messages(paid?: true, complete?: true)
|
159
|
-
order.finalize!
|
160
|
-
order.reload # reload so we're sure the changes are persisted
|
161
|
-
expect(order.shipment_state).to eq('ready')
|
162
|
-
end
|
163
|
-
|
164
|
-
after { Spree::Config.set track_inventory_levels: true }
|
165
|
-
it "should not sell inventory units if track_inventory_levels is false" do
|
166
|
-
Spree::Config.set track_inventory_levels: false
|
167
|
-
expect(Spree::InventoryUnit).not_to receive(:sell_units)
|
168
|
-
order.finalize!
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should send an order confirmation email" do
|
172
|
-
mail_message = double "Mail::Message"
|
173
|
-
expect(Spree::OrderMailer).to receive(:confirm_email).with(order.id).and_return mail_message
|
174
|
-
expect(mail_message).to receive :deliver_later
|
175
|
-
order.finalize!
|
176
|
-
end
|
177
|
-
|
178
|
-
it "sets confirmation delivered when finalizing" do
|
179
|
-
expect(order.confirmation_delivered?).to be false
|
180
|
-
order.finalize!
|
181
|
-
expect(order.confirmation_delivered?).to be true
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should not send duplicate confirmation emails" do
|
185
|
-
allow(order).to receive_messages(confirmation_delivered?: true)
|
186
|
-
expect(Spree::OrderMailer).not_to receive(:confirm_email)
|
187
|
-
order.finalize!
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should freeze all adjustments" do
|
191
|
-
allow(Spree::OrderMailer).to receive_message_chain :confirm_email, :deliver_later
|
192
|
-
adjustments = [double]
|
193
|
-
expect(order).to receive(:all_adjustments).and_return(adjustments)
|
194
|
-
adjustments.each do |adj|
|
195
|
-
expect(adj).to receive(:close)
|
196
|
-
end
|
197
|
-
order.finalize!
|
198
|
-
end
|
199
|
-
|
200
|
-
context "order is considered risky" do
|
201
|
-
before do
|
202
|
-
allow(order).to receive_messages is_risky?: true
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should change state to risky" do
|
206
|
-
expect(order).to receive(:considered_risky!)
|
207
|
-
order.finalize!
|
208
|
-
end
|
209
|
-
|
210
|
-
context "and order is approved" do
|
211
|
-
before do
|
212
|
-
allow(order).to receive_messages approved?: true
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should leave order in complete state" do
|
216
|
-
order.finalize!
|
217
|
-
expect(order.state).to eq 'complete'
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context "insufficient_stock_lines" do
|
224
|
-
let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true }
|
225
|
-
|
226
|
-
before { allow(order).to receive_messages(line_items: [line_item]) }
|
227
|
-
|
228
|
-
it "should return line_item that has insufficient stock on hand" do
|
229
|
-
expect(order.insufficient_stock_lines.size).to eq(1)
|
230
|
-
expect(order.insufficient_stock_lines.include?(line_item)).to be true
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "#ensure_line_item_variants_are_not_discontinued" do
|
235
|
-
subject { order.ensure_line_item_variants_are_not_discontinued }
|
236
|
-
|
237
|
-
let(:order) { create :order_with_line_items }
|
238
|
-
|
239
|
-
context 'when variant is destroyed' do
|
240
|
-
before do
|
241
|
-
order.line_items.first.variant.discontinue!
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'should restart checkout flow' do
|
245
|
-
expect(order).to receive(:restart_checkout_flow).once
|
246
|
-
subject
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'should have error message' do
|
250
|
-
subject
|
251
|
-
expect(order.errors[:base]).to include(Spree.t(:discontinued_variants_present))
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'should be false' do
|
255
|
-
expect(subject).to be_falsey
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
context 'when no variants are destroyed' do
|
260
|
-
it 'should not restart checkout' do
|
261
|
-
expect(order).to receive(:restart_checkout_flow).never
|
262
|
-
subject
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'should be true' do
|
266
|
-
expect(subject).to be_truthy
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe '#ensure_line_items_are_in_stock' do
|
272
|
-
subject { order.ensure_line_items_are_in_stock }
|
273
|
-
|
274
|
-
let(:line_item) { create(:line_item, order: order) }
|
275
|
-
|
276
|
-
before do
|
277
|
-
allow(order).to receive(:insufficient_stock_lines).and_return([true])
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'should restart checkout flow' do
|
281
|
-
allow(order).to receive(:restart_checkout_flow)
|
282
|
-
expect(order).to receive(:restart_checkout_flow).once
|
283
|
-
subject
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'should have error message' do
|
287
|
-
subject
|
288
|
-
expect(order.errors[:base]).to include(Spree.t(:insufficient_stock_lines_present))
|
289
|
-
end
|
290
|
-
|
291
|
-
it 'should be false' do
|
292
|
-
allow(order).to receive(:restart_checkout_flow)
|
293
|
-
expect(subject).to be_falsey
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context "empty!" do
|
298
|
-
let(:order) { Spree::Order.create(email: 'test@example.com') }
|
299
|
-
let(:promotion) { create :promotion, code: '10off' }
|
300
|
-
|
301
|
-
before do
|
302
|
-
promotion.orders << order
|
303
|
-
end
|
304
|
-
|
305
|
-
context 'completed order' do
|
306
|
-
before do
|
307
|
-
order.update_columns(state: 'complete', completed_at: Time.current)
|
308
|
-
end
|
309
|
-
|
310
|
-
it "raises an exception" do
|
311
|
-
expect { order.empty! }.to raise_error(RuntimeError, Spree.t(:cannot_empty_completed_order))
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
context 'incomplete order' do
|
316
|
-
before do
|
317
|
-
order.empty!
|
318
|
-
end
|
319
|
-
|
320
|
-
it "clears out line items, adjustments and update totals" do
|
321
|
-
expect(order.line_items.count).to be_zero
|
322
|
-
expect(order.adjustments.count).to be_zero
|
323
|
-
expect(order.shipments.count).to be_zero
|
324
|
-
expect(order.order_promotions.count).to be_zero
|
325
|
-
expect(order.promo_total).to be_zero
|
326
|
-
expect(order.item_total).to be_zero
|
327
|
-
expect(order.empty!).to eq(order)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
context "#display_outstanding_balance" do
|
333
|
-
it "returns the value as a spree money" do
|
334
|
-
allow(order).to receive(:outstanding_balance) { 10.55 }
|
335
|
-
expect(order.display_outstanding_balance).to eq(Spree::Money.new(10.55))
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
context "#display_item_total" do
|
340
|
-
it "returns the value as a spree money" do
|
341
|
-
allow(order).to receive(:item_total) { 10.55 }
|
342
|
-
expect(order.display_item_total).to eq(Spree::Money.new(10.55))
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context "#display_adjustment_total" do
|
347
|
-
it "returns the value as a spree money" do
|
348
|
-
order.adjustment_total = 10.55
|
349
|
-
expect(order.display_adjustment_total).to eq(Spree::Money.new(10.55))
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
context "#display_promo_total" do
|
354
|
-
it "returns the value as a spree money" do
|
355
|
-
order.promo_total = 10.55
|
356
|
-
expect(order.display_promo_total).to eq(Spree::Money.new(10.55))
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
context "#display_total" do
|
361
|
-
it "returns the value as a spree money" do
|
362
|
-
order.total = 10.55
|
363
|
-
expect(order.display_total).to eq(Spree::Money.new(10.55))
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
context "#currency" do
|
368
|
-
context "when object currency is ABC" do
|
369
|
-
before { order.currency = "ABC" }
|
370
|
-
|
371
|
-
it "returns the currency from the object" do
|
372
|
-
expect(order.currency).to eq("ABC")
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
context "when object currency is nil" do
|
377
|
-
before { order.currency = nil }
|
378
|
-
|
379
|
-
it "returns the globally configured currency" do
|
380
|
-
expect(order.currency).to eq("USD")
|
381
|
-
end
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
context "#confirmation_required?" do
|
386
|
-
|
387
|
-
# Regression test for #4117
|
388
|
-
it "is required if the state is currently 'confirm'" do
|
389
|
-
order = Spree::Order.new
|
390
|
-
assert !order.confirmation_required?
|
391
|
-
order.state = 'confirm'
|
392
|
-
assert order.confirmation_required?
|
393
|
-
end
|
394
|
-
|
395
|
-
context 'Spree::Config[:always_include_confirm_step] == true' do
|
396
|
-
|
397
|
-
before do
|
398
|
-
Spree::Config[:always_include_confirm_step] = true
|
399
|
-
end
|
400
|
-
|
401
|
-
it "returns true if payments empty" do
|
402
|
-
order = Spree::Order.new
|
403
|
-
assert order.confirmation_required?
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
context 'Spree::Config[:always_include_confirm_step] == false' do
|
408
|
-
|
409
|
-
it "returns false if payments empty and Spree::Config[:always_include_confirm_step] == false" do
|
410
|
-
order = Spree::Order.new
|
411
|
-
assert !order.confirmation_required?
|
412
|
-
end
|
413
|
-
|
414
|
-
it "does not bomb out when an order has an unpersisted payment" do
|
415
|
-
order = Spree::Order.new
|
416
|
-
order.payments.build
|
417
|
-
assert !order.confirmation_required?
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
|
423
|
-
context "add_update_hook" do
|
424
|
-
before do
|
425
|
-
Spree::Order.class_eval do
|
426
|
-
register_update_hook :add_awesome_sauce
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
after do
|
431
|
-
Spree::Order.update_hooks = Set.new
|
432
|
-
end
|
433
|
-
|
434
|
-
it "calls hook during update" do
|
435
|
-
order = create(:order)
|
436
|
-
expect(order).to receive(:add_awesome_sauce)
|
437
|
-
order.update_with_updater!
|
438
|
-
end
|
439
|
-
|
440
|
-
it "calls hook during finalize" do
|
441
|
-
order = create(:order)
|
442
|
-
expect(order).to receive(:add_awesome_sauce)
|
443
|
-
order.finalize!
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
describe "#tax_address" do
|
448
|
-
before { Spree::Config[:tax_using_ship_address] = tax_using_ship_address }
|
449
|
-
subject { order.tax_address }
|
450
|
-
|
451
|
-
context "when tax_using_ship_address is true" do
|
452
|
-
let(:tax_using_ship_address) { true }
|
453
|
-
|
454
|
-
it 'returns ship_address' do
|
455
|
-
expect(subject).to eq(order.ship_address)
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
context "when tax_using_ship_address is not true" do
|
460
|
-
let(:tax_using_ship_address) { false }
|
461
|
-
|
462
|
-
it "returns bill_address" do
|
463
|
-
expect(subject).to eq(order.bill_address)
|
464
|
-
end
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
describe "#restart_checkout_flow" do
|
469
|
-
it "updates the state column to the first checkout_steps value" do
|
470
|
-
order = create(:order_with_totals, state: "delivery")
|
471
|
-
expect(order.checkout_steps).to eql ["address", "delivery", "complete"]
|
472
|
-
expect{ order.restart_checkout_flow }.to change{order.state}.from("delivery").to("address")
|
473
|
-
end
|
474
|
-
|
475
|
-
context "without line items" do
|
476
|
-
it "updates the state column to cart" do
|
477
|
-
order = create(:order, state: "delivery")
|
478
|
-
expect{ order.restart_checkout_flow }.to change{order.state}.from("delivery").to("cart")
|
479
|
-
end
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
# Regression tests for #4072
|
484
|
-
context "#state_changed" do
|
485
|
-
let(:order) { FactoryGirl.create(:order) }
|
486
|
-
|
487
|
-
it "logs state changes" do
|
488
|
-
order.update_column(:payment_state, 'balance_due')
|
489
|
-
order.payment_state = 'paid'
|
490
|
-
expect(order.state_changes).to be_empty
|
491
|
-
order.state_changed('payment')
|
492
|
-
state_change = order.state_changes.find_by(name: 'payment')
|
493
|
-
expect(state_change.previous_state).to eq('balance_due')
|
494
|
-
expect(state_change.next_state).to eq('paid')
|
495
|
-
end
|
496
|
-
|
497
|
-
it "does not do anything if state does not change" do
|
498
|
-
order.update_column(:payment_state, 'balance_due')
|
499
|
-
expect(order.state_changes).to be_empty
|
500
|
-
order.state_changed('payment')
|
501
|
-
expect(order.state_changes).to be_empty
|
502
|
-
end
|
503
|
-
end
|
504
|
-
|
505
|
-
# Regression test for #4199
|
506
|
-
context "#available_payment_methods" do
|
507
|
-
it "includes frontend payment methods" do
|
508
|
-
payment_method = Spree::PaymentMethod.create!({
|
509
|
-
name: "Fake",
|
510
|
-
active: true,
|
511
|
-
display_on: "front_end",
|
512
|
-
})
|
513
|
-
expect(order.available_payment_methods).to include(payment_method)
|
514
|
-
end
|
515
|
-
|
516
|
-
it "includes 'both' payment methods" do
|
517
|
-
payment_method = Spree::PaymentMethod.create!({
|
518
|
-
name: "Fake",
|
519
|
-
active: true,
|
520
|
-
display_on: "both",
|
521
|
-
})
|
522
|
-
expect(order.available_payment_methods).to include(payment_method)
|
523
|
-
end
|
524
|
-
|
525
|
-
it "does not include a payment method twice if display_on is blank" do
|
526
|
-
payment_method = Spree::PaymentMethod.create!({
|
527
|
-
name: "Fake",
|
528
|
-
active: true,
|
529
|
-
display_on: "both",
|
530
|
-
})
|
531
|
-
expect(order.available_payment_methods.count).to eq(1)
|
532
|
-
expect(order.available_payment_methods).to include(payment_method)
|
533
|
-
end
|
534
|
-
|
535
|
-
let(:ok_method) { double :payment_method, available_for_order?: true }
|
536
|
-
let(:no_method) { double :payment_method, available_for_order?: false }
|
537
|
-
let(:methods) { [ok_method, no_method] }
|
538
|
-
|
539
|
-
it "does not include a payment method that is not suitable for this order" do
|
540
|
-
allow(Spree::PaymentMethod).to receive(:available_on_front_end).and_return(methods)
|
541
|
-
expect(order.available_payment_methods).to match_array [ok_method]
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
context "#apply_free_shipping_promotions" do
|
546
|
-
it "calls out to the FreeShipping promotion handler" do
|
547
|
-
shipment = double('Shipment')
|
548
|
-
allow(order).to receive_messages shipments: [shipment]
|
549
|
-
expect(Spree::PromotionHandler::FreeShipping).to receive(:new).and_return(handler = double)
|
550
|
-
expect(handler).to receive(:activate)
|
551
|
-
|
552
|
-
expect(Spree::Adjustable::AdjustmentsUpdater).to receive(:update).with(shipment)
|
553
|
-
|
554
|
-
expect(order.updater).to receive(:update_shipment_total)
|
555
|
-
expect(order.updater).to receive(:persist_totals)
|
556
|
-
order.apply_free_shipping_promotions
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
|
561
|
-
context "#products" do
|
562
|
-
before :each do
|
563
|
-
@variant1 = mock_model(Spree::Variant, product: "product1")
|
564
|
-
@variant2 = mock_model(Spree::Variant, product: "product2")
|
565
|
-
@line_items = [mock_model(Spree::LineItem, product: "product1", variant: @variant1, variant_id: @variant1.id, quantity: 1),
|
566
|
-
mock_model(Spree::LineItem, product: "product2", variant: @variant2, variant_id: @variant2.id, quantity: 2)]
|
567
|
-
allow(order).to receive_messages(line_items: @line_items)
|
568
|
-
end
|
569
|
-
|
570
|
-
it "gets the quantity of a given variant" do
|
571
|
-
expect(order.quantity_of(@variant1)).to eq(1)
|
572
|
-
|
573
|
-
@variant3 = mock_model(Spree::Variant, product: "product3")
|
574
|
-
expect(order.quantity_of(@variant3)).to eq(0)
|
575
|
-
end
|
576
|
-
|
577
|
-
it "can find a line item matching a given variant" do
|
578
|
-
expect(order.find_line_item_by_variant(@variant1)).not_to be_nil
|
579
|
-
expect(order.find_line_item_by_variant(mock_model(Spree::Variant))).to be_nil
|
580
|
-
end
|
581
|
-
|
582
|
-
context "match line item with options" do
|
583
|
-
before do
|
584
|
-
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
585
|
-
end
|
586
|
-
|
587
|
-
after do
|
588
|
-
# reset to avoid test pollution
|
589
|
-
Spree::Order.line_item_comparison_hooks = Set.new
|
590
|
-
end
|
591
|
-
|
592
|
-
it "matches line item when options match" do
|
593
|
-
allow(order).to receive(:foos_match).and_return(true)
|
594
|
-
expect(order.line_item_options_match(@line_items.first, {foos: {bar: :zoo}})).to be true
|
595
|
-
end
|
596
|
-
|
597
|
-
it "does not match line item without options" do
|
598
|
-
allow(order).to receive(:foos_match).and_return(false)
|
599
|
-
expect(order.line_item_options_match(@line_items.first, {})).to be false
|
600
|
-
end
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
describe "#associate_user!" do
|
605
|
-
let(:user) { FactoryGirl.create(:user_with_addreses) }
|
606
|
-
let(:email) { user.email }
|
607
|
-
let(:created_by) { user }
|
608
|
-
let(:bill_address) { user.bill_address }
|
609
|
-
let(:ship_address) { user.ship_address }
|
610
|
-
let(:override_email) { true }
|
611
|
-
|
612
|
-
let(:order) { FactoryGirl.build(:order, order_attributes) }
|
613
|
-
|
614
|
-
let(:order_attributes) do
|
615
|
-
{
|
616
|
-
user: nil,
|
617
|
-
email: nil,
|
618
|
-
created_by: nil,
|
619
|
-
bill_address: nil,
|
620
|
-
ship_address: nil
|
621
|
-
}
|
622
|
-
end
|
623
|
-
|
624
|
-
def assert_expected_order_state
|
625
|
-
expect(order.user).to eql(user)
|
626
|
-
expect(order.user_id).to eql(user.id)
|
627
|
-
|
628
|
-
expect(order.email).to eql(email)
|
629
|
-
|
630
|
-
expect(order.created_by).to eql(created_by)
|
631
|
-
expect(order.created_by_id).to eql(created_by.id)
|
632
|
-
|
633
|
-
expect(order.bill_address).to eql(bill_address)
|
634
|
-
expect(order.bill_address_id).to eql(bill_address.id)
|
635
|
-
|
636
|
-
expect(order.ship_address).to eql(ship_address)
|
637
|
-
expect(order.ship_address_id).to eql(ship_address.id)
|
638
|
-
end
|
639
|
-
|
640
|
-
shared_examples_for "#associate_user!" do |persisted = false|
|
641
|
-
it "associates a user to an order" do
|
642
|
-
order.associate_user!(user, override_email)
|
643
|
-
assert_expected_order_state
|
644
|
-
end
|
645
|
-
|
646
|
-
unless persisted
|
647
|
-
it "does not persist the order" do
|
648
|
-
expect { order.associate_user!(user) }
|
649
|
-
.to_not change(order, :persisted?)
|
650
|
-
.from(false)
|
651
|
-
end
|
652
|
-
end
|
653
|
-
end
|
654
|
-
|
655
|
-
context "when email is set" do
|
656
|
-
let(:order_attributes) { super().merge(email: 'test@example.com') }
|
657
|
-
|
658
|
-
context "when email should be overridden" do
|
659
|
-
it_should_behave_like "#associate_user!"
|
660
|
-
end
|
661
|
-
|
662
|
-
context "when email should not be overridden" do
|
663
|
-
let(:override_email) { false }
|
664
|
-
let(:email) { 'test@example.com' }
|
665
|
-
|
666
|
-
it_should_behave_like "#associate_user!"
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
context "when created_by is set" do
|
671
|
-
let(:order_attributes) { super().merge(created_by: created_by) }
|
672
|
-
let(:created_by) { create(:user_with_addreses) }
|
673
|
-
|
674
|
-
it_should_behave_like "#associate_user!"
|
675
|
-
end
|
676
|
-
|
677
|
-
context "when bill_address is set" do
|
678
|
-
let(:order_attributes) { super().merge(bill_address: bill_address) }
|
679
|
-
let(:bill_address) { FactoryGirl.build(:address) }
|
680
|
-
|
681
|
-
it_should_behave_like "#associate_user!"
|
682
|
-
end
|
683
|
-
|
684
|
-
context "when ship_address is set" do
|
685
|
-
let(:order_attributes) { super().merge(ship_address: ship_address) }
|
686
|
-
let(:ship_address) { FactoryGirl.build(:address) }
|
687
|
-
|
688
|
-
it_should_behave_like "#associate_user!"
|
689
|
-
end
|
690
|
-
|
691
|
-
context "when the user is not persisted" do
|
692
|
-
let(:user) { FactoryGirl.build(:user_with_addreses) }
|
693
|
-
|
694
|
-
it "does not persist the user" do
|
695
|
-
expect { order.associate_user!(user) }
|
696
|
-
.to_not change(user, :persisted?)
|
697
|
-
.from(false)
|
698
|
-
end
|
699
|
-
|
700
|
-
it_should_behave_like "#associate_user!"
|
701
|
-
end
|
702
|
-
|
703
|
-
context "when the order is persisted" do
|
704
|
-
let(:order) { FactoryGirl.create(:order, order_attributes) }
|
705
|
-
|
706
|
-
it "associates a user to a persisted order" do
|
707
|
-
order.associate_user!(user)
|
708
|
-
order.reload
|
709
|
-
assert_expected_order_state
|
710
|
-
end
|
711
|
-
|
712
|
-
it "does not persist other changes to the order" do
|
713
|
-
order.state = 'complete'
|
714
|
-
order.associate_user!(user)
|
715
|
-
order.reload
|
716
|
-
expect(order.state).to eql('cart')
|
717
|
-
end
|
718
|
-
|
719
|
-
it "does not change any other orders" do
|
720
|
-
other = FactoryGirl.create(:order)
|
721
|
-
order.associate_user!(user)
|
722
|
-
expect(other.reload.user).to_not eql(user)
|
723
|
-
end
|
724
|
-
|
725
|
-
it "is not affected by scoping" do
|
726
|
-
order.class.where.not(id: order).scoping do
|
727
|
-
order.associate_user!(user)
|
728
|
-
end
|
729
|
-
order.reload
|
730
|
-
assert_expected_order_state
|
731
|
-
end
|
732
|
-
|
733
|
-
it_should_behave_like "#associate_user!", true
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
context "#can_ship?" do
|
738
|
-
let(:order) { Spree::Order.create }
|
739
|
-
|
740
|
-
it "should be true for order in the 'complete' state" do
|
741
|
-
allow(order).to receive_messages(complete?: true)
|
742
|
-
expect(order.can_ship?).to be true
|
743
|
-
end
|
744
|
-
|
745
|
-
it "should be true for order in the 'resumed' state" do
|
746
|
-
allow(order).to receive_messages(resumed?: true)
|
747
|
-
expect(order.can_ship?).to be true
|
748
|
-
end
|
749
|
-
|
750
|
-
it "should be true for an order in the 'awaiting return' state" do
|
751
|
-
allow(order).to receive_messages(awaiting_return?: true)
|
752
|
-
expect(order.can_ship?).to be true
|
753
|
-
end
|
754
|
-
|
755
|
-
it "should be true for an order in the 'returned' state" do
|
756
|
-
allow(order).to receive_messages(returned?: true)
|
757
|
-
expect(order.can_ship?).to be true
|
758
|
-
end
|
759
|
-
|
760
|
-
it "should be false if the order is neither in the 'complete' nor 'resumed' state" do
|
761
|
-
allow(order).to receive_messages(resumed?: false, complete?: false)
|
762
|
-
expect(order.can_ship?).to be false
|
763
|
-
end
|
764
|
-
end
|
765
|
-
|
766
|
-
context "#completed?" do
|
767
|
-
it "should indicate if order is completed" do
|
768
|
-
order.completed_at = nil
|
769
|
-
expect(order.completed?).to be false
|
770
|
-
|
771
|
-
order.completed_at = Time.current
|
772
|
-
expect(order.completed?).to be true
|
773
|
-
end
|
774
|
-
end
|
775
|
-
|
776
|
-
context "#allow_checkout?" do
|
777
|
-
it "should be true if there are line_items in the order" do
|
778
|
-
allow(order).to receive_message_chain(:line_items, count: 1)
|
779
|
-
expect(order.checkout_allowed?).to be true
|
780
|
-
end
|
781
|
-
it "should be false if there are no line_items in the order" do
|
782
|
-
allow(order).to receive_message_chain(:line_items, count: 0)
|
783
|
-
expect(order.checkout_allowed?).to be false
|
784
|
-
end
|
785
|
-
end
|
786
|
-
|
787
|
-
context "#amount" do
|
788
|
-
before do
|
789
|
-
@order = create(:order, user: user)
|
790
|
-
@order.line_items = [create(:line_item, price: 1.0, quantity: 2),
|
791
|
-
create(:line_item, price: 1.0, quantity: 1)]
|
792
|
-
end
|
793
|
-
it "should return the correct lum sum of items" do
|
794
|
-
expect(@order.amount).to eq(3.0)
|
795
|
-
end
|
796
|
-
end
|
797
|
-
|
798
|
-
context "#backordered?" do
|
799
|
-
it 'is backordered if one of the shipments is backordered' do
|
800
|
-
allow(order).to receive_messages(shipments: [mock_model(Spree::Shipment, backordered?: false),
|
801
|
-
mock_model(Spree::Shipment, backordered?: true)])
|
802
|
-
expect(order).to be_backordered
|
803
|
-
end
|
804
|
-
end
|
805
|
-
|
806
|
-
context "#can_cancel?" do
|
807
|
-
it "should be false for completed order in the canceled state" do
|
808
|
-
order.state = 'canceled'
|
809
|
-
order.shipment_state = 'ready'
|
810
|
-
order.completed_at = Time.current
|
811
|
-
expect(order.can_cancel?).to be false
|
812
|
-
end
|
813
|
-
|
814
|
-
it "should be true for completed order with no shipment" do
|
815
|
-
order.state = 'complete'
|
816
|
-
order.shipment_state = nil
|
817
|
-
order.completed_at = Time.current
|
818
|
-
expect(order.can_cancel?).to be true
|
819
|
-
end
|
820
|
-
end
|
821
|
-
|
822
|
-
context "#tax_total" do
|
823
|
-
it "adds included tax and additional tax" do
|
824
|
-
allow(order).to receive_messages(additional_tax_total: 10, included_tax_total: 20)
|
825
|
-
|
826
|
-
expect(order.tax_total).to eq 30
|
827
|
-
end
|
828
|
-
end
|
829
|
-
|
830
|
-
# Regression test for #4923
|
831
|
-
context "locking" do
|
832
|
-
let(:order) { Spree::Order.create } # need a persisted in order to test locking
|
833
|
-
|
834
|
-
it 'can lock' do
|
835
|
-
expect { order.with_lock {} }.to_not raise_error
|
836
|
-
end
|
837
|
-
end
|
838
|
-
|
839
|
-
describe "#pre_tax_item_amount" do
|
840
|
-
it "sums all of the line items' pre tax amounts" do
|
841
|
-
subject.line_items = [
|
842
|
-
Spree::LineItem.new(price: 10, quantity: 2, pre_tax_amount: 5.0),
|
843
|
-
Spree::LineItem.new(price: 30, quantity: 1, pre_tax_amount: 14.0),
|
844
|
-
]
|
845
|
-
|
846
|
-
expect(subject.pre_tax_item_amount).to eq 19.0
|
847
|
-
end
|
848
|
-
end
|
849
|
-
|
850
|
-
describe '#quantity' do
|
851
|
-
# Uses a persisted record, as the quantity is retrieved via a DB count
|
852
|
-
let(:order) { create :order_with_line_items, line_items_count: 3 }
|
853
|
-
|
854
|
-
it 'sums the quantity of all line items' do
|
855
|
-
expect(order.quantity).to eq 3
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
describe '#has_non_reimbursement_related_refunds?' do
|
860
|
-
subject do
|
861
|
-
order.has_non_reimbursement_related_refunds?
|
862
|
-
end
|
863
|
-
|
864
|
-
context 'no refunds exist' do
|
865
|
-
it { is_expected.to eq false }
|
866
|
-
end
|
867
|
-
|
868
|
-
context 'a non-reimbursement related refund exists' do
|
869
|
-
let(:order) { refund.payment.order }
|
870
|
-
let(:refund) { create(:refund, reimbursement_id: nil, amount: 5) }
|
871
|
-
|
872
|
-
it { is_expected.to eq true }
|
873
|
-
end
|
874
|
-
|
875
|
-
context 'an old-style refund exists' do
|
876
|
-
let(:order) { create(:order_ready_to_ship) }
|
877
|
-
let(:payment) { order.payments.first.tap { |p| allow(p).to receive_messages(profiles_supported: false) } }
|
878
|
-
let!(:refund_payment) {
|
879
|
-
build(:payment, amount: -1, order: order, state: 'completed', source: payment).tap do |p|
|
880
|
-
allow(p).to receive_messages(profiles_supported?: false)
|
881
|
-
p.save!
|
882
|
-
end
|
883
|
-
}
|
884
|
-
|
885
|
-
it { is_expected.to eq true }
|
886
|
-
end
|
887
|
-
|
888
|
-
context 'a reimbursement related refund exists' do
|
889
|
-
let(:order) { refund.payment.order }
|
890
|
-
let(:refund) { create(:refund, reimbursement_id: 123, amount: 5)}
|
891
|
-
|
892
|
-
it { is_expected.to eq false }
|
893
|
-
end
|
894
|
-
end
|
895
|
-
|
896
|
-
describe "#create_proposed_shipments" do
|
897
|
-
context 'has unassociated inventory units' do
|
898
|
-
let!(:inventory_unit) { create(:inventory_unit, order: subject) }
|
899
|
-
|
900
|
-
before(:each) do
|
901
|
-
inventory_unit.update_column(:shipment_id, nil)
|
902
|
-
end
|
903
|
-
|
904
|
-
context 'when shipped' do
|
905
|
-
before(:each) do
|
906
|
-
inventory_unit.update_column(:state, 'shipped')
|
907
|
-
end
|
908
|
-
|
909
|
-
it 'does not delete inventory_unit' do
|
910
|
-
subject.create_proposed_shipments
|
911
|
-
expect(inventory_unit.reload).to eq inventory_unit
|
912
|
-
end
|
913
|
-
end
|
914
|
-
|
915
|
-
context 'when returned' do
|
916
|
-
before(:each) do
|
917
|
-
inventory_unit.update_column(:state, 'returned')
|
918
|
-
end
|
919
|
-
|
920
|
-
it 'does not delete inventory_unit' do
|
921
|
-
subject.create_proposed_shipments
|
922
|
-
expect(inventory_unit.reload).to eq inventory_unit
|
923
|
-
end
|
924
|
-
end
|
925
|
-
|
926
|
-
context 'when on_hand' do
|
927
|
-
before(:each) do
|
928
|
-
inventory_unit.update_column(:state, 'on_hand')
|
929
|
-
end
|
930
|
-
|
931
|
-
it 'deletes inventory_unit' do
|
932
|
-
subject.create_proposed_shipments
|
933
|
-
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
934
|
-
end
|
935
|
-
end
|
936
|
-
|
937
|
-
context 'when backordered' do
|
938
|
-
before(:each) do
|
939
|
-
inventory_unit.update_column(:state, 'backordered')
|
940
|
-
end
|
941
|
-
|
942
|
-
it 'deletes inventory_unit' do
|
943
|
-
subject.create_proposed_shipments
|
944
|
-
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
945
|
-
end
|
946
|
-
end
|
947
|
-
end
|
948
|
-
|
949
|
-
it "assigns the coordinator returned shipments to its shipments" do
|
950
|
-
shipment = build(:shipment)
|
951
|
-
allow_any_instance_of(Spree::Stock::Coordinator).to receive(:shipments).and_return([shipment])
|
952
|
-
subject.create_proposed_shipments
|
953
|
-
expect(subject.shipments).to eq [shipment]
|
954
|
-
end
|
955
|
-
end
|
956
|
-
|
957
|
-
describe "#all_inventory_units_returned?" do
|
958
|
-
let(:order) { create(:order_with_line_items, line_items_count: 3) }
|
959
|
-
|
960
|
-
subject { order.all_inventory_units_returned? }
|
961
|
-
|
962
|
-
context "all inventory units are returned" do
|
963
|
-
before { order.inventory_units.update_all(state: 'returned') }
|
964
|
-
|
965
|
-
it "is true" do
|
966
|
-
expect(subject).to eq true
|
967
|
-
end
|
968
|
-
end
|
969
|
-
|
970
|
-
context "some inventory units are returned" do
|
971
|
-
before do
|
972
|
-
order.inventory_units.first.update_attribute(:state, 'returned')
|
973
|
-
end
|
974
|
-
|
975
|
-
it "is false" do
|
976
|
-
expect(subject).to eq false
|
977
|
-
end
|
978
|
-
end
|
979
|
-
|
980
|
-
context "no inventory units are returned" do
|
981
|
-
it "is false" do
|
982
|
-
expect(subject).to eq false
|
983
|
-
end
|
984
|
-
end
|
985
|
-
end
|
986
|
-
|
987
|
-
describe "#fully_discounted?" do
|
988
|
-
let(:line_item) { Spree::LineItem.new(price: 10, quantity: 1) }
|
989
|
-
let(:shipment) { Spree::Shipment.new(cost: 10) }
|
990
|
-
let(:payment) { Spree::Payment.new(amount: 10) }
|
991
|
-
|
992
|
-
before do
|
993
|
-
allow(order).to receive(:line_items) { [line_item] }
|
994
|
-
allow(order).to receive(:shipments) { [shipment] }
|
995
|
-
allow(order).to receive(:payments) { [payment] }
|
996
|
-
end
|
997
|
-
|
998
|
-
context "the order had no inventory-related cost" do
|
999
|
-
before do
|
1000
|
-
# discount the cost of the line items
|
1001
|
-
allow(order).to receive(:adjustment_total) { -5 }
|
1002
|
-
allow(line_item).to receive(:adjustment_total) { -5 }
|
1003
|
-
|
1004
|
-
# but leave some shipment payment amount
|
1005
|
-
allow(shipment).to receive(:adjustment_total) { 0 }
|
1006
|
-
end
|
1007
|
-
|
1008
|
-
it { expect(order.fully_discounted?).to eq true }
|
1009
|
-
|
1010
|
-
end
|
1011
|
-
|
1012
|
-
context "the order had inventory-related cost" do
|
1013
|
-
before do
|
1014
|
-
# partially discount the cost of the line item
|
1015
|
-
allow(order).to receive(:adjustment_total) { 0 }
|
1016
|
-
allow(line_item).to receive(:adjustment_total) { -5 }
|
1017
|
-
|
1018
|
-
# and partially discount the cost of the shipment so the total
|
1019
|
-
# discount matches the item total for test completeness
|
1020
|
-
allow(shipment).to receive(:adjustment_total) { -5 }
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
it { expect(order.fully_discounted?).to eq false }
|
1024
|
-
end
|
1025
|
-
end
|
1026
|
-
|
1027
|
-
describe 'order transit to returned state from resumed state' do
|
1028
|
-
let!(:resumed_order) { create(:order_with_line_items, line_items_count: 3, state: :resumed) }
|
1029
|
-
|
1030
|
-
context 'when all inventory_units returned' do
|
1031
|
-
before do
|
1032
|
-
resumed_order.inventory_units.update_all(state: 'returned')
|
1033
|
-
resumed_order.return
|
1034
|
-
end
|
1035
|
-
it { expect(resumed_order).to be_returned }
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
context 'when some inventory_units returned' do
|
1039
|
-
before do
|
1040
|
-
resumed_order.inventory_units.first.update_attribute(:state, 'returned')
|
1041
|
-
resumed_order.return
|
1042
|
-
end
|
1043
|
-
it { expect(resumed_order).to be_resumed }
|
1044
|
-
end
|
1045
|
-
end
|
1046
|
-
end
|