spree_core 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
  3. data/app/models/concerns/spree/user_methods.rb +10 -0
  4. data/app/models/spree/legacy_user.rb +0 -8
  5. data/app/models/spree/order.rb +1 -1
  6. data/app/models/spree/product.rb +8 -0
  7. data/app/models/spree/product/scopes.rb +7 -3
  8. data/app/models/spree/stock_transfer.rb +1 -1
  9. data/config/locales/en.yml +2 -0
  10. data/lib/spree/core/version.rb +1 -1
  11. data/spree_core.gemspec +2 -2
  12. metadata +11 -208
  13. data/spec/fixtures/microdata.html +0 -22
  14. data/spec/fixtures/microdata_itemref.html +0 -15
  15. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  16. data/spec/fixtures/thinking-cat.jpg +0 -0
  17. data/spec/helpers/base_helper_spec.rb +0 -200
  18. data/spec/helpers/products_helper_spec.rb +0 -296
  19. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  20. data/spec/lib/i18n_spec.rb +0 -123
  21. data/spec/lib/search/base_spec.rb +0 -86
  22. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  23. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  24. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  25. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  26. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  27. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  28. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  29. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  30. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  31. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  32. data/spec/lib/spree/core_spec.rb +0 -23
  33. data/spec/lib/spree/localized_number_spec.rb +0 -48
  34. data/spec/lib/spree/migrations_spec.rb +0 -36
  35. data/spec/lib/spree/money_spec.rb +0 -122
  36. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  37. data/spec/mailers/order_mailer_spec.rb +0 -122
  38. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  39. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  40. data/spec/mailers/test_mailer_spec.rb +0 -38
  41. data/spec/models/option_type_prototype_spec.rb +0 -9
  42. data/spec/models/spree/ability_spec.rb +0 -251
  43. data/spec/models/spree/address_spec.rb +0 -291
  44. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  45. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  46. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  47. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  48. data/spec/models/spree/adjustment_spec.rb +0 -189
  49. data/spec/models/spree/app_configuration_spec.rb +0 -26
  50. data/spec/models/spree/asset_spec.rb +0 -28
  51. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  52. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  53. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  54. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  55. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  56. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  57. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -51
  58. data/spec/models/spree/calculator/shipping.rb +0 -8
  59. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  60. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  61. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  62. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  63. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  64. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  65. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  66. data/spec/models/spree/calculator_spec.rb +0 -69
  67. data/spec/models/spree/classification_spec.rb +0 -93
  68. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  69. data/spec/models/spree/concerns/user_methods_spec.rb +0 -55
  70. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  71. data/spec/models/spree/country_spec.rb +0 -55
  72. data/spec/models/spree/credit_card_spec.rb +0 -328
  73. data/spec/models/spree/customer_return_spec.rb +0 -240
  74. data/spec/models/spree/exchange_spec.rb +0 -75
  75. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  76. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  77. data/spec/models/spree/gateway_spec.rb +0 -61
  78. data/spec/models/spree/image_spec.rb +0 -8
  79. data/spec/models/spree/inventory_unit_spec.rb +0 -225
  80. data/spec/models/spree/line_item_spec.rb +0 -327
  81. data/spec/models/spree/option_type_spec.rb +0 -14
  82. data/spec/models/spree/option_value_spec.rb +0 -18
  83. data/spec/models/spree/order/address_spec.rb +0 -50
  84. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  85. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  86. data/spec/models/spree/order/checkout_spec.rb +0 -782
  87. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  88. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  89. data/spec/models/spree/order/helpers_spec.rb +0 -5
  90. data/spec/models/spree/order/payment_spec.rb +0 -214
  91. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  92. data/spec/models/spree/order/shipments_spec.rb +0 -43
  93. data/spec/models/spree/order/state_machine_spec.rb +0 -211
  94. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  95. data/spec/models/spree/order/tax_spec.rb +0 -84
  96. data/spec/models/spree/order/totals_spec.rb +0 -24
  97. data/spec/models/spree/order/updating_spec.rb +0 -18
  98. data/spec/models/spree/order/validations_spec.rb +0 -15
  99. data/spec/models/spree/order_contents_spec.rb +0 -297
  100. data/spec/models/spree/order_inventory_spec.rb +0 -238
  101. data/spec/models/spree/order_merger_spec.rb +0 -135
  102. data/spec/models/spree/order_spec.rb +0 -967
  103. data/spec/models/spree/order_updater_spec.rb +0 -305
  104. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  105. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  106. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  107. data/spec/models/spree/payment_method_spec.rb +0 -103
  108. data/spec/models/spree/payment_spec.rb +0 -919
  109. data/spec/models/spree/preference_spec.rb +0 -80
  110. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  111. data/spec/models/spree/preferences/preferable_spec.rb +0 -348
  112. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  113. data/spec/models/spree/preferences/store_spec.rb +0 -46
  114. data/spec/models/spree/price_spec.rb +0 -128
  115. data/spec/models/spree/product/scopes_spec.rb +0 -183
  116. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  117. data/spec/models/spree/product_filter_spec.rb +0 -26
  118. data/spec/models/spree/product_option_type_spec.rb +0 -9
  119. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  120. data/spec/models/spree/product_property_spec.rb +0 -22
  121. data/spec/models/spree/product_spec.rb +0 -540
  122. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
  123. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  124. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  125. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  126. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  127. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  128. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  129. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  130. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  131. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  132. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  133. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  134. data/spec/models/spree/promotion_action_spec.rb +0 -10
  135. data/spec/models/spree/promotion_category_spec.rb +0 -17
  136. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  137. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  138. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  139. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  140. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  141. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  142. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  143. data/spec/models/spree/promotion_spec.rb +0 -644
  144. data/spec/models/spree/property_prototype_spec.rb +0 -9
  145. data/spec/models/spree/property_spec.rb +0 -5
  146. data/spec/models/spree/prototype_spec.rb +0 -5
  147. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  148. data/spec/models/spree/refund_reason_spec.rb +0 -7
  149. data/spec/models/spree/refund_spec.rb +0 -195
  150. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  151. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  152. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  153. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  154. data/spec/models/spree/reimbursement_spec.rb +0 -188
  155. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  156. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  157. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  158. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  159. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  160. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  161. data/spec/models/spree/return_authorization_spec.rb +0 -230
  162. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  163. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  164. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  165. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  166. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  167. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  168. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  169. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  170. data/spec/models/spree/return_item_spec.rb +0 -731
  171. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  172. data/spec/models/spree/role_spec.rb +0 -7
  173. data/spec/models/spree/shipment_spec.rb +0 -740
  174. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  175. data/spec/models/spree/shipping_category_spec.rb +0 -19
  176. data/spec/models/spree/shipping_method_spec.rb +0 -95
  177. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  178. data/spec/models/spree/state_spec.rb +0 -29
  179. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  180. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  181. data/spec/models/spree/stock/coordinator_spec.rb +0 -51
  182. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  183. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  184. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  185. data/spec/models/spree/stock/package_spec.rb +0 -194
  186. data/spec/models/spree/stock/packer_spec.rb +0 -70
  187. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  188. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  189. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  190. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  191. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  192. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  193. data/spec/models/spree/stock_item_spec.rb +0 -428
  194. data/spec/models/spree/stock_location_spec.rb +0 -243
  195. data/spec/models/spree/stock_movement_spec.rb +0 -56
  196. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  197. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  198. data/spec/models/spree/store_credit_spec.rb +0 -786
  199. data/spec/models/spree/store_spec.rb +0 -78
  200. data/spec/models/spree/tax_category_spec.rb +0 -32
  201. data/spec/models/spree/tax_rate_spec.rb +0 -542
  202. data/spec/models/spree/taxon_spec.rb +0 -74
  203. data/spec/models/spree/taxonomy_spec.rb +0 -18
  204. data/spec/models/spree/tracker_spec.rb +0 -21
  205. data/spec/models/spree/user_spec.rb +0 -203
  206. data/spec/models/spree/variant_spec.rb +0 -795
  207. data/spec/models/spree/zone_member_spec.rb +0 -38
  208. data/spec/models/spree/zone_spec.rb +0 -470
  209. data/spec/spec_helper.rb +0 -77
  210. data/spec/support/big_decimal.rb +0 -5
  211. data/spec/support/concerns/adjustment_source.rb +0 -23
  212. data/spec/support/concerns/default_price.rb +0 -37
  213. data/spec/support/rake.rb +0 -13
  214. data/spec/support/test_gateway.rb +0 -2
  215. data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -1,428 +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 'maintains the count on hand for a variant' do
