spree_core 3.3.0.rc1 → 3.3.0.rc2

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 (220) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +1 -1
  3. data/app/mailers/spree/base_mailer.rb +5 -0
  4. data/app/models/spree/ability.rb +4 -1
  5. data/app/models/spree/image.rb +6 -2
  6. data/app/models/spree/order.rb +10 -9
  7. data/app/models/spree/order/payments.rb +1 -1
  8. data/app/models/spree/payment_method/store_credit.rb +4 -0
  9. data/app/models/spree/shipment.rb +2 -0
  10. data/app/views/spree/shared/_base_mailer_header.html.erb +5 -1
  11. data/app/views/spree/shared/_mailer_line_item.html.erb +5 -1
  12. data/config/routes.rb +0 -3
  13. data/lib/spree/core/components.rb +17 -0
  14. data/lib/spree/core/controller_helpers/auth.rb +3 -1
  15. data/lib/spree/core/engine.rb +1 -0
  16. data/lib/spree/core/validators/email.rb +1 -5
  17. data/lib/spree/core/version.rb +1 -1
  18. data/spree_core.gemspec +1 -1
  19. metadata +4 -204
  20. data/lib/spree/testing_support/shoulda_matcher_configuration.rb +0 -6
  21. data/spec/fixtures/thinking-cat.jpg +0 -0
  22. data/spec/helpers/base_helper_spec.rb +0 -200
  23. data/spec/helpers/products_helper_spec.rb +0 -289
  24. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  25. data/spec/lib/i18n_spec.rb +0 -123
  26. data/spec/lib/search/base_spec.rb +0 -86
  27. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  28. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  29. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  30. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  31. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  32. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  33. data/spec/lib/spree/core/importer/order_spec.rb +0 -607
  34. data/spec/lib/spree/core/number_generator_spec.rb +0 -139
  35. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  36. data/spec/lib/spree/core/validators/email_spec.rb +0 -54
  37. data/spec/lib/spree/core_spec.rb +0 -23
  38. data/spec/lib/spree/localized_number_spec.rb +0 -54
  39. data/spec/lib/spree/migrations_spec.rb +0 -36
  40. data/spec/lib/spree/money_spec.rb +0 -122
  41. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  42. data/spec/mailers/order_mailer_spec.rb +0 -122
  43. data/spec/mailers/reimbursement_mailer_spec.rb +0 -52
  44. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  45. data/spec/mailers/test_mailer_spec.rb +0 -38
  46. data/spec/models/spree/ability_spec.rb +0 -251
  47. data/spec/models/spree/address_spec.rb +0 -402
  48. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  49. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  50. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  51. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  52. data/spec/models/spree/adjustment_spec.rb +0 -189
  53. data/spec/models/spree/app_configuration_spec.rb +0 -26
  54. data/spec/models/spree/asset_spec.rb +0 -28
  55. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  56. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  57. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  58. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  59. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  60. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  61. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  62. data/spec/models/spree/calculator/shipping.rb +0 -8
  63. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  64. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  65. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  66. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  67. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  68. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  69. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  70. data/spec/models/spree/calculator_spec.rb +0 -69
  71. data/spec/models/spree/classification_spec.rb +0 -93
  72. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  73. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  74. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  75. data/spec/models/spree/country_spec.rb +0 -55
  76. data/spec/models/spree/credit_card_spec.rb +0 -328
  77. data/spec/models/spree/customer_return_spec.rb +0 -240
  78. data/spec/models/spree/exchange_spec.rb +0 -75
  79. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  80. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  81. data/spec/models/spree/gateway_spec.rb +0 -61
  82. data/spec/models/spree/image_spec.rb +0 -8
  83. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  84. data/spec/models/spree/line_item_spec.rb +0 -348
  85. data/spec/models/spree/option_type_prototype_spec.rb +0 -9
  86. data/spec/models/spree/option_type_spec.rb +0 -14
  87. data/spec/models/spree/option_value_spec.rb +0 -18
  88. data/spec/models/spree/order/address_spec.rb +0 -50
  89. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  90. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  91. data/spec/models/spree/order/checkout_spec.rb +0 -770
  92. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  93. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  94. data/spec/models/spree/order/helpers_spec.rb +0 -5
  95. data/spec/models/spree/order/payment_spec.rb +0 -214
  96. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  97. data/spec/models/spree/order/shipments_spec.rb +0 -43
  98. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  99. data/spec/models/spree/order/store_credit_spec.rb +0 -457
  100. data/spec/models/spree/order/tax_spec.rb +0 -84
  101. data/spec/models/spree/order/totals_spec.rb +0 -24
  102. data/spec/models/spree/order/updating_spec.rb +0 -18
  103. data/spec/models/spree/order/validations_spec.rb +0 -15
  104. data/spec/models/spree/order_contents_spec.rb +0 -332
  105. data/spec/models/spree/order_inventory_spec.rb +0 -247
  106. data/spec/models/spree/order_merger_spec.rb +0 -135
  107. data/spec/models/spree/order_spec.rb +0 -1067
  108. data/spec/models/spree/order_updater_spec.rb +0 -305
  109. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  110. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  111. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  112. data/spec/models/spree/payment_method_spec.rb +0 -108
  113. data/spec/models/spree/payment_spec.rb +0 -922
  114. data/spec/models/spree/preference_spec.rb +0 -80
  115. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  116. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  117. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  118. data/spec/models/spree/preferences/store_spec.rb +0 -46
  119. data/spec/models/spree/price_spec.rb +0 -128
  120. data/spec/models/spree/product/scopes_spec.rb +0 -174
  121. data/spec/models/spree/product_duplicator_spec.rb +0 -102
  122. data/spec/models/spree/product_filter_spec.rb +0 -26
  123. data/spec/models/spree/product_option_type_spec.rb +0 -9
  124. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  125. data/spec/models/spree/product_property_spec.rb +0 -26
  126. data/spec/models/spree/product_spec.rb +0 -626
  127. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  128. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  129. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  130. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  131. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  132. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  133. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  134. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  135. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  136. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  137. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  138. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  139. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  140. data/spec/models/spree/promotion_action_spec.rb +0 -10
  141. data/spec/models/spree/promotion_category_spec.rb +0 -17
  142. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  143. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  144. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  145. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  146. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  147. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  148. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  149. data/spec/models/spree/promotion_spec.rb +0 -674
  150. data/spec/models/spree/property_prototype_spec.rb +0 -9
  151. data/spec/models/spree/property_spec.rb +0 -5
  152. data/spec/models/spree/prototype_spec.rb +0 -5
  153. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  154. data/spec/models/spree/refund_reason_spec.rb +0 -20
  155. data/spec/models/spree/refund_spec.rb +0 -195
  156. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  157. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  158. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  159. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  160. data/spec/models/spree/reimbursement_spec.rb +0 -188
  161. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  162. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  163. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  164. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  165. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  166. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  167. data/spec/models/spree/return_authorization_spec.rb +0 -230
  168. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  169. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  170. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  171. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  172. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  173. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  174. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  175. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  176. data/spec/models/spree/return_item_spec.rb +0 -734
  177. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  178. data/spec/models/spree/role_spec.rb +0 -7
  179. data/spec/models/spree/shipment_spec.rb +0 -744
  180. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  181. data/spec/models/spree/shipping_category_spec.rb +0 -19
  182. data/spec/models/spree/shipping_method_spec.rb +0 -125
  183. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  184. data/spec/models/spree/state_spec.rb +0 -29
  185. data/spec/models/spree/stock/availability_validator_spec.rb +0 -42
  186. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  187. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  188. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  189. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  190. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -37
  191. data/spec/models/spree/stock/package_spec.rb +0 -182
  192. data/spec/models/spree/stock/packer_spec.rb +0 -70
  193. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  194. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  195. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  196. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  197. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  198. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  199. data/spec/models/spree/stock_item_spec.rb +0 -465
  200. data/spec/models/spree/stock_location_spec.rb +0 -243
  201. data/spec/models/spree/stock_movement_spec.rb +0 -120
  202. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  203. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  204. data/spec/models/spree/store_credit_spec.rb +0 -798
  205. data/spec/models/spree/store_spec.rb +0 -78
  206. data/spec/models/spree/tax_category_spec.rb +0 -32
  207. data/spec/models/spree/tax_rate_spec.rb +0 -561
  208. data/spec/models/spree/taxon_spec.rb +0 -93
  209. data/spec/models/spree/taxonomy_spec.rb +0 -18
  210. data/spec/models/spree/tracker_spec.rb +0 -21
  211. data/spec/models/spree/user_spec.rb +0 -203
  212. data/spec/models/spree/variant_spec.rb +0 -818
  213. data/spec/models/spree/zone_member_spec.rb +0 -38
  214. data/spec/models/spree/zone_spec.rb +0 -472
  215. data/spec/spec_helper.rb +0 -82
  216. data/spec/support/big_decimal.rb +0 -5
  217. data/spec/support/concerns/adjustment_source.rb +0 -23
  218. data/spec/support/concerns/default_price.rb +0 -37
  219. data/spec/support/rake.rb +0 -13
  220. data/spec/support/test_gateway.rb +0 -2
