spree_core 3.3.0.rc1 → 3.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/mailers/spree/base_mailer.rb +5 -0
- data/app/models/spree/ability.rb +4 -1
- data/app/models/spree/image.rb +6 -2
- data/app/models/spree/order.rb +10 -9
- data/app/models/spree/order/payments.rb +1 -1
- data/app/models/spree/payment_method/store_credit.rb +4 -0
- data/app/models/spree/shipment.rb +2 -0
- data/app/views/spree/shared/_base_mailer_header.html.erb +5 -1
- data/app/views/spree/shared/_mailer_line_item.html.erb +5 -1
- data/config/routes.rb +0 -3
- data/lib/spree/core/components.rb +17 -0
- data/lib/spree/core/controller_helpers/auth.rb +3 -1
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -5
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +4 -204
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +0 -6
- 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 -607
- data/spec/lib/spree/core/number_generator_spec.rb +0 -139
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -54
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -54
- 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 -52
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- 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 -348
- data/spec/models/spree/option_type_prototype_spec.rb +0 -9
- 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 -457
- 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 -332
- data/spec/models/spree/order_inventory_spec.rb +0 -247
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1067
- 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 -108
- data/spec/models/spree/payment_spec.rb +0 -922
- 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 -174
- data/spec/models/spree/product_duplicator_spec.rb +0 -102
- 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 -626
- 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 -674
- 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 -734
- 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 -744
- 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 -125
- 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 -42
- 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 -37
- 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 -465
- 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 -798
- 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 -93
- 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 -82
- 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,465 +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 five items)" do
|
74
|
-
context "when stock received is insufficient to fullfill backorders" do
|
75
|
-
let(:inventory_unit) { double('InventoryUnit') }
|
76
|
-
let(:inventory_unit_2) { double('InventoryUnit2') }
|
77
|
-
let(:split_inventory_unit) { double('SplitInventoryUnit') }
|
78
|
-
|
79
|
-
before do
|
80
|
-
allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2])
|
81
|
-
allow(split_inventory_unit).to receive_messages(quantity: 3)
|
82
|
-
allow(inventory_unit).to receive_messages(quantity: 4, split_inventory!: split_inventory_unit)
|
83
|
-
allow(inventory_unit_2).to receive_messages(quantity: 1)
|
84
|
-
subject.update_column(:count_on_hand, -5)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "splits inventory to fullfill partial backorder" do
|
88
|
-
expect(inventory_unit_2).not_to receive(:split_inventory!)
|
89
|
-
|
90
|
-
expect(split_inventory_unit).to receive(:fill_backorder)
|
91
|
-
expect(inventory_unit).not_to receive(:fill_backorder)
|
92
|
-
expect(inventory_unit_2).not_to receive(:fill_backorder)
|
93
|
-
|
94
|
-
subject.adjust_count_on_hand(3)
|
95
|
-
expect(subject.count_on_hand).to eq -2
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "item out of stock (by two items)" do
|
101
|
-
let(:inventory_unit) { double('InventoryUnit') }
|
102
|
-
let(:inventory_unit_2) { double('InventoryUnit2') }
|
103
|
-
|
104
|
-
before do
|
105
|
-
allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2])
|
106
|
-
allow(inventory_unit).to receive_messages(quantity: 1)
|
107
|
-
allow(inventory_unit_2).to receive_messages(quantity: 1)
|
108
|
-
subject.update_column(:count_on_hand, -2)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Regression test for #3755
|
112
|
-
it "processes existing backorders, even with negative stock" do
|
113
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
114
|
-
expect(inventory_unit_2).not_to receive(:fill_backorder)
|
115
|
-
subject.adjust_count_on_hand(1)
|
116
|
-
expect(subject.count_on_hand).to eq(-1)
|
117
|
-
end
|
118
|
-
|
119
|
-
# Test for #3755
|
120
|
-
it "does not process backorders when stock is adjusted negatively" do
|
121
|
-
expect(inventory_unit).not_to receive(:fill_backorder)
|
122
|
-
expect(inventory_unit_2).not_to receive(:fill_backorder)
|
123
|
-
subject.adjust_count_on_hand(-1)
|
124
|
-
expect(subject.count_on_hand).to eq(-3)
|
125
|
-
end
|
126
|
-
|
127
|
-
context "adds new items" do
|
128
|
-
before { allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2]) }
|
129
|
-
|
130
|
-
it "fills existing backorders" do
|
131
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
132
|
-
expect(inventory_unit_2).to receive(:fill_backorder)
|
133
|
-
|
134
|
-
subject.adjust_count_on_hand(3)
|
135
|
-
expect(subject.count_on_hand).to eq(1)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "set count_on_hand" do
|
142
|
-
let!(:current_on_hand) { subject.count_on_hand }
|
143
|
-
|
144
|
-
it 'is updated pessimistically' do
|
145
|
-
copy = Spree::StockItem.find(subject.id)
|
146
|
-
|
147
|
-
subject.set_count_on_hand(5)
|
148
|
-
expect(subject.count_on_hand).to eq(5)
|
149
|
-
|
150
|
-
expect(copy.count_on_hand).to eq(current_on_hand)
|
151
|
-
copy.set_count_on_hand(10)
|
152
|
-
expect(copy.count_on_hand).to eq(current_on_hand)
|
153
|
-
end
|
154
|
-
|
155
|
-
context "item out of stock (by two items)" do
|
156
|
-
let(:inventory_unit) { double('InventoryUnit') }
|
157
|
-
let(:inventory_unit_2) { double('InventoryUnit2') }
|
158
|
-
|
159
|
-
before { subject.set_count_on_hand(-2) }
|
160
|
-
|
161
|
-
it "doesn't process backorders" do
|
162
|
-
expect(subject).not_to receive(:backordered_inventory_units)
|
163
|
-
end
|
164
|
-
|
165
|
-
context "adds new items" do
|
166
|
-
before do
|
167
|
-
allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2])
|
168
|
-
allow(inventory_unit).to receive_messages(quantity: 1)
|
169
|
-
allow(inventory_unit_2).to receive_messages(quantity: 1)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "fills existing backorders" do
|
173
|
-
expect(inventory_unit).to receive(:fill_backorder)
|
174
|
-
expect(inventory_unit_2).to receive(:fill_backorder)
|
175
|
-
|
176
|
-
subject.set_count_on_hand(1)
|
177
|
-
expect(subject.count_on_hand).to eq(1)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "with stock movements" do
|
184
|
-
before { Spree::StockMovement.create(stock_item: subject, quantity: 1) }
|
185
|
-
|
186
|
-
it "doesnt raise ReadOnlyRecord error" do
|
187
|
-
expect { subject.destroy }.not_to raise_error
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context "destroyed" do
|
192
|
-
before { subject.destroy }
|
193
|
-
|
194
|
-
it "recreates stock item just fine" do
|
195
|
-
expect {
|
196
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
197
|
-
}.not_to raise_error
|
198
|
-
end
|
199
|
-
|
200
|
-
it "doesnt allow recreating more than one stock item at once" do
|
201
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
202
|
-
|
203
|
-
expect {
|
204
|
-
stock_location.stock_items.create!(variant: subject.variant)
|
205
|
-
}.to raise_error(StandardError)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "#after_save" do
|
210
|
-
before do
|
211
|
-
subject.variant.update_column(:updated_at, 1.day.ago)
|
212
|
-
end
|
213
|
-
|
214
|
-
context "binary_inventory_cache is set to false (default)" do
|
215
|
-
context "in_stock? changes" do
|
216
|
-
it "touches its variant" do
|
217
|
-
expect do
|
218
|
-
subject.adjust_count_on_hand(subject.count_on_hand * -1)
|
219
|
-
end.to change { subject.variant.reload.updated_at }
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context "in_stock? does not change" do
|
224
|
-
it "touches its variant" do
|
225
|
-
expect do
|
226
|
-
subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
|
227
|
-
end.to change { subject.variant.reload.updated_at }
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
context "binary_inventory_cache is set to true" do
|
233
|
-
before { Spree::Config.binary_inventory_cache = true }
|
234
|
-
context "in_stock? changes" do
|
235
|
-
it "touches its variant" do
|
236
|
-
expect do
|
237
|
-
subject.adjust_count_on_hand(subject.count_on_hand * -1)
|
238
|
-
end.to change { subject.variant.reload.updated_at }
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
context "in_stock? does not change" do
|
243
|
-
it "does not touch its variant" do
|
244
|
-
expect do
|
245
|
-
subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
|
246
|
-
end.not_to change { subject.variant.reload.updated_at }
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context "when a new stock location is added" do
|
251
|
-
it "touches its variant" do
|
252
|
-
expect do
|
253
|
-
create(:stock_location)
|
254
|
-
end.to change { subject.variant.reload.updated_at }
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "#after_touch" do
|
261
|
-
it "touches its variant" do
|
262
|
-
Timecop.scale(1000) do
|
263
|
-
expect do
|
264
|
-
subject.touch
|
265
|
-
end.to change { subject.variant.updated_at }
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
# Regression test for #4651
|
271
|
-
context "variant" do
|
272
|
-
it "can be found even if the variant is deleted" do
|
273
|
-
subject.variant.destroy
|
274
|
-
expect(subject.reload.variant).not_to be_nil
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
describe 'validations' do
|
279
|
-
describe 'count_on_hand' do
|
280
|
-
shared_examples_for 'valid count_on_hand' do
|
281
|
-
before(:each) do
|
282
|
-
subject.save
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'has :no errors_on' do
|
286
|
-
expect(subject.errors_on(:count_on_hand).size).to eq(0)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
shared_examples_for 'not valid count_on_hand' do
|
291
|
-
before(:each) do
|
292
|
-
subject.save
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'has 1 error_on' do
|
296
|
-
expect(subject.error_on(:count_on_hand).size).to eq(1)
|
297
|
-
end
|
298
|
-
it { expect(subject.errors[:count_on_hand]).to include 'must be greater than or equal to 0' }
|
299
|
-
end
|
300
|
-
|
301
|
-
context 'when count_on_hand not changed' do
|
302
|
-
context 'when not backorderable' do
|
303
|
-
before(:each) do
|
304
|
-
subject.backorderable = false
|
305
|
-
end
|
306
|
-
it_should_behave_like 'valid count_on_hand'
|
307
|
-
end
|
308
|
-
|
309
|
-
context 'when backorderable' do
|
310
|
-
before(:each) do
|
311
|
-
subject.backorderable = true
|
312
|
-
end
|
313
|
-
it_should_behave_like 'valid count_on_hand'
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context 'when count_on_hand changed' do
|
318
|
-
context 'when backorderable' do
|
319
|
-
before(:each) do
|
320
|
-
subject.backorderable = true
|
321
|
-
end
|
322
|
-
context 'when both count_on_hand and count_on_hand_was are positive' do
|
323
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
324
|
-
before(:each) do
|
325
|
-
subject.update_column(:count_on_hand, 3)
|
326
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 3)
|
327
|
-
end
|
328
|
-
it_should_behave_like 'valid count_on_hand'
|
329
|
-
end
|
330
|
-
|
331
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
332
|
-
before(:each) do
|
333
|
-
subject.update_column(:count_on_hand, 3)
|
334
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 2)
|
335
|
-
end
|
336
|
-
|
337
|
-
it_should_behave_like 'valid count_on_hand'
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context 'when both count_on_hand and count_on_hand_was are negative' do
|
342
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
343
|
-
before(:each) do
|
344
|
-
subject.update_column(:count_on_hand, -3)
|
345
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 2)
|
346
|
-
end
|
347
|
-
it_should_behave_like 'valid count_on_hand'
|
348
|
-
end
|
349
|
-
|
350
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
351
|
-
before(:each) do
|
352
|
-
subject.update_column(:count_on_hand, 3)
|
353
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 3)
|
354
|
-
end
|
355
|
-
|
356
|
-
it_should_behave_like 'valid count_on_hand'
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
context 'when both count_on_hand is positive and count_on_hand_was is negative' do
|
361
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
362
|
-
before(:each) do
|
363
|
-
subject.update_column(:count_on_hand, -3)
|
364
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 6)
|
365
|
-
end
|
366
|
-
it_should_behave_like 'valid count_on_hand'
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
context 'when both count_on_hand is negative and count_on_hand_was is positive' do
|
371
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
372
|
-
before(:each) do
|
373
|
-
subject.update_column(:count_on_hand, 3)
|
374
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 6)
|
375
|
-
end
|
376
|
-
it_should_behave_like 'valid count_on_hand'
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
context 'when not backorderable' do
|
382
|
-
before(:each) do
|
383
|
-
subject.backorderable = false
|
384
|
-
end
|
385
|
-
|
386
|
-
context 'when both count_on_hand and count_on_hand_was are positive' do
|
387
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
388
|
-
before(:each) do
|
389
|
-
subject.update_column(:count_on_hand, 3)
|
390
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 3)
|
391
|
-
end
|
392
|
-
it_should_behave_like 'valid count_on_hand'
|
393
|
-
end
|
394
|
-
|
395
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
396
|
-
before(:each) do
|
397
|
-
subject.update_column(:count_on_hand, 3)
|
398
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 2)
|
399
|
-
end
|
400
|
-
|
401
|
-
it_should_behave_like 'valid count_on_hand'
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
context 'when both count_on_hand and count_on_hand_was are negative' do
|
406
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
407
|
-
before(:each) do
|
408
|
-
subject.update_column(:count_on_hand, -3)
|
409
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 2)
|
410
|
-
end
|
411
|
-
it_should_behave_like 'valid count_on_hand'
|
412
|
-
end
|
413
|
-
|
414
|
-
context 'when count_on_hand is smaller than count_on_hand_was' do
|
415
|
-
before(:each) do
|
416
|
-
subject.update_column(:count_on_hand, -3)
|
417
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 3)
|
418
|
-
end
|
419
|
-
|
420
|
-
it_should_behave_like 'not valid count_on_hand'
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
context 'when both count_on_hand is positive and count_on_hand_was is negative' do
|
425
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
426
|
-
before(:each) do
|
427
|
-
subject.update_column(:count_on_hand, -3)
|
428
|
-
subject.send(:count_on_hand=, subject.count_on_hand + 6)
|
429
|
-
end
|
430
|
-
it_should_behave_like 'valid count_on_hand'
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
context 'when both count_on_hand is negative and count_on_hand_was is positive' do
|
435
|
-
context 'when count_on_hand is greater than count_on_hand_was' do
|
436
|
-
before(:each) do
|
437
|
-
subject.update_column(:count_on_hand, 3)
|
438
|
-
subject.send(:count_on_hand=, subject.count_on_hand - 6)
|
439
|
-
end
|
440
|
-
it_should_behave_like 'not valid count_on_hand'
|
441
|
-
end
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
describe 'scopes' do
|
449
|
-
context '.with_active_stock_location' do
|
450
|
-
let(:stock_items_with_active_location) { Spree::StockItem.with_active_stock_location }
|
451
|
-
|
452
|
-
context 'when stock location is active' do
|
453
|
-
before { stock_location.update_column(:active, true) }
|
454
|
-
|
455
|
-
it { expect(stock_items_with_active_location).to include(subject) }
|
456
|
-
end
|
457
|
-
|
458
|
-
context 'when stock location is inactive' do
|
459
|
-
before { stock_location.update_column(:active, false) }
|
460
|
-
|
461
|
-
it { expect(stock_items_with_active_location).to_not include(subject) }
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
465
|
-
end
|