spree_core 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/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,14 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Spree
|
|
4
|
-
describe ReturnsCalculator, type: :model do
|
|
5
|
-
let(:return_item) { build(:return_item) }
|
|
6
|
-
subject { ReturnsCalculator.new }
|
|
7
|
-
|
|
8
|
-
it 'compute_shipment must be overridden' do
|
|
9
|
-
expect {
|
|
10
|
-
subject.compute(return_item)
|
|
11
|
-
}.to raise_error(NotImplementedError)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,742 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'benchmark'
|
|
3
|
-
|
|
4
|
-
describe Spree::Shipment, type: :model do
|
|
5
|
-
let(:order) { mock_model Spree::Order, backordered?: false,
|
|
6
|
-
canceled?: false,
|
|
7
|
-
can_ship?: true,
|
|
8
|
-
currency: 'USD',
|
|
9
|
-
number: 'S12345',
|
|
10
|
-
paid?: false,
|
|
11
|
-
touch_later: false }
|
|
12
|
-
let(:shipping_method) { create(:shipping_method, name: "UPS") }
|
|
13
|
-
let(:shipment) do
|
|
14
|
-
shipment = Spree::Shipment.new(cost: 1, state: 'pending', stock_location: create(:stock_location))
|
|
15
|
-
allow(shipment).to receive_messages order: order
|
|
16
|
-
allow(shipment).to receive_messages shipping_method: shipping_method
|
|
17
|
-
shipment.save
|
|
18
|
-
shipment
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:variant) { mock_model(Spree::Variant) }
|
|
22
|
-
let(:line_item) { mock_model(Spree::LineItem, variant: variant) }
|
|
23
|
-
|
|
24
|
-
def create_shipment(order, stock_location)
|
|
25
|
-
order.shipments.create({ stock_location_id: stock_location.id }).inventory_units.create(
|
|
26
|
-
order_id: order.id,
|
|
27
|
-
variant_id: order.line_items.first.variant_id,
|
|
28
|
-
line_item_id: order.line_items.first.id
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "precision of pre_tax_amount" do
|
|
34
|
-
let(:line_item) { create :line_item, pre_tax_amount: 4.2051 }
|
|
35
|
-
|
|
36
|
-
it "keeps four digits of precision even when reloading" do
|
|
37
|
-
# prevent it from updating pre_tax_amount
|
|
38
|
-
allow_any_instance_of(Spree::LineItem).to receive(:update_tax_charge)
|
|
39
|
-
expect(line_item.reload.pre_tax_amount).to eq(4.2051)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Regression test for #4063
|
|
44
|
-
context "number generation" do
|
|
45
|
-
before do
|
|
46
|
-
allow(order).to receive :update_with_updater!
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "generates a number containing a letter + 11 numbers" do
|
|
50
|
-
expect(shipment.number[0]).to eq("H")
|
|
51
|
-
expect(/\d{11}/.match(shipment.number)).not_to be_nil
|
|
52
|
-
expect(shipment.number.length).to eq(12)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'is backordered if one if its inventory_units is backordered' do
|
|
57
|
-
allow(shipment).to receive_messages(inventory_units: [
|
|
58
|
-
mock_model(Spree::InventoryUnit, backordered?: false),
|
|
59
|
-
mock_model(Spree::InventoryUnit, backordered?: true)
|
|
60
|
-
])
|
|
61
|
-
expect(shipment).to be_backordered
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context '#determine_state' do
|
|
65
|
-
it 'returns canceled if order is canceled?' do
|
|
66
|
-
allow(order).to receive_messages canceled?: true
|
|
67
|
-
expect(shipment.determine_state(order)).to eq 'canceled'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'returns pending unless order.can_ship?' do
|
|
71
|
-
allow(order).to receive_messages can_ship?: false
|
|
72
|
-
expect(shipment.determine_state(order)).to eq 'pending'
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'returns pending if backordered' do
|
|
76
|
-
allow(shipment).to receive_messages inventory_units: [mock_model(Spree::InventoryUnit, backordered?: true)]
|
|
77
|
-
expect(shipment.determine_state(order)).to eq 'pending'
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'returns shipped when already shipped' do
|
|
81
|
-
allow(shipment).to receive_messages state: 'shipped'
|
|
82
|
-
expect(shipment.determine_state(order)).to eq 'shipped'
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'returns pending when unpaid' do
|
|
86
|
-
expect(shipment.determine_state(order)).to eq 'pending'
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'returns ready when paid' do
|
|
90
|
-
allow(order).to receive_messages paid?: true
|
|
91
|
-
expect(shipment.determine_state(order)).to eq 'ready'
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'returns ready when Config.auto_capture_on_dispatch' do
|
|
95
|
-
Spree::Config.auto_capture_on_dispatch = true
|
|
96
|
-
expect(shipment.determine_state(order)).to eq 'ready'
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
context "display_amount" do
|
|
101
|
-
it "retuns a Spree::Money" do
|
|
102
|
-
allow(shipment).to receive(:cost) { 21.22 }
|
|
103
|
-
expect(shipment.display_amount).to eq(Spree::Money.new(21.22))
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context "display_final_price" do
|
|
108
|
-
it "retuns a Spree::Money" do
|
|
109
|
-
allow(shipment).to receive(:final_price) { 21.22 }
|
|
110
|
-
expect(shipment.display_final_price).to eq(Spree::Money.new(21.22))
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "display_item_cost" do
|
|
115
|
-
it "retuns a Spree::Money" do
|
|
116
|
-
allow(shipment).to receive(:item_cost) { 21.22 }
|
|
117
|
-
expect(shipment.display_item_cost).to eq(Spree::Money.new(21.22))
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
context "#item_cost" do
|
|
122
|
-
it 'should equal shipment line items amount with tax' do
|
|
123
|
-
order = create(:order_with_line_item_quantity, line_items_quantity: 2)
|
|
124
|
-
|
|
125
|
-
stock_location = create(:stock_location)
|
|
126
|
-
|
|
127
|
-
create_shipment(order, stock_location)
|
|
128
|
-
create_shipment(order, stock_location)
|
|
129
|
-
|
|
130
|
-
create :tax_adjustment, adjustable: order.line_items.first, order: order
|
|
131
|
-
|
|
132
|
-
expect(order.shipments.first.item_cost).to eql(11.0)
|
|
133
|
-
expect(order.shipments.last.item_cost).to eql(11.0)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'should equal line items final amount with tax' do
|
|
137
|
-
shipment = create(:shipment, order: create(:order_with_line_item_quantity, line_items_quantity: 2))
|
|
138
|
-
create :tax_adjustment, adjustable: shipment.order.line_items.first, order: shipment.order
|
|
139
|
-
expect(shipment.item_cost).to eql(22.0)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "#discounted_cost" do
|
|
144
|
-
shipment = create(:shipment)
|
|
145
|
-
shipment.cost = 10
|
|
146
|
-
shipment.promo_total = -1
|
|
147
|
-
expect(shipment.discounted_cost).to eq(9)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it "#tax_total with included taxes" do
|
|
151
|
-
shipment = Spree::Shipment.new
|
|
152
|
-
expect(shipment.tax_total).to eq(0)
|
|
153
|
-
shipment.included_tax_total = 10
|
|
154
|
-
expect(shipment.tax_total).to eq(10)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "#tax_total with additional taxes" do
|
|
158
|
-
shipment = Spree::Shipment.new
|
|
159
|
-
expect(shipment.tax_total).to eq(0)
|
|
160
|
-
shipment.additional_tax_total = 10
|
|
161
|
-
expect(shipment.tax_total).to eq(10)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "#final_price" do
|
|
165
|
-
shipment = Spree::Shipment.new
|
|
166
|
-
shipment.cost = 10
|
|
167
|
-
shipment.adjustment_total = -2
|
|
168
|
-
shipment.included_tax_total = 1
|
|
169
|
-
expect(shipment.final_price).to eq(8)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context "manifest" do
|
|
173
|
-
let(:order) { Spree::Order.create }
|
|
174
|
-
let(:variant) { create(:variant) }
|
|
175
|
-
let!(:line_item) { order.contents.add variant }
|
|
176
|
-
let!(:shipment) { order.create_proposed_shipments.first }
|
|
177
|
-
|
|
178
|
-
it "returns variant expected" do
|
|
179
|
-
expect(shipment.manifest.first.variant).to eq variant
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
context "variant was removed" do
|
|
183
|
-
before { variant.destroy }
|
|
184
|
-
|
|
185
|
-
it "still returns variant expected" do
|
|
186
|
-
expect(shipment.manifest.first.variant).to eq variant
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
context 'shipping_rates' do
|
|
192
|
-
let(:shipment) { create(:shipment) }
|
|
193
|
-
let(:shipping_method1) { create(:shipping_method) }
|
|
194
|
-
let(:shipping_method2) { create(:shipping_method) }
|
|
195
|
-
let(:shipping_rates) { [
|
|
196
|
-
Spree::ShippingRate.new(shipping_method: shipping_method1, cost: 10.00, selected: true),
|
|
197
|
-
Spree::ShippingRate.new(shipping_method: shipping_method2, cost: 20.00)
|
|
198
|
-
] }
|
|
199
|
-
|
|
200
|
-
it 'returns shipping_method from selected shipping_rate' do
|
|
201
|
-
shipment.shipping_rates.delete_all
|
|
202
|
-
shipment.shipping_rates.create shipping_method: shipping_method1, cost: 10.00, selected: true
|
|
203
|
-
expect(shipment.shipping_method).to eq shipping_method1
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
context 'refresh_rates' do
|
|
207
|
-
let(:mock_estimator) { double('estimator', shipping_rates: shipping_rates) }
|
|
208
|
-
before { allow(shipment).to receive(:can_get_rates?){ true } }
|
|
209
|
-
|
|
210
|
-
it 'should request new rates, and maintain shipping_method selection' do
|
|
211
|
-
expect(Spree::Stock::Estimator).to receive(:new).with(shipment.order).and_return(mock_estimator)
|
|
212
|
-
allow(shipment).to receive_messages(shipping_method: shipping_method2)
|
|
213
|
-
|
|
214
|
-
expect(shipment.refresh_rates).to eq(shipping_rates)
|
|
215
|
-
expect(shipment.reload.selected_shipping_rate.shipping_method_id).to eq(shipping_method2.id)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it 'should handle no shipping_method selection' do
|
|
219
|
-
expect(Spree::Stock::Estimator).to receive(:new).with(shipment.order).and_return(mock_estimator)
|
|
220
|
-
allow(shipment).to receive_messages(shipping_method: nil)
|
|
221
|
-
expect(shipment.refresh_rates).to eq(shipping_rates)
|
|
222
|
-
expect(shipment.reload.selected_shipping_rate).not_to be_nil
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it 'should not refresh if shipment is shipped' do
|
|
226
|
-
expect(Spree::Stock::Estimator).not_to receive(:new)
|
|
227
|
-
shipment.shipping_rates.delete_all
|
|
228
|
-
allow(shipment).to receive_messages(shipped?: true)
|
|
229
|
-
expect(shipment.refresh_rates).to eq([])
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
it "can't get rates without a shipping address" do
|
|
233
|
-
shipment.order.ship_address = nil
|
|
234
|
-
expect(shipment.refresh_rates).to eq([])
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
context 'to_package' do
|
|
238
|
-
let(:inventory_units) do
|
|
239
|
-
[build(:inventory_unit, line_item: line_item, variant: variant, state: 'on_hand'),
|
|
240
|
-
build(:inventory_unit, line_item: line_item, variant: variant, state: 'backordered')]
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
before do
|
|
244
|
-
allow(shipment).to receive(:inventory_units) { inventory_units }
|
|
245
|
-
allow(inventory_units).to receive_message_chain(:includes, :joins).and_return inventory_units
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it 'should use symbols for states when adding contents to package' do
|
|
249
|
-
package = shipment.to_package
|
|
250
|
-
expect(package.on_hand.count).to eq 1
|
|
251
|
-
expect(package.backordered.count).to eq 1
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
context "#update!" do
|
|
258
|
-
shared_examples_for "immutable once shipped" do
|
|
259
|
-
it "should remain in shipped state once shipped" do
|
|
260
|
-
shipment.state = 'shipped'
|
|
261
|
-
expect(shipment).to receive(:update_columns).with(state: 'shipped', updated_at: kind_of(Time))
|
|
262
|
-
shipment.update!(order)
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
shared_examples_for "pending if backordered" do
|
|
267
|
-
it "should have a state of pending if backordered" do
|
|
268
|
-
allow(shipment).to receive_messages(inventory_units: [mock_model(Spree::InventoryUnit, backordered?: true)])
|
|
269
|
-
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
|
|
270
|
-
shipment.update!(order)
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
context "when order cannot ship" do
|
|
275
|
-
before { allow(order).to receive_messages can_ship?: false }
|
|
276
|
-
it "should result in a 'pending' state" do
|
|
277
|
-
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
|
|
278
|
-
shipment.update!(order)
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
context "when order is paid" do
|
|
283
|
-
before { allow(order).to receive_messages paid?: true }
|
|
284
|
-
it "should result in a 'ready' state" do
|
|
285
|
-
expect(shipment).to receive(:update_columns).with(state: 'ready', updated_at: kind_of(Time))
|
|
286
|
-
shipment.update!(order)
|
|
287
|
-
end
|
|
288
|
-
it_should_behave_like 'immutable once shipped'
|
|
289
|
-
it_should_behave_like 'pending if backordered'
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
context "when order has balance due" do
|
|
293
|
-
before { allow(order).to receive_messages paid?: false }
|
|
294
|
-
it "should result in a 'pending' state" do
|
|
295
|
-
shipment.state = 'ready'
|
|
296
|
-
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
|
|
297
|
-
shipment.update!(order)
|
|
298
|
-
end
|
|
299
|
-
it_should_behave_like 'immutable once shipped'
|
|
300
|
-
it_should_behave_like 'pending if backordered'
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
context "when order has a credit owed" do
|
|
304
|
-
before { allow(order).to receive_messages payment_state: 'credit_owed', paid?: true }
|
|
305
|
-
it "should result in a 'ready' state" do
|
|
306
|
-
shipment.state = 'pending'
|
|
307
|
-
expect(shipment).to receive(:update_columns).with(state: 'ready', updated_at: kind_of(Time))
|
|
308
|
-
shipment.update!(order)
|
|
309
|
-
end
|
|
310
|
-
it_should_behave_like 'immutable once shipped'
|
|
311
|
-
it_should_behave_like 'pending if backordered'
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
context "when shipment state changes to shipped" do
|
|
315
|
-
before do
|
|
316
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:send_shipped_email)
|
|
317
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
it "should call after_ship" do
|
|
321
|
-
shipment.state = 'pending'
|
|
322
|
-
expect(shipment).to receive :after_ship
|
|
323
|
-
allow(shipment).to receive_messages determine_state: 'shipped'
|
|
324
|
-
expect(shipment).to receive(:update_columns).with(state: 'shipped', updated_at: kind_of(Time))
|
|
325
|
-
shipment.update!(order)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
context "when using the default shipment handler" do
|
|
329
|
-
it "should call the 'perform' method" do
|
|
330
|
-
shipment.state = 'pending'
|
|
331
|
-
allow(shipment).to receive_messages determine_state: 'shipped'
|
|
332
|
-
expect_any_instance_of(Spree::ShipmentHandler).to receive(:perform)
|
|
333
|
-
shipment.update!(order)
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
context "when using a custom shipment handler" do
|
|
338
|
-
before do
|
|
339
|
-
Spree::ShipmentHandler::UPS = Class.new {
|
|
340
|
-
def initialize(shipment) true end
|
|
341
|
-
def perform() true end
|
|
342
|
-
}
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
it "should call the custom handler's 'perform' method" do
|
|
346
|
-
shipment.state = 'pending'
|
|
347
|
-
allow(shipment).to receive_messages determine_state: 'shipped'
|
|
348
|
-
expect_any_instance_of(Spree::ShipmentHandler::UPS).to receive(:perform)
|
|
349
|
-
shipment.update!(order)
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
after do
|
|
353
|
-
Spree::ShipmentHandler.send(:remove_const, :UPS)
|
|
354
|
-
end
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
# Regression test for #4347
|
|
358
|
-
context "with adjustments" do
|
|
359
|
-
before do
|
|
360
|
-
shipment.adjustments << Spree::Adjustment.create(order: order, label: "Label", amount: 5)
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
it "transitions to shipped" do
|
|
364
|
-
shipment.update_column(:state, "ready")
|
|
365
|
-
expect { shipment.ship! }.not_to raise_error
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
context "when order is completed" do
|
|
372
|
-
after { Spree::Config.set track_inventory_levels: true }
|
|
373
|
-
|
|
374
|
-
before do
|
|
375
|
-
allow(order).to receive_messages completed?: true
|
|
376
|
-
allow(order).to receive_messages canceled?: false
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
context "with inventory tracking" do
|
|
380
|
-
before { Spree::Config.set track_inventory_levels: true }
|
|
381
|
-
|
|
382
|
-
it "should validate with inventory" do
|
|
383
|
-
shipment.inventory_units = [create(:inventory_unit)]
|
|
384
|
-
expect(shipment.valid?).to be true
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
context "without inventory tracking" do
|
|
389
|
-
before { Spree::Config.set track_inventory_levels: false }
|
|
390
|
-
|
|
391
|
-
it "should validate with no inventory" do
|
|
392
|
-
expect(shipment.valid?).to be true
|
|
393
|
-
end
|
|
394
|
-
end
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
context "#cancel" do
|
|
398
|
-
it 'cancels the shipment' do
|
|
399
|
-
allow(shipment.order).to receive(:update_with_updater!)
|
|
400
|
-
|
|
401
|
-
shipment.state = 'pending'
|
|
402
|
-
expect(shipment).to receive(:after_cancel)
|
|
403
|
-
shipment.cancel!
|
|
404
|
-
expect(shipment.state).to eq 'canceled'
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
it 'restocks the items' do
|
|
408
|
-
allow(shipment).to receive_message_chain(inventory_units: [mock_model(Spree::InventoryUnit, state: "on_hand", line_item: line_item, variant: variant)])
|
|
409
|
-
shipment.stock_location = mock_model(Spree::StockLocation)
|
|
410
|
-
expect(shipment.stock_location).to receive(:restock).with(variant, 1, shipment)
|
|
411
|
-
shipment.after_cancel
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
context "with backordered inventory units" do
|
|
415
|
-
let(:order) { create(:order) }
|
|
416
|
-
let(:variant) { create(:variant) }
|
|
417
|
-
let(:other_order) { create(:order) }
|
|
418
|
-
|
|
419
|
-
before do
|
|
420
|
-
order.contents.add variant
|
|
421
|
-
order.create_proposed_shipments
|
|
422
|
-
|
|
423
|
-
other_order.contents.add variant
|
|
424
|
-
other_order.create_proposed_shipments
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
it "doesn't fill backorders when restocking inventory units" do
|
|
428
|
-
shipment = order.shipments.first
|
|
429
|
-
expect(shipment.inventory_units.count).to eq 1
|
|
430
|
-
expect(shipment.inventory_units.first).to be_backordered
|
|
431
|
-
|
|
432
|
-
other_shipment = other_order.shipments.first
|
|
433
|
-
expect(other_shipment.inventory_units.count).to eq 1
|
|
434
|
-
expect(other_shipment.inventory_units.first).to be_backordered
|
|
435
|
-
|
|
436
|
-
expect {
|
|
437
|
-
shipment.cancel!
|
|
438
|
-
}.not_to change { other_shipment.inventory_units.first.state }
|
|
439
|
-
end
|
|
440
|
-
end
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
context "#resume" do
|
|
444
|
-
it 'transitions state to ready if the order is ready' do
|
|
445
|
-
allow(shipment.order).to receive(:update_with_updater!)
|
|
446
|
-
|
|
447
|
-
shipment.state = 'canceled'
|
|
448
|
-
expect(shipment).to receive(:determine_state).and_return('ready')
|
|
449
|
-
expect(shipment).to receive(:after_resume)
|
|
450
|
-
shipment.resume!
|
|
451
|
-
expect(shipment.state).to eq 'ready'
|
|
452
|
-
end
|
|
453
|
-
|
|
454
|
-
it 'transitions state to pending if the order is not ready' do
|
|
455
|
-
allow(shipment.order).to receive(:update_with_updater!)
|
|
456
|
-
|
|
457
|
-
shipment.state = 'canceled'
|
|
458
|
-
expect(shipment).to receive(:determine_state).and_return('pending')
|
|
459
|
-
expect(shipment).to receive(:after_resume)
|
|
460
|
-
shipment.resume!
|
|
461
|
-
# Shipment is pending because order is already paid
|
|
462
|
-
expect(shipment.state).to eq 'pending'
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
it 'unstocks them items' do
|
|
466
|
-
allow(shipment).to receive_message_chain(inventory_units: [mock_model(Spree::InventoryUnit, line_item: line_item, variant: variant)])
|
|
467
|
-
shipment.stock_location = mock_model(Spree::StockLocation)
|
|
468
|
-
expect(shipment.stock_location).to receive(:unstock).with(variant, 1, shipment)
|
|
469
|
-
shipment.after_resume
|
|
470
|
-
end
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
-
context "#ship" do
|
|
474
|
-
context "when the shipment is canceled" do
|
|
475
|
-
let(:shipment_with_inventory_units) { create(:shipment, order: create(:order_with_line_items), state: 'canceled') }
|
|
476
|
-
let(:subject) { shipment_with_inventory_units.ship! }
|
|
477
|
-
before do
|
|
478
|
-
allow(order).to receive(:update_with_updater!)
|
|
479
|
-
allow(shipment_with_inventory_units).to receive_messages(require_inventory: false, update_order: true)
|
|
480
|
-
end
|
|
481
|
-
|
|
482
|
-
it 'unstocks them items' do
|
|
483
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)
|
|
484
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:send_shipped_email)
|
|
485
|
-
|
|
486
|
-
expect(shipment_with_inventory_units.stock_location).to receive(:unstock)
|
|
487
|
-
subject
|
|
488
|
-
end
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
['ready', 'canceled'].each do |state|
|
|
492
|
-
context "from #{state}" do
|
|
493
|
-
before do
|
|
494
|
-
allow(order).to receive(:update_with_updater!)
|
|
495
|
-
allow(shipment).to receive_messages(require_inventory: false, update_order: true, state: state)
|
|
496
|
-
end
|
|
497
|
-
|
|
498
|
-
it "should update shipped_at timestamp" do
|
|
499
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)
|
|
500
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:send_shipped_email)
|
|
501
|
-
|
|
502
|
-
shipment.ship!
|
|
503
|
-
expect(shipment.shipped_at).not_to be_nil
|
|
504
|
-
# Ensure value is persisted
|
|
505
|
-
shipment.reload
|
|
506
|
-
expect(shipment.shipped_at).not_to be_nil
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
it "should send a shipment email" do
|
|
510
|
-
mail_message = double 'Mail::Message'
|
|
511
|
-
shipment_id = nil
|
|
512
|
-
expect(Spree::ShipmentMailer).to receive(:shipped_email) { |*args|
|
|
513
|
-
shipment_id = args[0]
|
|
514
|
-
mail_message
|
|
515
|
-
}
|
|
516
|
-
expect(mail_message).to receive :deliver_later
|
|
517
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)
|
|
518
|
-
|
|
519
|
-
shipment.ship!
|
|
520
|
-
expect(shipment_id).to eq(shipment.id)
|
|
521
|
-
end
|
|
522
|
-
|
|
523
|
-
it "finalizes adjustments" do
|
|
524
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:update_order_shipment_state)
|
|
525
|
-
allow_any_instance_of(Spree::ShipmentHandler).to receive(:send_shipped_email)
|
|
526
|
-
|
|
527
|
-
shipment.adjustments.each do |adjustment|
|
|
528
|
-
expect(adjustment).to receive(:finalize!)
|
|
529
|
-
end
|
|
530
|
-
shipment.ship!
|
|
531
|
-
end
|
|
532
|
-
end
|
|
533
|
-
end
|
|
534
|
-
end
|
|
535
|
-
|
|
536
|
-
context "#ready" do
|
|
537
|
-
context 'with Config.auto_capture_on_dispatch == false' do
|
|
538
|
-
# Regression test for #2040
|
|
539
|
-
it "cannot ready a shipment for an order if the order is unpaid" do
|
|
540
|
-
allow(order).to receive_messages(paid?: false)
|
|
541
|
-
assert !shipment.can_ready?
|
|
542
|
-
end
|
|
543
|
-
end
|
|
544
|
-
|
|
545
|
-
context 'with Config.auto_capture_on_dispatch == true' do
|
|
546
|
-
before do
|
|
547
|
-
Spree::Config[:auto_capture_on_dispatch] = true
|
|
548
|
-
@order = create :completed_order_with_pending_payment
|
|
549
|
-
@shipment = @order.shipments.first
|
|
550
|
-
@shipment.cost = @order.ship_total
|
|
551
|
-
end
|
|
552
|
-
|
|
553
|
-
it "shipments ready for an order if the order is unpaid" do
|
|
554
|
-
expect(@shipment.ready?).to be true
|
|
555
|
-
end
|
|
556
|
-
|
|
557
|
-
it "tells the order to process payment in #after_ship" do
|
|
558
|
-
expect(@shipment).to receive(:process_order_payments)
|
|
559
|
-
@shipment.ship!
|
|
560
|
-
end
|
|
561
|
-
|
|
562
|
-
context "order has pending payments" do
|
|
563
|
-
let(:payment) do
|
|
564
|
-
payment = @order.payments.first
|
|
565
|
-
payment.update_attribute :state, 'pending'
|
|
566
|
-
payment
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
it "can fully capture an authorized payment" do
|
|
570
|
-
payment.update_attribute(:amount, @order.total)
|
|
571
|
-
|
|
572
|
-
expect(payment.amount).to eq payment.uncaptured_amount
|
|
573
|
-
@shipment.ship!
|
|
574
|
-
expect(payment.reload.uncaptured_amount.to_f).to eq 0
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
it "can partially capture an authorized payment" do
|
|
578
|
-
payment.update_attribute(:amount, @order.total + 50)
|
|
579
|
-
|
|
580
|
-
expect(payment.amount).to eq payment.uncaptured_amount
|
|
581
|
-
@shipment.ship!
|
|
582
|
-
expect(payment.captured_amount).to eq @order.total
|
|
583
|
-
expect(payment.captured_amount).to eq payment.amount
|
|
584
|
-
expect(payment.order.payments.pending.first.amount).to eq 50
|
|
585
|
-
end
|
|
586
|
-
end
|
|
587
|
-
end
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
context "updates cost when selected shipping rate is present" do
|
|
591
|
-
let(:shipment) { create(:shipment) }
|
|
592
|
-
|
|
593
|
-
before { allow(shipment).to receive_message_chain :selected_shipping_rate, cost: 5 }
|
|
594
|
-
|
|
595
|
-
it "updates shipment totals" do
|
|
596
|
-
shipment.update_amounts
|
|
597
|
-
expect(shipment.reload.cost).to eq(5)
|
|
598
|
-
end
|
|
599
|
-
|
|
600
|
-
it "factors in additional adjustments to adjustment total" do
|
|
601
|
-
shipment.adjustments.create!(
|
|
602
|
-
order: order,
|
|
603
|
-
label: "Additional",
|
|
604
|
-
amount: 5,
|
|
605
|
-
included: false,
|
|
606
|
-
state: "closed"
|
|
607
|
-
)
|
|
608
|
-
shipment.update_amounts
|
|
609
|
-
expect(shipment.reload.adjustment_total).to eq(5)
|
|
610
|
-
end
|
|
611
|
-
|
|
612
|
-
it "does not factor in included adjustments to adjustment total" do
|
|
613
|
-
shipment.adjustments.create!(
|
|
614
|
-
order: order,
|
|
615
|
-
label: "Included",
|
|
616
|
-
amount: 5,
|
|
617
|
-
included: true,
|
|
618
|
-
state: "closed"
|
|
619
|
-
)
|
|
620
|
-
shipment.update_amounts
|
|
621
|
-
expect(shipment.reload.adjustment_total).to eq(0)
|
|
622
|
-
end
|
|
623
|
-
end
|
|
624
|
-
|
|
625
|
-
context "changes shipping rate via general update" do
|
|
626
|
-
let(:order) do
|
|
627
|
-
Spree::Order.create(
|
|
628
|
-
payment_total: 100, payment_state: 'paid', total: 100, item_total: 100
|
|
629
|
-
)
|
|
630
|
-
end
|
|
631
|
-
|
|
632
|
-
let(:shipment) { Spree::Shipment.create order_id: order.id, stock_location: create(:stock_location) }
|
|
633
|
-
|
|
634
|
-
let(:shipping_rate) do
|
|
635
|
-
Spree::ShippingRate.create shipment_id: shipment.id, cost: 10
|
|
636
|
-
end
|
|
637
|
-
|
|
638
|
-
before do
|
|
639
|
-
shipment.update_attributes_and_order selected_shipping_rate_id: shipping_rate.id
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
it "updates everything around order shipment total and state" do
|
|
643
|
-
expect(shipment.cost.to_f).to eq 10
|
|
644
|
-
expect(shipment.state).to eq 'pending'
|
|
645
|
-
expect(shipment.order.total.to_f).to eq 110
|
|
646
|
-
expect(shipment.order.payment_state).to eq 'balance_due'
|
|
647
|
-
end
|
|
648
|
-
end
|
|
649
|
-
|
|
650
|
-
context "after_save" do
|
|
651
|
-
context "line item changes" do
|
|
652
|
-
before do
|
|
653
|
-
shipment.cost = shipment.cost + 10
|
|
654
|
-
end
|
|
655
|
-
|
|
656
|
-
it "triggers adjustment total recalculation" do
|
|
657
|
-
expect(shipment).to receive(:recalculate_adjustments)
|
|
658
|
-
shipment.save
|
|
659
|
-
end
|
|
660
|
-
|
|
661
|
-
it "does not trigger adjustment recalculation if shipment has shipped" do
|
|
662
|
-
shipment.state = 'shipped'
|
|
663
|
-
expect(shipment).not_to receive(:recalculate_adjustments)
|
|
664
|
-
shipment.save
|
|
665
|
-
end
|
|
666
|
-
end
|
|
667
|
-
|
|
668
|
-
context "line item does not change" do
|
|
669
|
-
it "does not trigger adjustment total recalculation" do
|
|
670
|
-
expect(shipment).not_to receive(:recalculate_adjustments)
|
|
671
|
-
shipment.save
|
|
672
|
-
end
|
|
673
|
-
end
|
|
674
|
-
end
|
|
675
|
-
|
|
676
|
-
context "currency" do
|
|
677
|
-
it "returns the order currency" do
|
|
678
|
-
expect(shipment.currency).to eq(order.currency)
|
|
679
|
-
end
|
|
680
|
-
end
|
|
681
|
-
|
|
682
|
-
context "nil costs" do
|
|
683
|
-
it "sets cost to 0" do
|
|
684
|
-
shipment = Spree::Shipment.new
|
|
685
|
-
shipment.valid?
|
|
686
|
-
expect(shipment.cost).to eq 0
|
|
687
|
-
end
|
|
688
|
-
end
|
|
689
|
-
|
|
690
|
-
context "#tracking_url" do
|
|
691
|
-
it "uses shipping method to determine url" do
|
|
692
|
-
expect(shipping_method).to receive(:build_tracking_url).with('1Z12345').and_return(:some_url)
|
|
693
|
-
shipment.tracking = '1Z12345'
|
|
694
|
-
|
|
695
|
-
expect(shipment.tracking_url).to eq(:some_url)
|
|
696
|
-
end
|
|
697
|
-
end
|
|
698
|
-
|
|
699
|
-
context "set up new inventory units" do
|
|
700
|
-
# let(:line_item) { double(
|
|
701
|
-
let(:variant) { double("Variant", id: 9) }
|
|
702
|
-
|
|
703
|
-
let(:inventory_units) { double }
|
|
704
|
-
|
|
705
|
-
let(:params) do
|
|
706
|
-
{ variant_id: variant.id, state: 'on_hand', order_id: order.id, line_item_id: line_item.id }
|
|
707
|
-
end
|
|
708
|
-
|
|
709
|
-
before { allow(shipment).to receive_messages inventory_units: inventory_units }
|
|
710
|
-
|
|
711
|
-
it "associates variant and order" do
|
|
712
|
-
expect(inventory_units).to receive(:create).with(params)
|
|
713
|
-
unit = shipment.set_up_inventory('on_hand', variant, order, line_item)
|
|
714
|
-
end
|
|
715
|
-
end
|
|
716
|
-
|
|
717
|
-
# Regression test for #3349
|
|
718
|
-
context "#destroy" do
|
|
719
|
-
it "destroys linked shipping_rates" do
|
|
720
|
-
reflection = Spree::Shipment.reflect_on_association(:shipping_rates)
|
|
721
|
-
expect(reflection.options[:dependent]).to be(:delete_all)
|
|
722
|
-
end
|
|
723
|
-
end
|
|
724
|
-
|
|
725
|
-
# Regression test for #4072 (kinda)
|
|
726
|
-
# The need for this was discovered in the research for #4702
|
|
727
|
-
context "state changes" do
|
|
728
|
-
before do
|
|
729
|
-
# Must be stubbed so transition can succeed
|
|
730
|
-
allow(order).to receive_messages paid?: true
|
|
731
|
-
end
|
|
732
|
-
|
|
733
|
-
it "are logged to the database" do
|
|
734
|
-
expect(shipment.state_changes).to be_empty
|
|
735
|
-
expect(shipment.ready!).to be true
|
|
736
|
-
expect(shipment.state_changes.count).to eq(1)
|
|
737
|
-
state_change = shipment.state_changes.first
|
|
738
|
-
expect(state_change.previous_state).to eq('pending')
|
|
739
|
-
expect(state_change.next_state).to eq('ready')
|
|
740
|
-
end
|
|
741
|
-
end
|
|
742
|
-
end
|