spree_core 3.1.5 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Spree::Order, :type => :model do
5
- let(:order) { stub_model(Spree::Order) }
6
-
7
- context "#tax_zone" do
8
- let(:bill_address) { create :address }
9
- let(:ship_address) { create :address }
10
- let(:order) { Spree::Order.create(:ship_address => ship_address, :bill_address => bill_address) }
11
- let(:zone) { create :zone }
12
-
13
- context "when no zones exist" do
14
- it "should return nil" do
15
- expect(order.tax_zone).to be_nil
16
- end
17
- end
18
-
19
- context "when :tax_using_ship_address => true" do
20
- before { Spree::Config.set(:tax_using_ship_address => true) }
21
-
22
- it "should calculate using ship_address" do
23
- expect(Spree::Zone).to receive(:match).at_least(:once).with(ship_address)
24
- expect(Spree::Zone).not_to receive(:match).with(bill_address)
25
- order.tax_zone
26
- end
27
- end
28
-
29
- context "when :tax_using_ship_address => false" do
30
- before { Spree::Config.set(:tax_using_ship_address => false) }
31
-
32
- it "should calculate using bill_address" do
33
- expect(Spree::Zone).to receive(:match).at_least(:once).with(bill_address)
34
- expect(Spree::Zone).not_to receive(:match).with(ship_address)
35
- order.tax_zone
36
- end
37
- end
38
-
39
- context "when there is a default tax zone" do
40
- before do
41
- @default_zone = create(:zone, :name => "foo_zone")
42
- allow(Spree::Zone).to receive_messages :default_tax => @default_zone
43
- end
44
-
45
- context "when there is a matching zone" do
46
- before { allow(Spree::Zone).to receive_messages(:match => zone) }
47
-
48
- it "should return the matching zone" do
49
- expect(order.tax_zone).to eq(zone)
50
- end
51
- end
52
-
53
- context "when there is no matching zone" do
54
- before { allow(Spree::Zone).to receive_messages(:match => nil) }
55
-
56
- it "should return the default tax zone" do
57
- expect(order.tax_zone).to eq(@default_zone)
58
- end
59
- end
60
- end
61
-
62
- context "when no default tax zone" do
63
- before { allow(Spree::Zone).to receive_messages :default_tax => nil }
64
-
65
- context "when there is a matching zone" do
66
- before { allow(Spree::Zone).to receive_messages(:match => zone) }
67
-
68
- it "should return the matching zone" do
69
- expect(order.tax_zone).to eq(zone)
70
- end
71
- end
72
-
73
- context "when there is no matching zone" do
74
- before { allow(Spree::Zone).to receive_messages(:match => nil) }
75
-
76
- it "should return nil" do
77
- expect(order.tax_zone).to be_nil
78
- end
79
- end
80
- end
81
- end
82
-
83
- end
84
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Order, :type => :model do
5
- let(:order) { Order.create }
6
- let(:shirt) { create(:variant) }
7
-
8
- context "adds item to cart and activates promo" do
9
- let(:promotion) { Promotion.create name: 'Huhu' }
10
- let(:calculator) { Calculator::FlatPercentItemTotal.new(:preferred_flat_percent => 10) }
11
- let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
12
-
13
- before { order.contents.add(shirt, 1) }
14
-
15
- context "item quantity changes" do
16
- it "recalculates order adjustments" do
17
- expect {
18
- order.contents.add(shirt, 3)
19
- }.to change { order.adjustments.eligible.pluck(:amount) }
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Order, :type => :model do
4
- let(:order) { create(:order) }
5
-
6
- context "#update_with_updater!" do
7
- let(:line_items) { [mock_model(Spree::LineItem, :amount => 5) ]}
8
-
9
- context "when there are update hooks" do
10
- before { Spree::Order.register_update_hook :foo }
11
- after { Spree::Order.update_hooks.clear }
12
- it "should call each of the update hooks" do
13
- expect(order).to receive :foo
14
- order.update_with_updater!
15
- end
16
- end
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Spree::Order, :type => :model do
5
- context "validations" do
6
- # Regression test for #2214
7
- it "does not return two error messages when email is blank" do
8
- order = Spree::Order.new
9
- allow(order).to receive_messages(:require_email => true)
10
- order.valid?
11
- expect(order.errors[:email]).to eq(["can't be blank"])
12
- end
13
- end
14
- end
15
- end
@@ -1,297 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::OrderContents, :type => :model do
4
- let(:order) { Spree::Order.create }
5
- let(:variant) { create(:variant) }
6
-
7
- subject { described_class.new(order) }
8
-
9
- context "#add" do
10
- context 'given quantity is not explicitly provided' do
11
- it 'should add one line item' do
12
- line_item = subject.add(variant)
13
- expect(line_item.quantity).to eq(1)
14
- expect(order.line_items.size).to eq(1)
15
- end
16
- end
17
-
18
- context 'given a shipment' do
19
- it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do
20
- shipment = create(:shipment)
21
- expect(subject.order).to_not receive(:ensure_updated_shipments)
22
- expect(shipment).to receive(:update_amounts)
23
- subject.add(variant, 1, shipment: shipment)
24
- end
25
- end
26
-
27
- context 'not given a shipment' do
28
- it "ensures updated shipments" do
29
- expect(subject.order).to receive(:ensure_updated_shipments)
30
- subject.add(variant)
31
- end
32
- end
33
-
34
- it 'should add line item if one does not exist' do
35
- line_item = subject.add(variant, 1)
36
- expect(line_item.quantity).to eq(1)
37
- expect(order.line_items.size).to eq(1)
38
- end
39
-
40
- it 'should update line item if one exists' do
41
- subject.add(variant, 1)
42
- line_item = subject.add(variant, 1)
43
- expect(line_item.quantity).to eq(2)
44
- expect(order.line_items.size).to eq(1)
45
- end
46
-
47
- it "should update order totals" do
48
- expect(order.item_total.to_f).to eq(0.00)
49
- expect(order.total.to_f).to eq(0.00)
50
-
51
- subject.add(variant, 1)
52
-
53
- expect(order.item_total.to_f).to eq(19.99)
54
- expect(order.total.to_f).to eq(19.99)
55
- end
56
-
57
- context "running promotions" do
58
- let(:promotion) { create(:promotion) }
59
- let(:calculator) { Spree::Calculator::FlatRate.new(:preferred_amount => 10) }
60
-
61
- shared_context "discount changes order total" do
62
- before { subject.add(variant, 1) }
63
- it { expect(subject.order.total).not_to eq variant.price }
64
- end
65
-
66
- context "one active order promotion" do
67
- let!(:action) { Spree::Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
68
-
69
- it "creates valid discount on order" do
70
- subject.add(variant, 1)
71
- expect(subject.order.adjustments.to_a.sum(&:amount)).not_to eq 0
72
- end
73
-
74
- include_context "discount changes order total"
75
- end
76
-
77
- context "one active line item promotion" do
78
- let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
79
-
80
- it "creates valid discount on order" do
81
- subject.add(variant, 1)
82
- expect(subject.order.line_item_adjustments.to_a.sum(&:amount)).not_to eq 0
83
- end
84
-
85
- include_context "discount changes order total"
86
- end
87
-
88
- context "VAT for variant with percent promotion" do
89
- let!(:category) { Spree::TaxCategory.create name: "Taxable Foo" }
90
- let!(:rate) do
91
- Spree::TaxRate.create(
92
- amount: 0.25,
93
- included_in_price: true,
94
- calculator: Spree::Calculator::DefaultTax.create,
95
- tax_category: category,
96
- zone: create(:zone_with_country, default_tax: true)
97
- )
98
- end
99
- let(:variant) { create(:variant, price: 1000) }
100
- let(:calculator) { Spree::Calculator::PercentOnLineItem.new(:preferred_percent => 50) }
101
- let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
102
-
103
- it "should update included_tax_total" do
104
- expect(order.included_tax_total.to_f).to eq(0.00)
105
- subject.add(variant, 1)
106
- expect(order.included_tax_total.to_f).to eq(100)
107
- end
108
-
109
- it "should update included_tax_total after adding two line items" do
110
- subject.add(variant, 1)
111
- expect(order.included_tax_total.to_f).to eq(100)
112
- subject.add(variant, 1)
113
- expect(order.included_tax_total.to_f).to eq(200)
114
- end
115
- end
116
- end
117
- end
118
-
119
- context "#remove" do
120
- context "given an invalid variant" do
121
- it "raises an exception" do
122
- expect {
123
- subject.remove(variant, 1)
124
- }.to raise_error(ActiveRecord::RecordNotFound)
125
- end
126
- end
127
-
128
- context 'given quantity is not explicitly provided' do
129
- it 'should remove one line item' do
130
- line_item = subject.add(variant, 3)
131
- subject.remove(variant)
132
-
133
- expect(line_item.quantity).to eq(2)
134
- end
135
- end
136
-
137
- context 'given a shipment' do
138
- it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do
139
- line_item = subject.add(variant, 1)
140
- shipment = create(:shipment)
141
- expect(subject.order).to_not receive(:ensure_updated_shipments)
142
- expect(shipment).to receive(:update_amounts)
143
- subject.remove(variant, 1, shipment: shipment)
144
- end
145
- end
146
-
147
- context 'not given a shipment' do
148
- it "ensures updated shipments" do
149
- line_item = subject.add(variant, 1)
150
- expect(subject.order).to receive(:ensure_updated_shipments)
151
- subject.remove(variant)
152
- end
153
- end
154
-
155
- it 'should reduce line_item quantity if quantity is less the line_item quantity' do
156
- line_item = subject.add(variant, 3)
157
- subject.remove(variant, 1)
158
-
159
- expect(line_item.quantity).to eq(2)
160
- end
161
-
162
- it 'should remove line_item if quantity matches line_item quantity' do
163
- subject.add(variant, 1)
164
- removed_line_item = subject.remove(variant, 1)
165
-
166
- # Should reflect the change already in Order#line_item
167
- expect(order.line_items).to_not include(removed_line_item)
168
- end
169
-
170
- it "should update order totals" do
171
- expect(order.item_total.to_f).to eq(0.00)
172
- expect(order.total.to_f).to eq(0.00)
173
-
174
- subject.add(variant,2)
175
-
176
- expect(order.item_total.to_f).to eq(39.98)
177
- expect(order.total.to_f).to eq(39.98)
178
-
179
- subject.remove(variant,1)
180
- expect(order.item_total.to_f).to eq(19.99)
181
- expect(order.total.to_f).to eq(19.99)
182
- end
183
- end
184
-
185
- context "#remove_line_item" do
186
- context 'given a shipment' do
187
- it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do
188
- line_item = subject.add(variant, 1)
189
- shipment = create(:shipment)
190
- expect(subject.order).to_not receive(:ensure_updated_shipments)
191
- expect(shipment).to receive(:update_amounts)
192
- subject.remove_line_item(line_item, shipment: shipment)
193
- end
194
- end
195
-
196
- context 'not given a shipment' do
197
- it "ensures updated shipments" do
198
- line_item = subject.add(variant, 1)
199
- expect(subject.order).to receive(:ensure_updated_shipments)
200
- subject.remove_line_item(line_item)
201
- end
202
- end
203
-
204
- it 'should remove line_item' do
205
- line_item = subject.add(variant, 1)
206
- subject.remove_line_item(line_item)
207
-
208
- expect(order.reload.line_items).to_not include(line_item)
209
- end
210
-
211
- it "should update order totals" do
212
- expect(order.item_total.to_f).to eq(0.00)
213
- expect(order.total.to_f).to eq(0.00)
214
-
215
- line_item = subject.add(variant,2)
216
-
217
- expect(order.item_total.to_f).to eq(39.98)
218
- expect(order.total.to_f).to eq(39.98)
219
-
220
- subject.remove_line_item(line_item)
221
- expect(order.item_total.to_f).to eq(0.00)
222
- expect(order.total.to_f).to eq(0.00)
223
- end
224
- end
225
-
226
- context "update cart" do
227
- let!(:shirt) { subject.add variant, 1 }
228
-
229
- let(:params) do
230
- { line_items_attributes: {
231
- "0" => { id: shirt.id, quantity: 3 }
232
- } }
233
- end
234
-
235
- it "changes item quantity" do
236
- subject.update_cart params
237
- expect(shirt.quantity).to eq 3
238
- end
239
-
240
- it "updates order totals" do
241
- expect {
242
- subject.update_cart params
243
- }.to change { subject.order.total }
244
- end
245
-
246
- context "submits item quantity 0" do
247
- let(:params) do
248
- { line_items_attributes: {
249
- "0" => { id: shirt.id, quantity: 0 },
250
- "1" => { id: "666", quantity: 0}
251
- } }
252
- end
253
-
254
- it "removes item from order" do
255
- expect {
256
- subject.update_cart params
257
- }.to change { subject.order.line_items.count }
258
- end
259
-
260
- it "doesnt try to update unexistent items" do
261
- filtered_params = { line_items_attributes: {
262
- "0" => { id: shirt.id, quantity: 0 },
263
- } }
264
- expect(subject.order).to receive(:update_attributes).with(filtered_params)
265
- subject.update_cart params
266
- end
267
-
268
- it "should not filter if there is only one line item" do
269
- single_line_item_params = { line_items_attributes: { id: shirt.id, quantity: 0 } }
270
- expect(subject.order).to receive(:update_attributes).with(single_line_item_params)
271
- subject.update_cart single_line_item_params
272
- end
273
-
274
- end
275
-
276
- it "ensures updated shipments" do
277
- expect(subject.order).to receive(:ensure_updated_shipments)
278
- subject.update_cart params
279
- end
280
- end
281
-
282
- context "completed order" do
283
- let(:order) { create(:order, state: 'complete', completed_at: Time.current) }
284
-
285
- before { order.shipments.create! stock_location_id: variant.stock_location_ids.first }
286
-
287
- it "updates order payment state" do
288
- expect {
289
- subject.add variant
290
- }.to change { order.payment_state }
291
-
292
- expect {
293
- subject.remove variant
294
- }.to change { order.payment_state }
295
- end
296
- end
297
- end
@@ -1,238 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::OrderInventory, type: :model do
4
- let(:order) { create :completed_order_with_totals }
5
- let(:line_item) { order.line_items.first }
6
-
7
- subject { described_class.new(order, line_item) }
8
-
9
- describe 'delegate' do
10
- it { is_expected.to delegate_method(:inventory_units).to(:line_item) }
11
- end
12
-
13
- context "when order is missing inventory units" do
14
- before { line_item.update_column(:quantity, 2) }
15
-
16
- it 'creates the proper number of inventory units' do
17
- subject.verify
18
- expect(subject.inventory_units.count).to eq 2
19
- end
20
- end
21
-
22
- context "#add_to_shipment" do
23
- let(:shipment) { order.shipments.first }
24
-
25
- context "order is not completed" do
26
- before { allow(order).to receive_messages completed?: false }
27
-
28
- it "doesn't unstock items" do
29
- expect(shipment.stock_location).not_to receive(:unstock)
30
- expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
31
- end
32
- end
33
-
34
- context "inventory units state" do
35
- before { shipment.inventory_units.destroy_all }
36
-
37
- it 'sets inventory_units state as per stock location availability' do
38
- expect(shipment.stock_location).to receive(:fill_status).with(subject.variant, 5).and_return([3, 2])
39
-
40
- expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
41
-
42
- units = shipment.inventory_units_for(subject.variant).group_by(&:state)
43
- expect(units['backordered'].size).to eq(2)
44
- expect(units['on_hand'].size).to eq(3)
45
- end
46
- end
47
-
48
- context "store doesnt track inventory" do
49
- let(:variant) { create(:variant) }
50
-
51
- before { Spree::Config.track_inventory_levels = false }
52
-
53
- it "creates only on hand inventory units" do
54
- variant.stock_items.destroy_all
55
-
56
- # The before_save callback in LineItem would verify inventory
57
- line_item = order.contents.add variant, 1, shipment: shipment
58
-
59
- units = shipment.inventory_units_for(line_item.variant)
60
- expect(units.count).to eq 1
61
- expect(units.first).to be_on_hand
62
- end
63
- end
64
-
65
- context "variant doesnt track inventory" do
66
- let(:variant) { create(:variant) }
67
- before { variant.track_inventory = false }
68
-
69
- it "creates only on hand inventory units" do
70
- variant.stock_items.destroy_all
71
-
72
- line_item = order.contents.add variant, 1
73
- subject.verify(shipment)
74
-
75
- units = shipment.inventory_units_for(line_item.variant)
76
- expect(units.count).to eq 1
77
- expect(units.first).to be_on_hand
78
- end
79
- end
80
-
81
- it 'should create stock_movement' do
82
- expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
83
-
84
- stock_item = shipment.stock_location.stock_item(subject.variant)
85
- movement = stock_item.stock_movements.last
86
- # movement.originator.should == shipment
87
- expect(movement.quantity).to eq(-5)
88
- end
89
- end
90
-
91
- context "#determine_target_shipment" do
92
- let(:stock_location) { create :stock_location }
93
- let(:variant) { line_item.variant }
94
-
95
- before do
96
- subject.verify
97
-
98
- order.shipments.create(stock_location_id: stock_location.id, cost: 5)
99
-
100
- shipped = order.shipments.create(stock_location_id: order.shipments.first.stock_location.id, cost: 10)
101
- shipped.update_column(:state, 'shipped')
102
- end
103
-
104
- it 'should select first non-shipped shipment that already contains given variant' do
105
- shipment = subject.send(:determine_target_shipment)
106
- expect(shipment.shipped?).to be false
107
- expect(shipment.inventory_units_for(variant)).not_to be_empty
108
-
109
- expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
110
- end
111
-
112
- context "when no shipments already contain this varint" do
113
- before do
114
- subject.line_item.reload
115
- subject.inventory_units.destroy_all
116
- end
117
-
118
- it 'selects first non-shipped shipment that leaves from same stock_location' do
119
- shipment = subject.send(:determine_target_shipment)
120
- shipment.reload
121
- expect(shipment.shipped?).to be false
122
- expect(shipment.inventory_units_for(variant)).to be_empty
123
- expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
124
- end
125
- end
126
- end
127
-
128
- context 'when order has too many inventory units' do
129
- before do
130
- line_item.quantity = 3
131
- line_item.save!
132
-
133
- line_item.update_column(:quantity, 2)
134
- subject.line_item.reload
135
- end
136
-
137
- it 'should be a messed up order' do
138
- expect(order.shipments.first.inventory_units_for(line_item.variant).size).to eq(3)
139
- expect(line_item.quantity).to eq(2)
140
- end
141
-
142
- it 'should decrease the number of inventory units' do
143
- subject.verify
144
- expect(subject.inventory_units.count).to eq 2
145
- end
146
-
147
- context '#remove_from_shipment' do
148
- let(:shipment) { order.shipments.first }
149
- let(:variant) { subject.variant }
150
-
151
- context "order is not completed" do
152
- before { allow(order).to receive_messages completed?: false }
153
-
154
- it "doesn't restock items" do
155
- expect(shipment.stock_location).not_to receive(:restock)
156
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
157
- end
158
- end
159
-
160
- it 'should create stock_movement' do
161
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
162
-
163
- stock_item = shipment.stock_location.stock_item(variant)
164
- movement = stock_item.stock_movements.last
165
- # movement.originator.should == shipment
166
- expect(movement.quantity).to eq(1)
167
- end
168
-
169
- it 'should destroy backordered units first' do
170
- allow(shipment).to receive_messages(
171
- inventory_units_for_item: [
172
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'backordered', shipped?: false),
173
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand', shipped?: false),
174
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'backordered', shipped?: false)
175
- ]
176
- )
177
-
178
- expect(shipment.inventory_units_for_item[0]).to receive(:destroy)
179
- expect(shipment.inventory_units_for_item[1]).not_to receive(:destroy)
180
- expect(shipment.inventory_units_for_item[2]).to receive(:destroy)
181
-
182
- expect(subject.send(:remove_from_shipment, shipment, 2)).to eq(2)
183
- end
184
-
185
- it 'should destroy unshipped units first' do
186
- allow(shipment).to receive_messages(
187
- inventory_units_for_item: [
188
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'shipped', shipped?: true),
189
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand', shipped?: false)
190
- ]
191
- )
192
-
193
- expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
194
- expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
195
-
196
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
197
- end
198
-
199
- it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
200
- allow(shipment).to receive_messages(
201
- inventory_units_for_item: [
202
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'shipped', shipped?: true),
203
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand', shipped?: false)
204
- ]
205
- )
206
-
207
- expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
208
- expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
209
-
210
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
211
- end
212
-
213
- it 'should destroy self if not inventory units remain' do
214
- allow(shipment.inventory_units).to receive_messages(count: 0)
215
- expect(shipment).to receive(:destroy)
216
-
217
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
218
- end
219
-
220
- context "inventory unit line item and variant points to different products" do
221
- let(:different_line_item) { create(:line_item) }
222
-
223
- let!(:different_inventory) do
224
- shipment.set_up_inventory("on_hand", variant, order, different_line_item)
225
- end
226
-
227
- context "completed order" do
228
- before { order.touch :completed_at }
229
-
230
- it "removes only units that match both line item and variant" do
231
- subject.send(:remove_from_shipment, shipment, shipment.inventory_units.count)
232
- expect(different_inventory.reload).to be_persisted
233
- end
234
- end
235
- end
236
- end
237
- end
238
- end