@@ -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,607 +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: Array.new(3) { { sku: sku, variant_id: variant.id } }
285
- },
286
- {
287
- tracking: '123456789',
288
- cost: '14.99',
289
- shipping_method: shipping_method.name,
290
- stock_location: stock_location.name,
291
- inventory_units: Array.new(2) { { sku: sku, variant_id: variant.id } }
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 2
319
- expect(order.shipments.first.inventory_units.count).to eq 1
320
- expect(order.shipments.first.inventory_units.first.quantity).to eq 3
321
- expect(order.shipments.last.inventory_units.count).to eq 1
322
- expect(order.shipments.last.inventory_units.first.quantity).to eq 2
323
- end
324
-
325
- it "accepts admin name for stock location" do
326
- params[:shipments_attributes][0][:stock_location] = stock_location.admin_name
327
- order = Importer::Order.import(user, params)
328
- shipment = order.shipments.first
329
-
330
- expect(shipment.stock_location).to eq stock_location
331
- end
332
-
333
- it "raises if cant find stock location" do
334
- params[:shipments_attributes][0][:stock_location] = "doesnt exist"
335
- expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
336
- end
337
-
338
- context 'when a shipping adjustment is present' do
339
- it 'creates the shipping adjustment' do
340
- adjustment_attributes = [{ label: 'Shipping Discount', amount: -5.00 }]
341
- params[:shipments_attributes][0][:adjustments_attributes] = adjustment_attributes
342
- order = Importer::Order.import(user, params)
343
- shipment = order.shipments.first
344
-
345
- expect(shipment.adjustments.first.label).to eq('Shipping Discount')
346
- expect(shipment.adjustments.first.amount).to eq(-5.00)
347
- end
348
- end
349
-
350
- context 'when completed_at and shipped_at present' do
351
- let(:params) do
352
- {
353
- completed_at: 2.days.ago,
354
- line_items_attributes: line_items,
355
- shipments_attributes: [
356
- {
357
- tracking: '123456789',
358
- cost: '4.99',
359
- shipped_at: 1.day.ago,
360
- shipping_method: shipping_method.name,
361
- stock_location: stock_location.name,
362
- inventory_units: [{ sku: sku }]
363
- }
364
- ]
365
- }
366
- end
367
-
368
- it 'builds them properly' do
369
- order = Importer::Order.import(user, params)
370
- shipment = order.shipments.first
371
-
372
- expect(shipment.cost.to_f).to eq 4.99
373
- expect(shipment.inventory_units.first.variant_id).to eq product.master.id
374
- expect(shipment.tracking).to eq '123456789'
375
- expect(shipment.shipped_at).to be_present
376
- expect(shipment.shipping_rates.first.cost).to eq 4.99
377
- expect(shipment.selected_shipping_rate).to eq(shipment.shipping_rates.first)
378
- expect(shipment.stock_location).to eq stock_location
379
- expect(shipment.state).to eq('shipped')
380
- expect(shipment.inventory_units.all?(&:shipped?)).to be true
381
- expect(order.shipment_state).to eq('shipped')
382
- expect(order.shipment_total.to_f).to eq 4.99
383
- end
384
- end
385
- end
386
-
387
- it 'handles shipment building exceptions' do
388
- params = {
389
- shipments_attributes: [
390
- {
391
- tracking: '123456789',
392
- cost: '4.99',
393
- shipping_method: 'XXX',
394
- inventory_units: [{ sku: sku }]
395
- }
396
- ]
397
- }
398
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
399
- end
400
-
401
- it 'adds adjustments' do
402
- params = {
403
- adjustments_attributes: [
404
- {
405
- label: 'Shipping Discount',
406
- amount: -4.99
407
- },
408
- {
409
- label: 'Promotion Discount',
410
- amount: -3.00
411
- }
412
- ]
413
- }
414
-
415
- order = Importer::Order.import(user, params)
416
- expect(order.adjustments.all?(&:closed?)).to be true
417
- expect(order.adjustments.first.label).to eq 'Shipping Discount'
418
- expect(order.adjustments.first.amount).to eq -4.99
419
- end
420
-
421
- it 'adds line item adjustments from promotion' do
422
- line_items.first[:adjustments_attributes] = [
423
- {
424
- label: 'Line Item Discount',
425
- amount: -4.99,
426
- promotion: true
427
- }
428
- ]
429
- params = {
430
- line_items_attributes: line_items,
431
- adjustments_attributes: [
432
- { label: 'Order Discount', amount: -5.99 }
433
- ]
434
- }
435
-
436
- order = Importer::Order.import(user, params)
437
- line_item_adjustment = order.line_item_adjustments.first
438
- expect(line_item_adjustment.closed?).to be true
439
- expect(line_item_adjustment.label).to eq 'Line Item Discount'
440
- expect(line_item_adjustment.amount).to eq -4.99
441
- expect(order.line_items.first.adjustment_total).to eq -4.99
442
- end
443
-
444
- it 'adds line item adjustments from taxation' do
445
- line_items.first[:adjustments_attributes] = [
446
- { label: 'Line Item Tax', amount: -4.99, tax: true }
447
- ]
448
- params = {
449
- line_items_attributes: line_items,
450
- adjustments_attributes: [
451
- { label: 'Order Discount', amount: -5.99 }
452
- ]
453
- }
454
-
455
- order = Importer::Order.import(user, params)
456
-
457
- line_item_adjustment = order.line_item_adjustments.first
458
- expect(line_item_adjustment.closed?).to be true
459
- expect(line_item_adjustment.label).to eq 'Line Item Tax'
460
- expect(line_item_adjustment.amount).to eq -4.99
461
- expect(order.line_items.first.adjustment_total).to eq -4.99
462
- end
463
-
464
- it "calculates final order total correctly" do
465
- params = {
466
- adjustments_attributes: [
467
- { label: 'Promotion Discount', amount: -3.00 }
468
- ],
469
- line_items_attributes: [
470
- {
471
- variant_id: variant.id,
472
- quantity: 5
473
- }
474
- ]
475
- }
476
-
477
- order = Importer::Order.import(user, params)
478
- expect(order.item_total).to eq(166.1)
479
- expect(order.total).to eq(163.1) # = item_total (166.1) - adjustment_total (3.00)
480
- end
481
-
482
- it 'handles adjustment building exceptions' do
483
- params = {
484
- adjustments_attributes: [
485
- {
486
- amount: 'XXX'
487
- },
488
- {
489
- label: 'Promotion Discount',
490
- amount: '-3.00'
491
- }
492
- ]
493
- }
494
-
495
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
496
- end
497
-
498
- it 'builds a payment using state' do
499
- params = {
500
- payments_attributes: [
501
- {
502
- amount: '4.99',
503
- payment_method: payment_method.name,
504
- state: 'completed'
505
- }
506
- ]
507
- }
508
- order = Importer::Order.import(user, params)
509
- expect(order.payments.first.amount).to eq 4.99
510
- end
511
-
512
- it 'builds a payment using status as fallback' do
513
- params = {
514
- payments_attributes: [
515
- {
516
- amount: '4.99',
517
- payment_method: payment_method.name,
518
- status: 'completed'
519
- }
520
- ]
521
- }
522
- order = Importer::Order.import(user, params)
523
- expect(order.payments.first.amount).to eq 4.99
524
- end
525
-
526
- it 'handles payment building exceptions' do
527
- params = {
528
- payments_attributes: [
529
- {
530
- amount: '4.99',
531
- payment_method: 'XXX'
532
- }
533
- ]
534
- }
535
- expect { Importer::Order.import(user, params) }.to raise_error /XXX/
536
- end
537
-
538
- it 'build a source payment using years and month' do
539
- params = {
540
- payments_attributes: [
541
- {
542
- amount: '4.99',
543
- payment_method: payment_method.name,
544
- status: 'completed',
545
- source: {
546
- name: 'Fox',
547
- last_digits: "7424",
548
- cc_type: "visa",
549
- year: '2022',
550
- month: "5"
551
- }
552
- }
553
- ]
554
- }
555
-
556
- order = Importer::Order.import(user, params)
557
- expect(order.payments.first.source.last_digits).to eq '7424'
558
- end
559
-
560
- it 'handles source building exceptions when do not have years and month' do
561
- params = {
562
- payments_attributes: [
563
- {
564
- amount: '4.99',
565
- payment_method: payment_method.name,
566
- status: 'completed',
567
- source: {
568
- name: 'Fox',
569
- last_digits: "7424",
570
- cc_type: "visa"
571
- }
572
- }
573
- ]
574
- }
575
-
576
- expect { Importer::Order.import(user, params) }.
577
- to raise_error /Validation failed: Credit card Month is not a number, Credit card Year is not a number/
578
- end
579
-
580
- it 'builds a payment with an optional created_at' do
581
- created_at = 2.days.ago
582
- params = {
583
- payments_attributes: [
584
- {
585
- amount: '4.99',
586
- payment_method: payment_method.name,
587
- state: 'completed',
588
- created_at: created_at
589
- }
590
- ]
591
- }
592
- order = Importer::Order.import(user, params)
593
- expect(order.payments.first.created_at).to be_within(1).of created_at
594
- end
595
-
596
- context "raises error" do
597
- it "clears out order from db" do
598
- params = { payments_attributes: [{ payment_method: "XXX" }] }
599
- count = Order.count
600
-
601
- expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
602
- expect(Order.count).to eq count
603
- end
604
- end
605
- end
606
- end
607
- end