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,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- describe Packer, :type => :model do
6
- let(:inventory_units) { [InventoryUnit.new(variant: create(:variant))] }
7
- let(:stock_location) { create(:stock_location) }
8
-
9
- subject { Packer.new(stock_location, inventory_units) }
10
-
11
- context 'packages' do
12
- it 'builds an array of packages' do
13
- packages = subject.packages
14
- expect(packages).to be_a Array
15
- expect(packages.first).to be_a Package
16
- end
17
-
18
- it 'allows users to set splitters to an empty array' do
19
- packer = Packer.new(StockLocation.new, [], [])
20
- expect(packer).not_to receive(:build_splitter)
21
- packages = packer.packages
22
- end
23
- end
24
-
25
- context 'default_package' do
26
- let!(:inventory_units) { 2.times.map { InventoryUnit.new variant: create(:variant) } }
27
-
28
- it 'contains all the items' do
29
- package = subject.default_package
30
- expect(package.contents.size).to eq 2
31
- end
32
-
33
- it 'variants are added as backordered without enough on_hand' do
34
- expect(stock_location).to receive(:fill_status).exactly(2).times.and_return(
35
- *(Array.new(1, [1,0]) + Array.new(1, [0,1]))
36
- )
37
-
38
- package = subject.default_package
39
- expect(package.on_hand.size).to eq 1
40
- expect(package.backordered.size).to eq 1
41
- end
42
-
43
- context "location doesn't have order items in stock" do
44
- let(:stock_location) { create(:stock_location, propagate_all_variants: false) }
45
- let(:inventory_units) { [InventoryUnit.new(variant: create(:variant))] }
46
- let(:packer) { Packer.new(stock_location, inventory_units) }
47
-
48
- it "builds an empty package" do
49
- expect(packer.default_package.contents).to be_empty
50
- end
51
- end
52
-
53
- context "doesn't track inventory levels" do
54
- let(:inventory_units) { 2.times.map { InventoryUnit.new(variant: create(:variant)) } }
55
-
56
- before { Config.track_inventory_levels = false }
57
-
58
- it "doesn't bother stock items status in stock location" do
59
- expect(subject.stock_location).not_to receive(:fill_status)
60
- subject.default_package
61
- end
62
-
63
- it "still creates package with proper quantity" do
64
- expect(subject.default_package.quantity).to eql 2
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,125 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- describe Prioritizer, :type => :model do
6
- let(:order) { mock_model(Order) }
7
- let(:stock_location) { build(:stock_location) }
8
- let(:variant) { build(:variant) }
9
-
10
- def inventory_units
11
- @inventory_units ||= []
12
- end
13
-
14
- def build_inventory_unit
15
- mock_model(InventoryUnit, variant: variant).tap do |unit|
16
- inventory_units << unit
17
- end
18
- end
19
-
20
- def pack
21
- package = Package.new(order)
22
- yield(package) if block_given?
23
- package
24
- end
25
-
26
- it 'keeps a single package' do
27
- package1 = pack do |package|
28
- package.add build_inventory_unit
29
- package.add build_inventory_unit
30
- end
31
-
32
- packages = [package1]
33
- prioritizer = Prioritizer.new(inventory_units, packages)
34
- packages = prioritizer.prioritized_packages
35
- expect(packages.size).to eq 1
36
- end
37
-
38
- it 'removes duplicate packages' do
39
- package1 = pack do |package|
40
- package.add build_inventory_unit
41
- package.add build_inventory_unit
42
- end
43
-
44
- package2 = pack do |package|
45
- package.add inventory_units.first
46
- package.add inventory_units.last
47
- end
48
-
49
- packages = [package1, package2]
50
- prioritizer = Prioritizer.new(inventory_units, packages)
51
- packages = prioritizer.prioritized_packages
52
- expect(packages.size).to eq 1
53
- end
54
-
55
- it 'split over 2 packages' do
56
- package1 = pack do |package|
57
- package.add build_inventory_unit
58
- end
59
- package2 = pack do |package|
60
- package.add build_inventory_unit
61
- end
62
-
63
- packages = [package1, package2]
64
- prioritizer = Prioritizer.new(inventory_units, packages)
65
- packages = prioritizer.prioritized_packages
66
- expect(packages.size).to eq 2
67
- end
68
-
69
- it '1st has some, 2nd has remaining' do
70
- 5.times { build_inventory_unit }
71
-
72
- package1 = pack do |package|
73
- 2.times { |i| package.add inventory_units[i] }
74
- end
75
- package2 = pack do |package|
76
- 5.times { |i| package.add inventory_units[i] }
77
- end
78
-
79
- packages = [package1, package2]
80
- prioritizer = Prioritizer.new(inventory_units, packages)
81
- packages = prioritizer.prioritized_packages
82
- expect(packages.count).to eq 2
83
- expect(packages[0].quantity).to eq 2
84
- expect(packages[1].quantity).to eq 3
85
- end
86
-
87
- it '1st has backorder, 2nd has some' do
88
- 5.times { build_inventory_unit }
89
-
90
- package1 = pack do |package|
91
- 5.times { |i| package.add inventory_units[i], :backordered }
92
- end
93
- package2 = pack do |package|
94
- 2.times { |i| package.add inventory_units[i] }
95
- end
96
-
97
- packages = [package1, package2]
98
- prioritizer = Prioritizer.new(inventory_units, packages)
99
- packages = prioritizer.prioritized_packages
100
-
101
- expect(packages[0].quantity(:backordered)).to eq 3
102
- expect(packages[1].quantity(:on_hand)).to eq 2
103
- end
104
-
105
- it '1st has backorder, 2nd has all' do
106
- 5.times { build_inventory_unit }
107
-
108
- package1 = pack do |package|
109
- 3.times { |i| package.add inventory_units[i], :backordered }
110
- end
111
- package2 = pack do |package|
112
- 5.times { |i| package.add inventory_units[i] }
113
- end
114
-
115
- packages = [package1, package2]
116
- prioritizer = Prioritizer.new(inventory_units, packages)
117
- packages = prioritizer.prioritized_packages
118
- expect(packages[0]).to eq package2
119
- expect(packages[1]).to be_nil
120
- expect(packages[0].quantity(:backordered)).to eq 0
121
- expect(packages[0].quantity(:on_hand)).to eq 5
122
- end
123
- end
124
- end
125
- end
@@ -1,126 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for 'unlimited supply' do
4
- it 'can_supply? any amount' do
5
- expect(subject.can_supply?(1)).to be true
6
- expect(subject.can_supply?(101)).to be true
7
- expect(subject.can_supply?(100_001)).to be true
8
- end
9
- end
10
-
11
- module Spree
12
- module Stock
13
- describe Quantifier, type: :model do
14
- before(:all) { Spree::StockLocation.destroy_all } # FIXME leaky database
15
-
16
- let!(:stock_location) { create :stock_location_with_items }
17
- let!(:stock_item) { stock_location.stock_items.order(:id).first }
18
-
19
- subject { described_class.new(stock_item.variant) }
20
-
21
- specify { expect(subject.stock_items).to eq([stock_item]) }
22
- specify { expect(subject.variant).to eq(stock_item.variant) }
23
-
24
- context 'with a single stock location/item' do
25
- it 'total_on_hand should match stock_item' do
26
- expect(subject.total_on_hand).to eq(stock_item.count_on_hand)
27
- end
28
-
29
- context 'when variant is available' do
30
- before(:each) do
31
- allow(subject.variant).to receive(:available?) { true }
32
- end
33
-
34
- context 'when track_inventory_levels is false' do
35
- before { configure_spree_preferences { |config| config.track_inventory_levels = false } }
36
-
37
- specify { expect(subject.total_on_hand).to eq(Float::INFINITY) }
38
-
39
- it_should_behave_like 'unlimited supply'
40
- end
41
-
42
- context 'when variant inventory tracking is off' do
43
- before { stock_item.variant.track_inventory = false }
44
-
45
- specify { expect(subject.total_on_hand).to eq(Float::INFINITY) }
46
-
47
- it_should_behave_like 'unlimited supply'
48
- end
49
-
50
- context 'when stock item allows backordering' do
51
-
52
- specify { expect(subject.backorderable?).to be true }
53
-
54
- it_should_behave_like 'unlimited supply'
55
- end
56
-
57
- context 'when stock item prevents backordering' do
58
- before { stock_item.update_attributes(backorderable: false) }
59
-
60
- specify { expect(subject.backorderable?).to be false }
61
-
62
- it 'can_supply? only upto total_on_hand' do
63
- expect(subject.can_supply?(1)).to be true
64
- expect(subject.can_supply?(10)).to be true
65
- expect(subject.can_supply?(11)).to be false
66
- end
67
- end
68
- end
69
-
70
- context 'when variant is not available' do
71
- before(:each) do
72
- allow(subject.variant).to receive(:available?) { false }
73
- end
74
-
75
- it { expect(subject.can_supply?).to be false }
76
- end
77
- end
78
-
79
- context 'with multiple stock locations/items' do
80
- let!(:stock_location_2) { create :stock_location }
81
- let!(:stock_location_3) { create :stock_location, active: false }
82
-
83
- before do
84
- stock_location_2.stock_items.where(variant_id: stock_item.variant).update_all(count_on_hand: 5, backorderable: false)
85
- stock_location_3.stock_items.where(variant_id: stock_item.variant).update_all(count_on_hand: 5, backorderable: false)
86
- end
87
-
88
- it 'total_on_hand should total all active stock_items' do
89
- expect(subject.total_on_hand).to eq(15)
90
- end
91
-
92
- context 'when variant is available' do
93
- before(:each) do
94
- allow(subject.variant).to receive(:available?) { true }
95
- end
96
-
97
- context 'when any stock item allows backordering' do
98
- specify { expect(subject.backorderable?).to be true }
99
-
100
- it_should_behave_like 'unlimited supply'
101
- end
102
-
103
- context 'when all stock items prevent backordering' do
104
- before { stock_item.update_attributes(backorderable: false) }
105
-
106
- specify { expect(subject.backorderable?).to be false }
107
-
108
- it 'can_supply? upto total_on_hand' do
109
- expect(subject.can_supply?(1)).to be true
110
- expect(subject.can_supply?(15)).to be true
111
- expect(subject.can_supply?(16)).to be false
112
- end
113
- end
114
- end
115
-
116
- context 'when variant is not available' do
117
- before(:each) do
118
- allow(subject.variant).to receive(:available?) { false }
119
- end
120
-
121
- it { expect(subject.can_supply?).to be false }
122
- end
123
- end
124
- end
125
- end
126
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- module Splitter
6
- describe Backordered, :type => :model do
7
- let(:variant) { build(:variant) }
8
-
9
- let(:packer) { build(:stock_packer) }
10
-
11
- subject { Backordered.new(packer) }
12
-
13
- it 'splits packages by status' do
14
- package = Package.new(packer.stock_location)
15
- 4.times { package.add build(:inventory_unit, variant: variant) }
16
- 5.times { package.add build(:inventory_unit, variant: variant), :backordered }
17
-
18
- packages = subject.split([package])
19
- expect(packages.count).to eq 2
20
- expect(packages.first.quantity).to eq 4
21
- expect(packages.first.on_hand.count).to eq 4
22
- expect(packages.first.backordered.count).to eq 0
23
-
24
- expect(packages[1].contents.count).to eq 5
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- module Splitter
6
- describe Base, :type => :model do
7
- let(:packer) { build(:stock_packer) }
8
-
9
- it 'continues to splitter chain' do
10
- splitter1 = Base.new(packer)
11
- splitter2 = Base.new(packer, splitter1)
12
- packages = []
13
-
14
- expect(splitter1).to receive(:split).with(packages)
15
- splitter2.split(packages)
16
- end
17
-
18
- end
19
- end
20
- end
21
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- module Splitter
6
- describe ShippingCategory, :type => :model do
7
-
8
- let(:variant1) { build(:variant) }
9
- let(:variant2) { build(:variant) }
10
- let(:shipping_category_1) { create(:shipping_category, name: 'A') }
11
- let(:shipping_category_2) { create(:shipping_category, name: 'B') }
12
-
13
- def inventory_unit1
14
- InventoryUnit.new(variant: variant1).tap do |inventory_unit|
15
- inventory_unit.variant.product.shipping_category = shipping_category_1
16
- end
17
- end
18
-
19
- def inventory_unit2
20
- InventoryUnit.new(variant: variant2).tap do |inventory_unit|
21
- inventory_unit.variant.product.shipping_category = shipping_category_2
22
- end
23
- end
24
-
25
- let(:packer) { build(:stock_packer) }
26
-
27
- subject { ShippingCategory.new(packer) }
28
-
29
- it 'splits each package by shipping category' do
30
- package1 = Package.new(packer.stock_location)
31
- 4.times { package1.add inventory_unit1 }
32
- 8.times { package1.add inventory_unit2 }
33
-
34
- package2 = Package.new(packer.stock_location)
35
- 6.times { package2.add inventory_unit1 }
36
- 9.times { package2.add inventory_unit2, :backordered }
37
-
38
- packages = subject.split([package1, package2])
39
- expect(packages[0].quantity).to eq 4
40
- expect(packages[1].quantity).to eq 8
41
- expect(packages[2].quantity).to eq 6
42
- expect(packages[3].quantity).to eq 9
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- module Splitter
6
- describe Weight, type: :model do
7
- let(:packer) { build(:stock_packer) }
8
- let(:heavy_variant) { build(:base_variant, weight: 100) }
9
- let(:variant) { build(:base_variant, weight: 49) }
10
-
11
- subject { Weight.new(packer) }
12
-
13
- it 'splits and keeps splitting until all packages are underweight' do
14
- package = Package.new(packer.stock_location)
15
- 2.times { package.add build(:inventory_unit, variant: heavy_variant) }
16
- 4.times { package.add build(:inventory_unit, variant: variant) }
17
- 2.times { package.add build(:inventory_unit, variant: heavy_variant) }
18
- packages = subject.split([package])
19
- expect(packages.size).to eq 4
20
- end
21
-
22
- it 'handles packages that can not be reduced' do
23
- package = Package.new(packer.stock_location)
24
- allow(variant).to receive_messages(weight: 200)
25
- 2.times { package.add build(:inventory_unit, variant: variant) }
26
- packages = subject.split([package])
27
- expect(packages.size).to eq 2
28
- end
29
- end
30
- end
31
- end
32
- end