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,432 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Spree::StockItem, type: :model do
|
|
4
|
-
let(:stock_location) { create(:stock_location_with_items) }
|
|
5
|
-
|
|
6
|
-
subject { stock_location.stock_items.order(:id).first }
|
|
7
|
-
|
|
8
|
-
it { is_expected.to delegate_method(:product).to(:variant) }
|
|
9
|
-
|
|
10
|
-
it 'maintains the count on hand for a variant' do
|
|
11
|
-
expect(subject.count_on_hand).to eq 10
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "can return the stock item's variant's name" do
|
|
15
|
-
expect(subject.variant_name).to eq(subject.variant.name)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "available to be included in shipment" do
|
|
19
|
-
context "has stock" do
|
|
20
|
-
it { expect(subject).to be_available }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context "backorderable" do
|
|
24
|
-
before { subject.backorderable = true }
|
|
25
|
-
it { expect(subject).to be_available }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "no stock and not backorderable" do
|
|
29
|
-
before do
|
|
30
|
-
subject.backorderable = false
|
|
31
|
-
allow(subject).to receive_messages(count_on_hand: 0)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it { expect(subject).not_to be_available }
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe 'reduce_count_on_hand_to_zero' do
|
|
39
|
-
context 'when count_on_hand > 0' do
|
|
40
|
-
before(:each) do
|
|
41
|
-
subject.update_column('count_on_hand', 4)
|
|
42
|
-
subject.reduce_count_on_hand_to_zero
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it { expect(subject.count_on_hand).to eq(0) }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'when count_on_hand > 0' do
|
|
49
|
-
before(:each) do
|
|
50
|
-
subject.update_column('count_on_hand', -4)
|
|
51
|
-
@count_on_hand = subject.count_on_hand
|
|
52
|
-
subject.reduce_count_on_hand_to_zero
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it { expect(subject.count_on_hand).to eq(@count_on_hand) }
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "adjust count_on_hand" do
|
|
60
|
-
let!(:current_on_hand) { subject.count_on_hand }
|
|
61
|
-
|
|
62
|
-
it 'is updated pessimistically' do
|
|
63
|
-
copy = Spree::StockItem.find(subject.id)
|
|
64
|
-
|
|
65
|
-
subject.adjust_count_on_hand(5)
|
|
66
|
-
expect(subject.count_on_hand).to eq(current_on_hand + 5)
|
|
67
|
-
|
|
68
|
-
expect(copy.count_on_hand).to eq(current_on_hand)
|
|
69
|
-
copy.adjust_count_on_hand(5)
|
|
70
|
-
expect(copy.count_on_hand).to eq(current_on_hand + 10)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context "item out of stock (by two items)" do
|
|
74
|
-
let(:inventory_unit) { double('InventoryUnit') }
|
|
75
|
-
let(:inventory_unit_2) { double('InventoryUnit2') }
|
|
76
|
-
|
|
77
|
-
before do
|
|
78
|
-
allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2])
|
|
79
|
-
subject.update_column(:count_on_hand, -2)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Regression test for #3755
|
|
83
|
-
it "processes existing backorders, even with negative stock" do
|
|
84
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
|
85
|
-
expect(inventory_unit_2).not_to receive(:fill_backorder)
|
|
86
|
-
subject.adjust_count_on_hand(1)
|
|
87
|
-
expect(subject.count_on_hand).to eq(-1)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Test for #3755
|
|
91
|
-
it "does not process backorders when stock is adjusted negatively" do
|
|
92
|
-
expect(inventory_unit).not_to receive(:fill_backorder)
|
|
93
|
-
expect(inventory_unit_2).not_to receive(:fill_backorder)
|
|
94
|
-
subject.adjust_count_on_hand(-1)
|
|
95
|
-
expect(subject.count_on_hand).to eq(-3)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "adds new items" do
|
|
99
|
-
before { allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2]) }
|
|
100
|
-
|
|
101
|
-
it "fills existing backorders" do
|
|
102
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
|
103
|
-
expect(inventory_unit_2).to receive(:fill_backorder)
|
|
104
|
-
|
|
105
|
-
subject.adjust_count_on_hand(3)
|
|
106
|
-
expect(subject.count_on_hand).to eq(1)
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
context "set count_on_hand" do
|
|
113
|
-
let!(:current_on_hand) { subject.count_on_hand }
|
|
114
|
-
|
|
115
|
-
it 'is updated pessimistically' do
|
|
116
|
-
copy = Spree::StockItem.find(subject.id)
|
|
117
|
-
|
|
118
|
-
subject.set_count_on_hand(5)
|
|
119
|
-
expect(subject.count_on_hand).to eq(5)
|
|
120
|
-
|
|
121
|
-
expect(copy.count_on_hand).to eq(current_on_hand)
|
|
122
|
-
copy.set_count_on_hand(10)
|
|
123
|
-
expect(copy.count_on_hand).to eq(current_on_hand)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context "item out of stock (by two items)" do
|
|
127
|
-
let(:inventory_unit) { double('InventoryUnit') }
|
|
128
|
-
let(:inventory_unit_2) { double('InventoryUnit2') }
|
|
129
|
-
|
|
130
|
-
before { subject.set_count_on_hand(-2) }
|
|
131
|
-
|
|
132
|
-
it "doesn't process backorders" do
|
|
133
|
-
expect(subject).not_to receive(:backordered_inventory_units)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context "adds new items" do
|
|
137
|
-
before { allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2]) }
|
|
138
|
-
|
|
139
|
-
it "fills existing backorders" do
|
|
140
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
|
141
|
-
expect(inventory_unit_2).to receive(:fill_backorder)
|
|
142
|
-
|
|
143
|
-
subject.set_count_on_hand(1)
|
|
144
|
-
expect(subject.count_on_hand).to eq(1)
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "with stock movements" do
|
|
151
|
-
before { Spree::StockMovement.create(stock_item: subject, quantity: 1) }
|
|
152
|
-
|
|
153
|
-
it "doesnt raise ReadOnlyRecord error" do
|
|
154
|
-
expect { subject.destroy }.not_to raise_error
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
context "destroyed" do
|
|
159
|
-
before { subject.destroy }
|
|
160
|
-
|
|
161
|
-
it "recreates stock item just fine" do
|
|
162
|
-
expect {
|
|
163
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
|
164
|
-
}.not_to raise_error
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "doesnt allow recreating more than one stock item at once" do
|
|
168
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
|
169
|
-
|
|
170
|
-
expect {
|
|
171
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
|
172
|
-
}.to raise_error(StandardError)
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "#after_save" do
|
|
177
|
-
before do
|
|
178
|
-
subject.variant.update_column(:updated_at, 1.day.ago)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
context "binary_inventory_cache is set to false (default)" do
|
|
182
|
-
context "in_stock? changes" do
|
|
183
|
-
it "touches its variant" do
|
|
184
|
-
expect do
|
|
185
|
-
subject.adjust_count_on_hand(subject.count_on_hand * -1)
|
|
186
|
-
end.to change { subject.variant.reload.updated_at }
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
context "in_stock? does not change" do
|
|
191
|
-
it "touches its variant" do
|
|
192
|
-
expect do
|
|
193
|
-
subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
|
|
194
|
-
end.to change { subject.variant.reload.updated_at }
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
context "binary_inventory_cache is set to true" do
|
|
200
|
-
before { Spree::Config.binary_inventory_cache = true }
|
|
201
|
-
context "in_stock? changes" do
|
|
202
|
-
it "touches its variant" do
|
|
203
|
-
expect do
|
|
204
|
-
subject.adjust_count_on_hand(subject.count_on_hand * -1)
|
|
205
|
-
end.to change { subject.variant.reload.updated_at }
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context "in_stock? does not change" do
|
|
210
|
-
it "does not touch its variant" do
|
|
211
|
-
expect do
|
|
212
|
-
subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
|
|
213
|
-
end.not_to change { subject.variant.reload.updated_at }
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
context "when a new stock location is added" do
|
|
218
|
-
it "touches its variant" do
|
|
219
|
-
expect do
|
|
220
|
-
create(:stock_location)
|
|
221
|
-
end.to change { subject.variant.reload.updated_at }
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
describe "#after_touch" do
|
|
228
|
-
it "touches its variant" do
|
|
229
|
-
Timecop.scale(1000) do
|
|
230
|
-
expect do
|
|
231
|
-
subject.touch
|
|
232
|
-
end.to change { subject.variant.updated_at }
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
# Regression test for #4651
|
|
238
|
-
context "variant" do
|
|
239
|
-
it "can be found even if the variant is deleted" do
|
|
240
|
-
subject.variant.destroy
|
|
241
|
-
expect(subject.reload.variant).not_to be_nil
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
describe 'validations' do
|
|
246
|
-
describe 'count_on_hand' do
|
|
247
|
-
shared_examples_for 'valid count_on_hand' do
|
|
248
|
-
before(:each) do
|
|
249
|
-
subject.save
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it 'has :no errors_on' do
|
|
253
|
-
expect(subject.errors_on(:count_on_hand).size).to eq(0)
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
shared_examples_for 'not valid count_on_hand' do
|
|
258
|
-
before(:each) do
|
|
259
|
-
subject.save
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
it 'has 1 error_on' do
|
|
263
|
-
expect(subject.error_on(:count_on_hand).size).to eq(1)
|
|
264
|
-
end
|
|
265
|
-
it { expect(subject.errors[:count_on_hand]).to include 'must be greater than or equal to 0' }
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
context 'when count_on_hand not changed' do
|
|
269
|
-
context 'when not backorderable' do
|
|
270
|
-
before(:each) do
|
|
271
|
-
subject.backorderable = false
|
|
272
|
-
end
|
|
273
|
-
it_should_behave_like 'valid count_on_hand'
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
context 'when backorderable' do
|
|
277
|
-
before(:each) do
|
|
278
|
-
subject.backorderable = true
|
|
279
|
-
end
|
|
280
|
-
it_should_behave_like 'valid count_on_hand'
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
context 'when count_on_hand changed' do
|
|
285
|
-
context 'when backorderable' do
|
|
286
|
-
before(:each) do
|
|
287
|
-
subject.backorderable = true
|
|
288
|
-
end
|
|
289
|
-
context 'when both count_on_hand and count_on_hand_was are positive' do
|
|
290
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
291
|
-
before(:each) do
|
|
292
|
-
subject.update_column(:count_on_hand, 3)
|
|
293
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 3)
|
|
294
|
-
end
|
|
295
|
-
it_should_behave_like 'valid count_on_hand'
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
|
299
|
-
before(:each) do
|
|
300
|
-
subject.update_column(:count_on_hand, 3)
|
|
301
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 2)
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
it_should_behave_like 'valid count_on_hand'
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
context 'when both count_on_hand and count_on_hand_was are negative' do
|
|
309
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
310
|
-
before(:each) do
|
|
311
|
-
subject.update_column(:count_on_hand, -3)
|
|
312
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 2)
|
|
313
|
-
end
|
|
314
|
-
it_should_behave_like 'valid count_on_hand'
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
|
318
|
-
before(:each) do
|
|
319
|
-
subject.update_column(:count_on_hand, 3)
|
|
320
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 3)
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
it_should_behave_like 'valid count_on_hand'
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
context 'when both count_on_hand is positive and count_on_hand_was is negative' do
|
|
328
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
329
|
-
before(:each) do
|
|
330
|
-
subject.update_column(:count_on_hand, -3)
|
|
331
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 6)
|
|
332
|
-
end
|
|
333
|
-
it_should_behave_like 'valid count_on_hand'
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
context 'when both count_on_hand is negative and count_on_hand_was is positive' do
|
|
338
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
339
|
-
before(:each) do
|
|
340
|
-
subject.update_column(:count_on_hand, 3)
|
|
341
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 6)
|
|
342
|
-
end
|
|
343
|
-
it_should_behave_like 'valid count_on_hand'
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
context 'when not backorderable' do
|
|
349
|
-
before(:each) do
|
|
350
|
-
subject.backorderable = false
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
context 'when both count_on_hand and count_on_hand_was are positive' do
|
|
354
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
355
|
-
before(:each) do
|
|
356
|
-
subject.update_column(:count_on_hand, 3)
|
|
357
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 3)
|
|
358
|
-
end
|
|
359
|
-
it_should_behave_like 'valid count_on_hand'
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
|
363
|
-
before(:each) do
|
|
364
|
-
subject.update_column(:count_on_hand, 3)
|
|
365
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 2)
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
it_should_behave_like 'valid count_on_hand'
|
|
369
|
-
end
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
context 'when both count_on_hand and count_on_hand_was are negative' do
|
|
373
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
374
|
-
before(:each) do
|
|
375
|
-
subject.update_column(:count_on_hand, -3)
|
|
376
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 2)
|
|
377
|
-
end
|
|
378
|
-
it_should_behave_like 'valid count_on_hand'
|
|
379
|
-
end
|
|
380
|
-
|
|
381
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
|
382
|
-
before(:each) do
|
|
383
|
-
subject.update_column(:count_on_hand, -3)
|
|
384
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 3)
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
it_should_behave_like 'not valid count_on_hand'
|
|
388
|
-
end
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
context 'when both count_on_hand is positive and count_on_hand_was is negative' do
|
|
392
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
393
|
-
before(:each) do
|
|
394
|
-
subject.update_column(:count_on_hand, -3)
|
|
395
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 6)
|
|
396
|
-
end
|
|
397
|
-
it_should_behave_like 'valid count_on_hand'
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
context 'when both count_on_hand is negative and count_on_hand_was is positive' do
|
|
402
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
|
403
|
-
before(:each) do
|
|
404
|
-
subject.update_column(:count_on_hand, 3)
|
|
405
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 6)
|
|
406
|
-
end
|
|
407
|
-
it_should_behave_like 'not valid count_on_hand'
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
describe 'scopes' do
|
|
416
|
-
context '.with_active_stock_location' do
|
|
417
|
-
let(:stock_items_with_active_location) { Spree::StockItem.with_active_stock_location }
|
|
418
|
-
|
|
419
|
-
context 'when stock location is active' do
|
|
420
|
-
before { stock_location.update_column(:active, true) }
|
|
421
|
-
|
|
422
|
-
it { expect(stock_items_with_active_location).to include(subject) }
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
context 'when stock location is inactive' do
|
|
426
|
-
before { stock_location.update_column(:active, false) }
|
|
427
|
-
|
|
428
|
-
it { expect(stock_items_with_active_location).to_not include(subject) }
|
|
429
|
-
end
|
|
430
|
-
end
|
|
431
|
-
end
|
|
432
|
-
end
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Spree
|
|
4
|
-
describe StockLocation, type: :model do
|
|
5
|
-
subject { create(:stock_location_with_items, backorderable_default: true) }
|
|
6
|
-
let(:stock_item) { subject.stock_items.order(:id).first }
|
|
7
|
-
let(:variant) { stock_item.variant }
|
|
8
|
-
|
|
9
|
-
it 'creates stock_items for all variants' do
|
|
10
|
-
expect(subject.stock_items.count).to eq Variant.count
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context "handling stock items" do
|
|
14
|
-
let!(:variant) { create(:variant) }
|
|
15
|
-
|
|
16
|
-
context "given a variant" do
|
|
17
|
-
subject { StockLocation.create(name: "testing", propagate_all_variants: false) }
|
|
18
|
-
|
|
19
|
-
context "set up" do
|
|
20
|
-
it "creates stock item" do
|
|
21
|
-
expect(subject).to receive(:propagate_variant)
|
|
22
|
-
subject.set_up_stock_item(variant)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "stock item exists" do
|
|
26
|
-
let!(:stock_item) { subject.propagate_variant(variant) }
|
|
27
|
-
|
|
28
|
-
it "returns existing stock item" do
|
|
29
|
-
expect(subject.set_up_stock_item(variant)).to eq(stock_item)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "propagate variants" do
|
|
35
|
-
let(:stock_item) { subject.propagate_variant(variant) }
|
|
36
|
-
|
|
37
|
-
it "creates a new stock item" do
|
|
38
|
-
expect {
|
|
39
|
-
subject.propagate_variant(variant)
|
|
40
|
-
}.to change{ StockItem.count }.by(1)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "passes backorderable default config" do
|
|
44
|
-
context "true" do
|
|
45
|
-
before { subject.backorderable_default = true }
|
|
46
|
-
it { expect(stock_item.backorderable).to be true }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "false" do
|
|
50
|
-
before { subject.backorderable_default = false }
|
|
51
|
-
it { expect(stock_item.backorderable).to be false }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context "propagate all variants" do
|
|
57
|
-
subject { StockLocation.new(name: "testing") }
|
|
58
|
-
|
|
59
|
-
context "true" do
|
|
60
|
-
before { subject.propagate_all_variants = true }
|
|
61
|
-
|
|
62
|
-
specify do
|
|
63
|
-
expect(subject).to receive(:propagate_variant).at_least(:once)
|
|
64
|
-
subject.save!
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context "false" do
|
|
69
|
-
before { subject.propagate_all_variants = false }
|
|
70
|
-
|
|
71
|
-
specify do
|
|
72
|
-
expect(subject).not_to receive(:propagate_variant)
|
|
73
|
-
subject.save!
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'finds a stock_item for a variant' do
|
|
81
|
-
stock_item = subject.stock_item(variant)
|
|
82
|
-
expect(stock_item.count_on_hand).to eq 10
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'finds a stock_item for a variant by id' do
|
|
86
|
-
stock_item = subject.stock_item(variant.id)
|
|
87
|
-
expect(stock_item.variant).to eq variant
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'returns nil when stock_item is not found for variant' do
|
|
91
|
-
stock_item = subject.stock_item(100)
|
|
92
|
-
expect(stock_item).to be_nil
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe '#stock_item_or_create' do
|
|
96
|
-
before do
|
|
97
|
-
variant = create(:variant)
|
|
98
|
-
variant.stock_items.destroy_all
|
|
99
|
-
variant.save
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'creates a stock_item if not found for a variant' do
|
|
103
|
-
stock_item = subject.stock_item_or_create(variant)
|
|
104
|
-
expect(stock_item.variant).to eq variant
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it 'finds a count_on_hand for a variant' do
|
|
109
|
-
expect(subject.count_on_hand(variant)).to eq 10
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it 'finds determines if you a variant is backorderable' do
|
|
113
|
-
expect(subject.backorderable?(variant)).to be true
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it 'restocks a variant with a positive stock movement' do
|
|
117
|
-
originator = double
|
|
118
|
-
expect(subject).to receive(:move).with(variant, 5, originator)
|
|
119
|
-
subject.restock(variant, 5, originator)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it 'unstocks a variant with a negative stock movement' do
|
|
123
|
-
originator = double
|
|
124
|
-
expect(subject).to receive(:move).with(variant, -5, originator)
|
|
125
|
-
subject.unstock(variant, 5, originator)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'it creates a stock_movement' do
|
|
129
|
-
expect {
|
|
130
|
-
subject.move variant, 5
|
|
131
|
-
}.to change { subject.stock_movements.where(stock_item_id: stock_item).count }.by(1)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it 'can be deactivated' do
|
|
135
|
-
create(:stock_location, active: true)
|
|
136
|
-
create(:stock_location, active: false)
|
|
137
|
-
expect(Spree::StockLocation.active.count).to eq 1
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'ensures only one stock location is default at a time' do
|
|
141
|
-
first = create(:stock_location, active: true, default: true)
|
|
142
|
-
second = create(:stock_location, active: true, default: true)
|
|
143
|
-
|
|
144
|
-
expect(first.reload.default).to eq false
|
|
145
|
-
expect(second.reload.default).to eq true
|
|
146
|
-
|
|
147
|
-
first.default = true
|
|
148
|
-
first.save!
|
|
149
|
-
|
|
150
|
-
expect(first.reload.default).to eq true
|
|
151
|
-
expect(second.reload.default).to eq false
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
context 'fill_status' do
|
|
155
|
-
it 'all on_hand with no backordered' do
|
|
156
|
-
on_hand, backordered = subject.fill_status(variant, 5)
|
|
157
|
-
expect(on_hand).to eq 5
|
|
158
|
-
expect(backordered).to eq 0
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it 'some on_hand with some backordered' do
|
|
162
|
-
on_hand, backordered = subject.fill_status(variant, 20)
|
|
163
|
-
expect(on_hand).to eq 10
|
|
164
|
-
expect(backordered).to eq 10
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it 'zero on_hand with all backordered' do
|
|
168
|
-
zero_stock_item = mock_model(StockItem,
|
|
169
|
-
count_on_hand: 0,
|
|
170
|
-
backorderable?: true)
|
|
171
|
-
expect(subject).to receive(:stock_item).with(variant).and_return(zero_stock_item)
|
|
172
|
-
|
|
173
|
-
on_hand, backordered = subject.fill_status(variant, 20)
|
|
174
|
-
expect(on_hand).to eq 0
|
|
175
|
-
expect(backordered).to eq 20
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
context 'when backordering is not allowed' do
|
|
179
|
-
before do
|
|
180
|
-
@stock_item = mock_model(StockItem, backorderable?: false)
|
|
181
|
-
expect(subject).to receive(:stock_item).with(variant).and_return(@stock_item)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
it 'all on_hand' do
|
|
185
|
-
allow(@stock_item).to receive_messages(count_on_hand: 10)
|
|
186
|
-
|
|
187
|
-
on_hand, backordered = subject.fill_status(variant, 5)
|
|
188
|
-
expect(on_hand).to eq 5
|
|
189
|
-
expect(backordered).to eq 0
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
it 'some on_hand' do
|
|
193
|
-
allow(@stock_item).to receive_messages(count_on_hand: 10)
|
|
194
|
-
|
|
195
|
-
on_hand, backordered = subject.fill_status(variant, 20)
|
|
196
|
-
expect(on_hand).to eq 10
|
|
197
|
-
expect(backordered).to eq 0
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it 'zero on_hand' do
|
|
201
|
-
allow(@stock_item).to receive_messages(count_on_hand: 0)
|
|
202
|
-
|
|
203
|
-
on_hand, backordered = subject.fill_status(variant, 20)
|
|
204
|
-
expect(on_hand).to eq 0
|
|
205
|
-
expect(backordered).to eq 0
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context 'without stock_items' do
|
|
210
|
-
subject { create(:stock_location) }
|
|
211
|
-
let(:variant) { create(:base_variant) }
|
|
212
|
-
|
|
213
|
-
it 'zero on_hand and backordered' do
|
|
214
|
-
subject
|
|
215
|
-
variant.stock_items.destroy_all
|
|
216
|
-
on_hand, backordered = subject.fill_status(variant, 1)
|
|
217
|
-
expect(on_hand).to eq 0
|
|
218
|
-
expect(backordered).to eq 0
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
context '#state_text' do
|
|
224
|
-
context 'state is blank' do
|
|
225
|
-
subject { StockLocation.create(name: "testing", state: nil, state_name: 'virginia') }
|
|
226
|
-
specify { expect(subject.state_text).to eq('virginia') }
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
context 'both name and abbr is present' do
|
|
230
|
-
let(:state) { stub_model(Spree::State, name: 'virginia', abbr: 'va') }
|
|
231
|
-
subject { StockLocation.create(name: "testing", state: state, state_name: nil) }
|
|
232
|
-
specify { expect(subject.state_text).to eq('va') }
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
context 'only name is present' do
|
|
236
|
-
let(:state) { stub_model(Spree::State, name: 'virginia', abbr: nil) }
|
|
237
|
-
subject { StockLocation.create(name: "testing", state: state, state_name: nil) }
|
|
238
|
-
specify { expect(subject.state_text).to eq('virginia') }
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
end
|
|
243
|
-
end
|