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,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class FakesController < ApplicationController
4
- include Spree::Core::ControllerHelpers::Auth
5
- include Spree::Core::ControllerHelpers::Order
6
- include Spree::Core::ControllerHelpers::Store
7
- end
8
-
9
- describe Spree::Core::ControllerHelpers::Store, type: :controller do
10
- controller(FakesController) {}
11
-
12
- describe '#current_store' do
13
- let!(:store) { create :store, default: true }
14
- it 'returns current store' do
15
- expect(controller.current_store).to eq store
16
- end
17
- end
18
-
19
- describe "#current_price_options" do
20
- subject(:current_price_options) { controller.current_price_options }
21
-
22
- context "when there is a default tax zone" do
23
- let(:default_zone) { Spree::Zone.new }
24
-
25
- before do
26
- allow(Spree::Zone).to receive(:default_tax).and_return(default_zone)
27
- end
28
-
29
- context "when there is no current order" do
30
- it "returns the default tax zone" do
31
- is_expected.to include(tax_zone: default_zone)
32
- end
33
- end
34
-
35
- context "when there is a current order" do
36
- let(:other_zone) { Spree::Zone.new }
37
- let(:current_order) { Spree::Order.new }
38
-
39
- before do
40
- allow(current_order).to receive(:tax_zone).and_return(other_zone)
41
- allow(controller).to receive(:current_order).and_return(current_order)
42
- end
43
-
44
- it { is_expected.to include(tax_zone: other_zone) }
45
- end
46
- end
47
-
48
- context "when there is no default tax zone" do
49
- before do
50
- allow(Spree::Zone).to receive(:default_tax).and_return(nil)
51
- end
52
-
53
- context "when there is no current order" do
54
- it "return nil when asked for the current tax zone" do
55
- expect(current_price_options[:tax_zone]).to be_nil
56
- end
57
- end
58
-
59
- context "when there is a current order" do
60
- let(:other_zone) { Spree::Zone.new }
61
- let(:current_order) { Spree::Order.new }
62
-
63
- before do
64
- allow(current_order).to receive(:tax_zone).and_return(other_zone)
65
- allow(controller).to receive(:current_order).and_return(current_order)
66
- end
67
-
68
- it { is_expected.to include(tax_zone: other_zone) }
69
- end
70
- end
71
- end
72
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class FakesController < ApplicationController
4
- include Spree::Core::ControllerHelpers::StrongParameters
5
- end
6
-
7
- describe Spree::Core::ControllerHelpers::StrongParameters, type: :controller do
8
- controller(FakesController) {}
9
-
10
- describe '#permitted_attributes' do
11
- it 'returns Spree::PermittedAttributes module' do
12
- expect(controller.permitted_attributes).to eq Spree::PermittedAttributes
13
- end
14
- end
15
-
16
- describe '#permitted_payment_attributes' do
17
- it 'returns Array class' do
18
- expect(controller.permitted_payment_attributes.class).to eq Array
19
- end
20
- end
21
-
22
- describe '#permitted_checkout_attributes' do
23
- it 'returns Array class' do
24
- expect(controller.permitted_checkout_attributes.class).to eq Array
25
- end
26
- end
27
-
28
- describe '#permitted_order_attributes' do
29
- it 'returns Array class' do
30
- expect(controller.permitted_order_attributes.class).to eq Array
31
- end
32
- end
33
-
34
- describe '#permitted_product_attributes' do
35
- it 'returns Array class' do
36
- expect(controller.permitted_product_attributes.class).to eq Array
37
- end
38
- end
39
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # This is a bit of a insane spec I have to admit
4
- # Chosed the spree_payment_methods table because it has a `name` column
5
- # already. Stubs wouldn't work here (the delegation runs before this spec is
6
- # loaded) and adding a column here might make the test even crazy so here we go
7
- module Spree
8
- class DelegateBelongsToStubModel < Spree::Base
9
- self.table_name = "spree_payment_methods"
10
- belongs_to :product
11
- delegate_belongs_to :product, :name
12
- end
13
-
14
- describe DelegateBelongsToStubModel do
15
- context "model has column attr delegated to associated object" do
16
- it "doesnt touch the associated object" do
17
- expect(subject).not_to receive(:product)
18
- subject.name
19
- end
20
- end
21
- end
22
- end
@@ -1,605 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Core
5
- describe Importer::Order do
6
- let!(:country) { create(:country) }
7
- let!(:state) { country.states.first || create(:state, country: country) }
8
- let!(:stock_location) { create(:stock_location, admin_name: 'Admin Name') }
9
-
10
- let(:user) { stub_model(LegacyUser, email: 'fox@mudler.com') }
11
- let(:shipping_method) { create(:shipping_method) }
12
- let(:payment_method) { create(:check_payment_method) }
13
-
14
- let(:product) do
15
- product = Spree::Product.create(name: 'Test',
16
- sku: 'TEST-1',
17
- price: 33.22, available_on: Time.current - 1.day)
18
- product.shipping_category = create(:shipping_category)
19
- product.save
20
- product
21
- end
22
-
23
- let(:variant) do
24
- variant = product.master
25
- variant.stock_items.each { |si| si.update_attribute(:count_on_hand, 10) }
26
- variant
27
- end
28
-
29
- let(:sku) { variant.sku }
30
- let(:variant_id) { variant.id }
31
-
32
- let(:line_items) { [{ variant_id: variant.id, quantity: 5 }] }
33
- let(:ship_address) do
34
- {
35
- address1: '123 Testable Way',
36
- firstname: 'Fox',
37
- lastname: 'Mulder',
38
- city: 'Washington',
39
- country_id: country.id,
40
- state_id: state.id,
41
- zipcode: '66666',
42
- phone: '666-666-6666'
43
- }
44
- end
45
-
46
- it 'can import an order number' do
47
- params = { number: '123-456-789' }
48
- order = Importer::Order.import(user, params)
49
- expect(order.number).to eq '123-456-789'
50
- end
51
-
52
- it 'optionally add completed at' do
53
- params = {
54
- email: 'test@test.com',
55
- completed_at: Time.current,
56
- line_items_attributes: line_items
57
- }
58
-
59
- order = Importer::Order.import(user, params)
60
- expect(order).to be_completed
61
- expect(order.state).to eq 'complete'
62
- end
63
-
64
- it "assigns order[email] over user email to order" do
65
- params = { email: 'wooowww@test.com' }
66
- order = Importer::Order.import(user, params)
67
- expect(order.email).to eq params[:email]
68
- end
69
-
70
- context "assigning a user to an order" do
71
- let(:other_user) { stub_model(LegacyUser, email: 'dana@scully.com') }
72
-
73
- context "as an admin" do
74
- before { allow(user).to receive_messages has_spree_role?: true }
75
-
76
- context "a user's id is not provided" do
77
- # this is a regression spec for an issue we ran into at Bonobos
78
- it "doesn't unassociate the admin from the order" do
79
- params = {}
80
- order = Importer::Order.import(user, params)
81
- expect(order.user_id).to eq(user.id)
82
- end
83
- end
84
- end
85
-
86
- context "as a user" do
87
- before { allow(user).to receive_messages has_spree_role?: false }
88
- it "does not assign the order to the other user" do
89
- params = { user_id: other_user.id }
90
- order = Importer::Order.import(user, params)
91
- expect(order.user_id).to eq(user.id)
92
- end
93
- end
94
- end
95
-
96
- it 'can build an order from API with just line items' do
97
- params = { line_items_attributes: line_items }
98
-
99
- expect(Importer::Order).to receive(:ensure_variant_id_from_params).and_return(variant_id: variant.id,
100
- quantity: 5)
101
- order = Importer::Order.import(user, params)
102
- expect(order.user).to eq(nil)
103
- line_item = order.line_items.first
104
- expect(line_item.quantity).to eq(5)
105
- expect(line_item.variant_id).to eq(variant_id)
106
- end
107
-
108
- it 'handles line_item building exceptions' do
109
- line_items.first[:variant_id] = 'XXX'
110
- params = { line_items_attributes: line_items }
111
-
112
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
113
- end
114
-
115
- it 'handles line_item updating exceptions' do
116
- line_items.first[:currency] = 'GBP'
117
- params = { line_items_attributes: line_items }
118
-
119
- expect { Importer::Order.import(user, params) }.to raise_error /Validation failed/
120
- end
121
-
122
- it 'can build an order from API with variant sku' do
123
- params = { line_items_attributes: [{ sku: sku, quantity: 5 }] }
124
-
125
- order = Importer::Order.import(user, params)
126
-
127
- line_item = order.line_items.first
128
- expect(line_item.variant_id).to eq(variant_id)
129
- expect(line_item.quantity).to eq(5)
130
- end
131
-
132
- it 'handles exceptions when sku is not found' do
133
- params = { line_items_attributes: [{ sku: 'XXX', quantity: 5 }] }
134
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
135
- end
136
-
137
- it 'can build an order from API shipping address' do
138
- params = {
139
- ship_address_attributes: ship_address,
140
- line_items_attributes: line_items
141
- }
142
-
143
- order = Importer::Order.import(user, params)
144
- expect(order.ship_address.address1).to eq '123 Testable Way'
145
- end
146
-
147
- it 'can build an order from API with country attributes' do
148
- ship_address.delete(:country_id)
149
- ship_address[:country] = { 'iso' => 'US' }
150
- params = {
151
- ship_address_attributes: ship_address,
152
- line_items_attributes: line_items
153
- }
154
-
155
- order = Importer::Order.import(user, params)
156
- expect(order.ship_address.country.iso).to eq 'US'
157
- end
158
-
159
- it 'handles country lookup exceptions' do
160
- ship_address.delete(:country_id)
161
- ship_address[:country] = { 'iso' => 'XXX' }
162
- params = {
163
- ship_address_attributes: ship_address,
164
- line_items_attributes: line_items
165
- }
166
-
167
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
168
- end
169
-
170
- it 'can build an order from API with state attributes' do
171
- ship_address.delete(:state_id)
172
- ship_address[:state] = { 'name' => state.name }
173
- params = {
174
- ship_address_attributes: ship_address,
175
- line_items_attributes: line_items
176
- }
177
-
178
- order = Importer::Order.import(user, params)
179
- expect(order.ship_address.state.name).to eq state.name
180
- end
181
-
182
- context "with a different currency" do
183
- before { variant.price_in("GBP").update_attribute(:price, 18.99) }
184
-
185
- it "sets the order currency" do
186
- params = { currency: "GBP" }
187
- order = Importer::Order.import(user, params)
188
- expect(order.currency).to eq "GBP"
189
- end
190
-
191
- it "can handle it when a line order price is specified" do
192
- params = {
193
- currency: "GBP",
194
- line_items_attributes: line_items
195
- }
196
- line_items.first.merge! currency: "GBP", price: 1.99
197
- order = Importer::Order.import(user, params)
198
- expect(order.currency).to eq "GBP"
199
- expect(order.line_items.first.price).to eq 1.99
200
- expect(order.line_items.first.currency).to eq "GBP"
201
- end
202
- end
203
-
204
- context "state passed is not associated with country" do
205
- let(:params) do
206
- {
207
- ship_address_attributes: ship_address,
208
- line_items_attributes: line_items
209
- }
210
- end
211
-
212
- let(:other_state) { create(:state, name: "Uhuhuh", country: create(:country)) }
213
-
214
- before do
215
- ship_address.delete(:state_id)
216
- ship_address[:state] = { 'name' => other_state.name }
217
- end
218
-
219
- it 'sets states name instead of state id' do
220
- order = Importer::Order.import(user, params)
221
- expect(order.ship_address.state_name).to eq other_state.name
222
- end
223
- end
224
-
225
- it 'sets state name if state record not found' do
226
- ship_address.delete(:state_id)
227
- ship_address[:state] = { 'name' => 'XXX' }
228
- params = {
229
- ship_address_attributes: ship_address,
230
- line_items_attributes: line_items
231
- }
232
-
233
- order = Importer::Order.import(user, params)
234
- expect(order.ship_address.state_name).to eq 'XXX'
235
- end
236
-
237
- context 'variant not deleted' do
238
- it 'ensures variant id from api' do
239
- hash = { sku: variant.sku }
240
- Importer::Order.ensure_variant_id_from_params(hash)
241
- expect(hash[:variant_id]).to eq variant.id
242
- end
243
- end
244
-
245
- context 'variant was deleted' do
246
- it 'raise error as variant shouldnt be found' do
247
- variant.product.destroy
248
- hash = { sku: variant.sku }
249
- expect { Importer::Order.ensure_variant_id_from_params(hash) }.to raise_error("Ensure order import variant: Variant w/SKU #{ hash[:sku] } not found.")
250
- end
251
- end
252
-
253
- it 'ensures_country_id for country fields' do
254
- [:name, :iso, :iso_name, :iso3].each do |field|
255
- address = { country: { field => country.send(field) } }
256
- Importer::Order.ensure_country_id_from_params(address)
257
- expect(address[:country_id]).to eq country.id
258
- end
259
- end
260
-
261
- it "raises with proper message when cant find country" do
262
- address = { country: { "name" => "NoNoCountry" } }
263
- expect { Importer::Order.ensure_country_id_from_params(address) }.to raise_error /NoNoCountry/
264
- end
265
-
266
- it 'ensures_state_id for state fields' do
267
- [:name, :abbr].each do |field|
268
- address = { country_id: country.id, state: { field => state.send(field) } }
269
- Importer::Order.ensure_state_id_from_params(address)
270
- expect(address[:state_id]).to eq state.id
271
- end
272
- end
273
-
274
- context "shipments" do
275
- let(:params) do
276
- {
277
- line_items_attributes: line_items,
278
- shipments_attributes: [
279
- {
280
- tracking: '123456789',
281
- cost: '14.99',
282
- shipping_method: shipping_method.name,
283
- stock_location: stock_location.name,
284
- inventory_units: 3.times.map { { sku: sku } }
285
- },
286
- {
287
- tracking: '123456789',
288
- cost: '14.99',
289
- shipping_method: shipping_method.name,
290
- stock_location: stock_location.name,
291
- inventory_units: 2.times.map { { sku: sku } }
292
- }
293
- ]
294
- }
295
- end
296
-
297
- it 'ensures variant exists and is not deleted' do
298
- expect(Importer::Order).to receive(:ensure_variant_id_from_params).exactly(6).times { line_items.first }
299
- Importer::Order.import(user, params)
300
- end
301
-
302
- it 'builds them properly' do
303
- order = Importer::Order.import(user, params)
304
- shipment = order.shipments.first
305
-
306
- expect(shipment.cost.to_f).to eq 14.99
307
- expect(shipment.inventory_units.first.variant_id).to eq product.master.id
308
- expect(shipment.tracking).to eq '123456789'
309
- expect(shipment.shipping_rates.first.cost).to eq 14.99
310
- expect(shipment.selected_shipping_rate).to eq(shipment.shipping_rates.first)
311
- expect(shipment.stock_location).to eq stock_location
312
- expect(order.shipment_total.to_f).to eq 29.98
313
- end
314
-
315
- it "allocates inventory units to the correct shipments" do
316
- order = Importer::Order.import(user, params)
317
-
318
- expect(order.inventory_units.count).to eq 5
319
- expect(order.shipments.first.inventory_units.count).to eq 3
320
- expect(order.shipments.last.inventory_units.count).to eq 2
321
- end
322
-
323
- it "accepts admin name for stock location" do
324
- params[:shipments_attributes][0][:stock_location] = stock_location.admin_name
325
- order = Importer::Order.import(user, params)
326
- shipment = order.shipments.first
327
-
328
- expect(shipment.stock_location).to eq stock_location
329
- end
330
-
331
- it "raises if cant find stock location" do
332
- params[:shipments_attributes][0][:stock_location] = "doesnt exist"
333
- expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
334
- end
335
-
336
- context 'when a shipping adjustment is present' do
337
- it 'creates the shipping adjustment' do
338
- adjustment_attributes = [{ label: 'Shipping Discount', amount: -5.00 }]
339
- params[:shipments_attributes][0][:adjustments_attributes] = adjustment_attributes
340
- order = Importer::Order.import(user, params)
341
- shipment = order.shipments.first
342
-
343
- expect(shipment.adjustments.first.label).to eq('Shipping Discount')
344
- expect(shipment.adjustments.first.amount).to eq(-5.00)
345
- end
346
- end
347
-
348
- context 'when completed_at and shipped_at present' do
349
- let(:params) do
350
- {
351
- completed_at: 2.days.ago,
352
- line_items_attributes: line_items,
353
- shipments_attributes: [
354
- {
355
- tracking: '123456789',
356
- cost: '4.99',
357
- shipped_at: 1.day.ago,
358
- shipping_method: shipping_method.name,
359
- stock_location: stock_location.name,
360
- inventory_units: [{ sku: sku }]
361
- }
362
- ]
363
- }
364
- end
365
-
366
- it 'builds them properly' do
367
- order = Importer::Order.import(user, params)
368
- shipment = order.shipments.first
369
-
370
- expect(shipment.cost.to_f).to eq 4.99
371
- expect(shipment.inventory_units.first.variant_id).to eq product.master.id
372
- expect(shipment.tracking).to eq '123456789'
373
- expect(shipment.shipped_at).to be_present
374
- expect(shipment.shipping_rates.first.cost).to eq 4.99
375
- expect(shipment.selected_shipping_rate).to eq(shipment.shipping_rates.first)
376
- expect(shipment.stock_location).to eq stock_location
377
- expect(shipment.state).to eq('shipped')
378
- expect(shipment.inventory_units.all?(&:shipped?)).to be true
379
- expect(order.shipment_state).to eq('shipped')
380
- expect(order.shipment_total.to_f).to eq 4.99
381
- end
382
- end
383
- end
384
-
385
- it 'handles shipment building exceptions' do
386
- params = {
387
- shipments_attributes: [
388
- {
389
- tracking: '123456789',
390
- cost: '4.99',
391
- shipping_method: 'XXX',
392
- inventory_units: [{ sku: sku }]
393
- }
394
- ]
395
- }
396
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
397
- end
398
-
399
- it 'adds adjustments' do
400
- params = {
401
- adjustments_attributes: [
402
- {
403
- label: 'Shipping Discount',
404
- amount: -4.99
405
- },
406
- {
407
- label: 'Promotion Discount',
408
- amount: -3.00
409
- }
410
- ]
411
- }
412
-
413
- order = Importer::Order.import(user, params)
414
- expect(order.adjustments.all?(&:closed?)).to be true
415
- expect(order.adjustments.first.label).to eq 'Shipping Discount'
416
- expect(order.adjustments.first.amount).to eq -4.99
417
- end
418
-
419
- it 'adds line item adjustments from promotion' do
420
- line_items.first[:adjustments_attributes] = [
421
- {
422
- label: 'Line Item Discount',
423
- amount: -4.99,
424
- promotion: true
425
- }
426
- ]
427
- params = {
428
- line_items_attributes: line_items,
429
- adjustments_attributes: [
430
- { label: 'Order Discount', amount: -5.99 }
431
- ]
432
- }
433
-
434
- order = Importer::Order.import(user, params)
435
- line_item_adjustment = order.line_item_adjustments.first
436
- expect(line_item_adjustment.closed?).to be true
437
- expect(line_item_adjustment.label).to eq 'Line Item Discount'
438
- expect(line_item_adjustment.amount).to eq -4.99
439
- expect(order.line_items.first.adjustment_total).to eq -4.99
440
- end
441
-
442
- it 'adds line item adjustments from taxation' do
443
- line_items.first[:adjustments_attributes] = [
444
- { label: 'Line Item Tax', amount: -4.99, tax: true }
445
- ]
446
- params = {
447
- line_items_attributes: line_items,
448
- adjustments_attributes: [
449
- { label: 'Order Discount', amount: -5.99 }
450
- ]
451
- }
452
-
453
- order = Importer::Order.import(user, params)
454
-
455
- line_item_adjustment = order.line_item_adjustments.first
456
- expect(line_item_adjustment.closed?).to be true
457
- expect(line_item_adjustment.label).to eq 'Line Item Tax'
458
- expect(line_item_adjustment.amount).to eq -4.99
459
- expect(order.line_items.first.adjustment_total).to eq -4.99
460
- end
461
-
462
- it "calculates final order total correctly" do
463
- params = {
464
- adjustments_attributes: [
465
- { label: 'Promotion Discount', amount: -3.00 }
466
- ],
467
- line_items_attributes: [
468
- {
469
- variant_id: variant.id,
470
- quantity: 5
471
- }
472
- ]
473
- }
474
-
475
- order = Importer::Order.import(user, params)
476
- expect(order.item_total).to eq(166.1)
477
- expect(order.total).to eq(163.1) # = item_total (166.1) - adjustment_total (3.00)
478
- end
479
-
480
- it 'handles adjustment building exceptions' do
481
- params = {
482
- adjustments_attributes: [
483
- {
484
- amount: 'XXX'
485
- },
486
- {
487
- label: 'Promotion Discount',
488
- amount: '-3.00'
489
- }
490
- ]
491
- }
492
-
493
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
494
- end
495
-
496
- it 'builds a payment using state' do
497
- params = {
498
- payments_attributes: [
499
- {
500
- amount: '4.99',
501
- payment_method: payment_method.name,
502
- state: 'completed'
503
- }
504
- ]
505
- }
506
- order = Importer::Order.import(user, params)
507
- expect(order.payments.first.amount).to eq 4.99
508
- end
509
-
510
- it 'builds a payment using status as fallback' do
511
- params = {
512
- payments_attributes: [
513
- {
514
- amount: '4.99',
515
- payment_method: payment_method.name,
516
- status: 'completed'
517
- }
518
- ]
519
- }
520
- order = Importer::Order.import(user, params)
521
- expect(order.payments.first.amount).to eq 4.99
522
- end
523
-
524
- it 'handles payment building exceptions' do
525
- params = {
526
- payments_attributes: [
527
- {
528
- amount: '4.99',
529
- payment_method: 'XXX'
530
- }
531
- ]
532
- }
533
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
534
- end
535
-
536
- it 'build a source payment using years and month' do
537
- params = {
538
- payments_attributes: [
539
- {
540
- amount: '4.99',
541
- payment_method: payment_method.name,
542
- status: 'completed',
543
- source: {
544
- name: 'Fox',
545
- last_digits: "7424",
546
- cc_type: "visa",
547
- year: '2022',
548
- month: "5"
549
- }
550
- }
551
- ]
552
- }
553
-
554
- order = Importer::Order.import(user, params)
555
- expect(order.payments.first.source.last_digits).to eq '7424'
556
- end
557
-
558
- it 'handles source building exceptions when do not have years and month' do
559
- params = {
560
- payments_attributes: [
561
- {
562
- amount: '4.99',
563
- payment_method: payment_method.name,
564
- status: 'completed',
565
- source: {
566
- name: 'Fox',
567
- last_digits: "7424",
568
- cc_type: "visa"
569
- }
570
- }
571
- ]
572
- }
573
-
574
- expect { Importer::Order.import(user, params) }.
575
- to raise_error /Validation failed: Credit card Month is not a number, Credit card Year is not a number/
576
- end
577
-
578
- it 'builds a payment with an optional created_at' do
579
- created_at = 2.days.ago
580
- params = {
581
- payments_attributes: [
582
- {
583
- amount: '4.99',
584
- payment_method: payment_method.name,
585
- state: 'completed',
586
- created_at: created_at
587
- }
588
- ]
589
- }
590
- order = Importer::Order.import(user, params)
591
- expect(order.payments.first.created_at).to be_within(1).of created_at
592
- end
593
-
594
- context "raises error" do
595
- it "clears out order from db" do
596
- params = { payments_attributes: [{ payment_method: "XXX" }] }
597
- count = Order.count
598
-
599
- expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
600
- expect(Order.count).to eq count
601
- end
602
- end
603
- end
604
- end
605
- end