9
- expect(subject.count_on_hand).to eq 10
10
- end
11
-
12
- it "can return the stock item's variant's name" do
13
- expect(subject.variant_name).to eq(subject.variant.name)
14
- end
15
-
16
- context "available to be included in shipment" do
17
- context "has stock" do
18
- it { expect(subject).to be_available }
19
- end
20
-
21
- context "backorderable" do
22
- before { subject.backorderable = true }
23
- it { expect(subject).to be_available }
24
- end
25
-
26
- context "no stock and not backorderable" do
27
- before do
28
- subject.backorderable = false
29
- allow(subject).to receive_messages(count_on_hand: 0)
30
- end
31
-
32
- it { expect(subject).not_to be_available }
33
- end
34
- end
35
-
36
- describe 'reduce_count_on_hand_to_zero' do
37
- context 'when count_on_hand > 0' do
38
- before(:each) do
39
- subject.update_column('count_on_hand', 4)
40
- subject.reduce_count_on_hand_to_zero
41
- end
42
-
43
- it { expect(subject.count_on_hand).to eq(0) }
44
- end
45
-
46
- context 'when count_on_hand > 0' do
47
- before(:each) do
48
- subject.update_column('count_on_hand', -4)
49
- @count_on_hand = subject.count_on_hand
50
- subject.reduce_count_on_hand_to_zero
51
- end
52
-
53
- it { expect(subject.count_on_hand).to eq(@count_on_hand) }
54
- end
55
- end
56
-
57
- context "adjust count_on_hand" do
58
- let!(:current_on_hand) { subject.count_on_hand }
59
-
60
- it 'is updated pessimistically' do
61
- copy = Spree::StockItem.find(subject.id)
62
-
63
- subject.adjust_count_on_hand(5)
64
- expect(subject.count_on_hand).to eq(current_on_hand + 5)
65
-
66
- expect(copy.count_on_hand).to eq(current_on_hand)
67
- copy.adjust_count_on_hand(5)
68
- expect(copy.count_on_hand).to eq(current_on_hand + 10)
69
- end
70
-
71
- context "item out of stock (by two items)" do
72
- let(:inventory_unit) { double('InventoryUnit') }
73
- let(:inventory_unit_2) { double('InventoryUnit2') }
74
-
75
- before do
76
- allow(subject).to receive_messages(:backordered_inventory_units => [inventory_unit, inventory_unit_2])
77
- subject.update_column(:count_on_hand, -2)
78
- end
79
-
80
- # Regression test for #3755
81
- it "processes existing backorders, even with negative stock" do
82
- expect(inventory_unit).to receive(:fill_backorder)
83
- expect(inventory_unit_2).not_to receive(:fill_backorder)
84
- subject.adjust_count_on_hand(1)
85
- expect(subject.count_on_hand).to eq(-1)
86
- end
87
-
88
- # Test for #3755
89
- it "does not process backorders when stock is adjusted negatively" do
90
- expect(inventory_unit).not_to receive(:fill_backorder)
91
- expect(inventory_unit_2).not_to receive(:fill_backorder)
92
- subject.adjust_count_on_hand(-1)
93
- expect(subject.count_on_hand).to eq(-3)
94
- end
95
-
96
- context "adds new items" do
97
- before { allow(subject).to receive_messages(:backordered_inventory_units => [inventory_unit, inventory_unit_2]) }
98
-
99
- it "fills existing backorders" do
100
- expect(inventory_unit).to receive(:fill_backorder)
101
- expect(inventory_unit_2).to receive(:fill_backorder)
102
-
103
- subject.adjust_count_on_hand(3)
104
- expect(subject.count_on_hand).to eq(1)
105
- end
106
- end
107
- end
108
- end
109
-
110
- context "set count_on_hand" do
111
- let!(:current_on_hand) { subject.count_on_hand }
112
-
113
- it 'is updated pessimistically' do
114
- copy = Spree::StockItem.find(subject.id)
115
-
116
- subject.set_count_on_hand(5)
117
- expect(subject.count_on_hand).to eq(5)
118
-
119
- expect(copy.count_on_hand).to eq(current_on_hand)
120
- copy.set_count_on_hand(10)
121
- expect(copy.count_on_hand).to eq(current_on_hand)
122
- end
123
-
124
- context "item out of stock (by two items)" do
125
- let(:inventory_unit) { double('InventoryUnit') }
126
- let(:inventory_unit_2) { double('InventoryUnit2') }
127
-
128
- before { subject.set_count_on_hand(-2) }
129
-
130
- it "doesn't process backorders" do
131
- expect(subject).not_to receive(:backordered_inventory_units)
132
- end
133
-
134
- context "adds new items" do
135
- before { allow(subject).to receive_messages(:backordered_inventory_units => [inventory_unit, inventory_unit_2]) }
136
-
137
- it "fills existing backorders" do
138
- expect(inventory_unit).to receive(:fill_backorder)
139
- expect(inventory_unit_2).to receive(:fill_backorder)
140
-
141
- subject.set_count_on_hand(1)
142
- expect(subject.count_on_hand).to eq(1)
143
- end
144
- end
145
- end
146
- end
147
-
148
- context "with stock movements" do
149
- before { Spree::StockMovement.create(stock_item: subject, quantity: 1) }
150
-
151
- it "doesnt raise ReadOnlyRecord error" do
152
- expect { subject.destroy }.not_to raise_error
153
- end
154
- end
155
-
156
- context "destroyed" do
157
- before { subject.destroy }
158
-
159
- it "recreates stock item just fine" do
160
- expect {
161
- stock_location.stock_items.create!(variant: subject.variant)
162
- }.not_to raise_error
163
- end
164
-
165
- it "doesnt allow recreating more than one stock item at once" do
166
- stock_location.stock_items.create!(variant: subject.variant)
167
-
168
- expect {
169
- stock_location.stock_items.create!(variant: subject.variant)
170
- }.to raise_error(StandardError)
171
- end
172
- end
173
-
174
- describe "#after_save" do
175
- before do
176
- subject.variant.update_column(:updated_at, 1.day.ago)
177
- end
178
-
179
- context "binary_inventory_cache is set to false (default)" do
180
- context "in_stock? changes" do
181
- it "touches its variant" do
182
- expect do
183
- subject.adjust_count_on_hand(subject.count_on_hand * -1)
184
- end.to change { subject.variant.reload.updated_at }
185
- end
186
- end
187
-
188
- context "in_stock? does not change" do
189
- it "touches its variant" do
190
- expect do
191
- subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
192
- end.to change { subject.variant.reload.updated_at }
193
- end
194
- end
195
- end
196
-
197
- context "binary_inventory_cache is set to true" do
198
- before { Spree::Config.binary_inventory_cache = true }
199
- context "in_stock? changes" do
200
- it "touches its variant" do
201
- expect do
202
- subject.adjust_count_on_hand(subject.count_on_hand * -1)
203
- end.to change { subject.variant.reload.updated_at }
204
- end
205
- end
206
-
207
- context "in_stock? does not change" do
208
- it "does not touch its variant" do
209
- expect do
210
- subject.adjust_count_on_hand((subject.count_on_hand * -1) + 1)
211
- end.not_to change { subject.variant.reload.updated_at }
212
- end
213
- end
214
-
215
- context "when a new stock location is added" do
216
- it "touches its variant" do
217
- expect do
218
- create(:stock_location)
219
- end.to change { subject.variant.reload.updated_at }
220
- end
221
- end
222
- end
223
- end
224
-
225
- describe "#after_touch" do
226
- it "touches its variant" do
227
- expect do
228
- subject.touch
229
- end.to change { subject.variant.updated_at }
230
- end
231
- end
232
-
233
- # Regression test for #4651
234
- context "variant" do
235
- it "can be found even if the variant is deleted" do
236
- subject.variant.destroy
237
- expect(subject.reload.variant).not_to be_nil
238
- end
239
- end
240
-
241
- describe 'validations' do
242
- describe 'count_on_hand' do
243
- shared_examples_for 'valid count_on_hand' do
244
- before(:each) do
245
- subject.save
246
- end
247
-
248
- it 'has :no errors_on' do
249
- expect(subject.errors_on(:count_on_hand).size).to eq(0)
250
- end
251
- end
252
-
253
- shared_examples_for 'not valid count_on_hand' do
254
- before(:each) do
255
- subject.save
256
- end
257
-
258
- it 'has 1 error_on' do
259
- expect(subject.error_on(:count_on_hand).size).to eq(1)
260
- end
261
- it { expect(subject.errors[:count_on_hand]).to include 'must be greater than or equal to 0' }
262
- end
263
-
264
- context 'when count_on_hand not changed' do
265
- context 'when not backorderable' do
266
- before(:each) do
267
- subject.backorderable = false
268
- end
269
- it_should_behave_like 'valid count_on_hand'
270
- end
271
-
272
- context 'when backorderable' do
273
- before(:each) do
274
- subject.backorderable = true
275
- end
276
- it_should_behave_like 'valid count_on_hand'
277
- end
278
- end
279
-
280
- context 'when count_on_hand changed' do
281
- context 'when backorderable' do
282
- before(:each) do
283
- subject.backorderable = true
284
- end
285
- context 'when both count_on_hand and count_on_hand_was are positive' do
286
- context 'when count_on_hand is greater than count_on_hand_was' do
287
- before(:each) do
288
- subject.update_column(:count_on_hand, 3)
289
- subject.send(:count_on_hand=, subject.count_on_hand + 3)
290
- end
291
- it_should_behave_like 'valid count_on_hand'
292
- end
293
-
294
- context 'when count_on_hand is smaller than count_on_hand_was' do
295
- before(:each) do
296
- subject.update_column(:count_on_hand, 3)
297
- subject.send(:count_on_hand=, subject.count_on_hand - 2)
298
- end
299
-
300
- it_should_behave_like 'valid count_on_hand'
301
- end
302
- end
303
-
304
- context 'when both count_on_hand and count_on_hand_was are negative' do
305
- context 'when count_on_hand is greater than count_on_hand_was' do
306
- before(:each) do
307
- subject.update_column(:count_on_hand, -3)
308
- subject.send(:count_on_hand=, subject.count_on_hand + 2)
309
- end
310
- it_should_behave_like 'valid count_on_hand'
311
- end
312
-
313
- context 'when count_on_hand is smaller than count_on_hand_was' do
314
- before(:each) do
315
- subject.update_column(:count_on_hand, 3)
316
- subject.send(:count_on_hand=, subject.count_on_hand - 3)
317
- end
318
-
319
- it_should_behave_like 'valid count_on_hand'
320
- end
321
- end
322
-
323
- context 'when both count_on_hand is positive and count_on_hand_was is negative' do
324
- context 'when count_on_hand is greater than count_on_hand_was' do
325
- before(:each) do
326
- subject.update_column(:count_on_hand, -3)
327
- subject.send(:count_on_hand=, subject.count_on_hand + 6)
328
- end
329
- it_should_behave_like 'valid count_on_hand'
330
- end
331
- end
332
-
333
- context 'when both count_on_hand is negative and count_on_hand_was is positive' do
334
- context 'when count_on_hand is greater than count_on_hand_was' do
335
- before(:each) do
336
- subject.update_column(:count_on_hand, 3)
337
- subject.send(:count_on_hand=, subject.count_on_hand - 6)
338
- end
339
- it_should_behave_like 'valid count_on_hand'
340
- end
341
- end
342
- end
343
-
344
- context 'when not backorderable' do
345
- before(:each) do
346
- subject.backorderable = false
347
- end
348
-
349
- context 'when both count_on_hand and count_on_hand_was are positive' do
350
- context 'when count_on_hand is greater 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
- it_should_behave_like 'valid count_on_hand'
356
- end
357
-
358
- context 'when count_on_hand is smaller than count_on_hand_was' do
359
- before(:each) do
360
- subject.update_column(:count_on_hand, 3)
361
- subject.send(:count_on_hand=, subject.count_on_hand - 2)
362
- end
363
-
364
- it_should_behave_like 'valid count_on_hand'
365
- end
366
- end
367
-
368
- context 'when both count_on_hand and count_on_hand_was are negative' do
369
- context 'when count_on_hand is greater than count_on_hand_was' do
370
- before(:each) do
371
- subject.update_column(:count_on_hand, -3)
372
- subject.send(:count_on_hand=, subject.count_on_hand + 2)
373
- end
374
- it_should_behave_like 'valid count_on_hand'
375
- end
376
-
377
- context 'when count_on_hand is smaller than count_on_hand_was' do
378
- before(:each) do
379
- subject.update_column(:count_on_hand, -3)
380
- subject.send(:count_on_hand=, subject.count_on_hand - 3)
381
- end
382
-
383
- it_should_behave_like 'not valid count_on_hand'
384
- end
385
- end
386
-
387
- context 'when both count_on_hand is positive and count_on_hand_was is negative' do
388
- context 'when count_on_hand is greater than count_on_hand_was' do
389
- before(:each) do
390
- subject.update_column(:count_on_hand, -3)
391
- subject.send(:count_on_hand=, subject.count_on_hand + 6)
392
- end
393
- it_should_behave_like 'valid count_on_hand'
394
- end
395
- end
396
-
397
- context 'when both count_on_hand is negative and count_on_hand_was is positive' do
398
- context 'when count_on_hand is greater than count_on_hand_was' do
399
- before(:each) do
400
- subject.update_column(:count_on_hand, 3)
401
- subject.send(:count_on_hand=, subject.count_on_hand - 6)
402
- end
403
- it_should_behave_like 'not valid count_on_hand'
404
- end
405
- end
406
- end
407
- end
408
- end
409
- end
410
-
411
- describe 'scopes' do
412
- context '.with_active_stock_location' do
413
- let(:stock_items_with_active_location) { Spree::StockItem.with_active_stock_location }
414
-
415
- context 'when stock location is active' do
416
- before { stock_location.update_column(:active, true) }
417
-
418
- it { expect(stock_items_with_active_location).to include(subject) }
419
- end
420
-
421
- context 'when stock location is inactive' do
422
- before { stock_location.update_column(:active, false) }
423
-
424
- it { expect(stock_items_with_active_location).to_not include(subject) }
425
- end
426
- end
427
- end
428
- 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