solidus_core 2.10.5 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (494) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree.js.erb +31 -2
  3. data/app/controllers/spree/base_controller.rb +1 -0
  4. data/app/mailers/spree/base_mailer.rb +4 -0
  5. data/app/mailers/spree/order_mailer.rb +1 -1
  6. data/app/models/concerns/spree/active_storage_adapter.rb +116 -0
  7. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +69 -0
  8. data/app/models/concerns/spree/active_storage_adapter/normalization.rb +39 -0
  9. data/app/models/concerns/spree/default_price.rb +1 -1
  10. data/app/models/concerns/spree/soft_deletable.rb +18 -0
  11. data/app/models/concerns/spree/user_address_book.rb +86 -32
  12. data/app/models/concerns/spree/user_methods.rb +3 -2
  13. data/app/models/spree/ability.rb +34 -10
  14. data/app/models/spree/address.rb +94 -17
  15. data/app/models/spree/address/name.rb +49 -0
  16. data/app/models/spree/address/state_validator.rb +71 -0
  17. data/app/models/spree/adjustment.rb +1 -1
  18. data/app/models/spree/base.rb +1 -0
  19. data/app/models/spree/calculator/default_tax.rb +1 -1
  20. data/app/models/spree/calculator/percent_per_item.rb +4 -4
  21. data/app/models/spree/calculator/price_sack.rb +1 -1
  22. data/app/models/spree/credit_card.rb +2 -2
  23. data/app/models/spree/customer_return.rb +4 -2
  24. data/app/models/spree/exchange.rb +1 -1
  25. data/app/models/spree/image/active_storage_attachment.rb +21 -0
  26. data/app/models/spree/inventory_unit.rb +1 -1
  27. data/app/models/spree/line_item.rb +13 -4
  28. data/app/models/spree/option_type.rb +1 -1
  29. data/app/models/spree/option_value.rb +2 -2
  30. data/app/models/spree/order.rb +91 -20
  31. data/app/models/spree/order/checkout.rb +1 -0
  32. data/app/models/spree/order_inventory.rb +16 -4
  33. data/app/models/spree/order_merger.rb +6 -4
  34. data/app/models/spree/order_promotion.rb +1 -1
  35. data/app/models/spree/order_updater.rb +11 -10
  36. data/app/models/spree/payment.rb +3 -3
  37. data/app/models/spree/payment/cancellation.rb +3 -3
  38. data/app/models/spree/payment/processing.rb +54 -30
  39. data/app/models/spree/payment_method.rb +8 -9
  40. data/app/models/spree/preference.rb +1 -1
  41. data/app/models/spree/price.rb +2 -8
  42. data/app/models/spree/product.rb +19 -14
  43. data/app/models/spree/product/scopes.rb +9 -4
  44. data/app/models/spree/promotion.rb +18 -7
  45. data/app/models/spree/promotion/actions/free_shipping.rb +6 -5
  46. data/app/models/spree/promotion_action.rb +1 -7
  47. data/app/models/spree/promotion_code.rb +6 -1
  48. data/app/models/spree/promotion_code_batch.rb +1 -1
  49. data/app/models/spree/promotion_handler/coupon.rb +2 -2
  50. data/app/models/spree/promotion_rule.rb +1 -1
  51. data/app/models/spree/promotion_rule_role.rb +1 -1
  52. data/app/models/spree/refund.rb +54 -12
  53. data/app/models/spree/reimbursement.rb +27 -0
  54. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +10 -3
  55. data/app/models/spree/return_authorization.rb +1 -1
  56. data/app/models/spree/return_item.rb +21 -10
  57. data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +1 -1
  58. data/app/models/spree/role.rb +1 -1
  59. data/app/models/spree/shipment.rb +2 -2
  60. data/app/models/spree/shipping_calculator.rb +1 -1
  61. data/app/models/spree/shipping_manifest.rb +2 -2
  62. data/app/models/spree/shipping_method.rb +2 -9
  63. data/app/models/spree/shipping_rate.rb +1 -1
  64. data/app/models/spree/shipping_rate_tax.rb +1 -1
  65. data/app/models/spree/stock/inventory_unit_builder.rb +18 -7
  66. data/app/models/spree/stock/inventory_units_finalizer.rb +3 -5
  67. data/app/models/spree/stock/package.rb +1 -1
  68. data/app/models/spree/stock/simple_coordinator.rb +1 -3
  69. data/app/models/spree/stock_item.rb +2 -8
  70. data/app/models/spree/stock_movement.rb +2 -0
  71. data/app/models/spree/store.rb +1 -1
  72. data/app/models/spree/store_credit.rb +1 -7
  73. data/app/models/spree/store_credit_category.rb +30 -3
  74. data/app/models/spree/store_credit_event.rb +1 -7
  75. data/app/models/spree/store_credit_reason.rb +0 -4
  76. data/app/models/spree/tax/tax_helpers.rb +1 -1
  77. data/app/models/spree/tax_category.rb +2 -8
  78. data/app/models/spree/tax_rate.rb +7 -7
  79. data/app/models/spree/taxon.rb +1 -1
  80. data/app/models/spree/taxon/active_storage_attachment.rb +19 -0
  81. data/app/models/spree/user_address.rb +8 -2
  82. data/app/models/spree/variant.rb +7 -13
  83. data/app/models/spree/variant_property_rule.rb +5 -1
  84. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +8 -3
  85. data/app/models/spree/zone.rb +1 -1
  86. data/config/locales/en.yml +44 -5
  87. data/db/default/spree/countries.rb +1 -1
  88. data/db/default/spree/states.rb +12 -4
  89. data/db/default/spree/store_credit.rb +2 -2
  90. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +12 -0
  91. data/db/migrate/20200320144521_add_default_billng_flag_to_user_addresses.rb +6 -0
  92. data/db/migrate/20200530111458_add_bcc_email_to_spree_stores.rb +7 -0
  93. data/db/migrate/20201008213609_add_discontinue_on_to_spree_products.rb +7 -0
  94. data/lib/generators/solidus/install/install_generator.rb +253 -0
  95. data/lib/generators/{spree → solidus}/install/templates/config/initializers/spree.rb.tt +36 -5
  96. data/lib/generators/{spree → solidus}/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -0
  97. data/lib/generators/{spree → solidus}/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -0
  98. data/lib/generators/{spree → solidus}/install/templates/vendor/assets/stylesheets/spree/backend/all.css +0 -0
  99. data/lib/generators/{spree → solidus}/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -0
  100. data/lib/generators/spree/install/install_generator.rb +7 -189
  101. data/lib/solidus/migrations/promotions_with_code_handlers.rb +1 -1
  102. data/lib/spree/app_configuration.rb +117 -51
  103. data/lib/spree/awesome_nested_set_override.rb +44 -0
  104. data/lib/spree/core.rb +5 -11
  105. data/lib/spree/core/controller_helpers/auth.rb +17 -4
  106. data/lib/spree/core/controller_helpers/current_host.rb +17 -0
  107. data/lib/spree/core/controller_helpers/order.rb +8 -7
  108. data/lib/spree/core/engine.rb +39 -2
  109. data/lib/spree/core/importer/order.rb +24 -10
  110. data/lib/spree/core/permalinks.rb +1 -3
  111. data/lib/spree/core/product_filters.rb +6 -5
  112. data/lib/spree/core/state_machines.rb +20 -1
  113. data/lib/spree/core/state_machines/order.rb +249 -0
  114. data/lib/spree/core/state_machines/return_item/reception_status.rb +2 -2
  115. data/lib/spree/core/version.rb +1 -1
  116. data/lib/spree/encryptor.rb +25 -0
  117. data/lib/spree/event.rb +40 -7
  118. data/lib/spree/event/adapters/active_support_notifications.rb +32 -0
  119. data/lib/spree/event/configuration.rb +11 -6
  120. data/lib/spree/event/subscriber.rb +38 -18
  121. data/lib/spree/event/subscriber_registry.rb +92 -0
  122. data/lib/spree/i18n.rb +1 -1
  123. data/lib/spree/mailer_previews/carton_preview.rb +2 -1
  124. data/lib/spree/paranoia_deprecations.rb +32 -12
  125. data/lib/spree/permission_sets/configuration_display.rb +14 -14
  126. data/lib/spree/permission_sets/default_customer.rb +16 -16
  127. data/lib/spree/permission_sets/order_display.rb +11 -11
  128. data/lib/spree/permission_sets/order_management.rb +1 -1
  129. data/lib/spree/permission_sets/product_display.rb +9 -9
  130. data/lib/spree/permission_sets/promotion_display.rb +5 -5
  131. data/lib/spree/permission_sets/restricted_stock_display.rb +2 -2
  132. data/lib/spree/permission_sets/restricted_stock_management.rb +1 -1
  133. data/lib/spree/permission_sets/stock_display.rb +2 -2
  134. data/lib/spree/permission_sets/stock_management.rb +1 -1
  135. data/lib/spree/permission_sets/user_display.rb +3 -3
  136. data/lib/spree/permission_sets/user_management.rb +4 -3
  137. data/lib/spree/permitted_attributes.rb +4 -3
  138. data/lib/spree/preferences/preferable.rb +4 -3
  139. data/lib/spree/preferences/preferable_class_methods.rb +22 -3
  140. data/lib/spree/testing_support/ability_helpers.rb +9 -9
  141. data/lib/spree/testing_support/authorization_helpers.rb +1 -0
  142. data/lib/spree/testing_support/blacklist_urls.rb +23 -0
  143. data/lib/spree/testing_support/capybara_ext.rb +3 -0
  144. data/lib/spree/testing_support/common_rake.rb +3 -3
  145. data/lib/spree/testing_support/dummy_app.rb +44 -23
  146. data/lib/spree/testing_support/dummy_app/migrations.rb +5 -6
  147. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +1 -3
  148. data/lib/spree/testing_support/factories/address_factory.rb +1 -2
  149. data/lib/spree/testing_support/factories/image_factory.rb +1 -1
  150. data/lib/spree/testing_support/factories/promotion_factory.rb +6 -0
  151. data/lib/spree/testing_support/factories/refund_factory.rb +1 -0
  152. data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
  153. data/lib/spree/testing_support/factories/return_item_factory.rb +0 -1
  154. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +8 -0
  155. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +1 -0
  156. data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +3 -1
  157. data/lib/spree/testing_support/factories/taxon_factory.rb +4 -0
  158. data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
  159. data/lib/spree/testing_support/job_helpers.rb +24 -0
  160. data/lib/spree/testing_support/precompiled_assets.rb +15 -0
  161. data/lib/spree/testing_support/preferences.rb +3 -1
  162. data/lib/spree/testing_support/shared_examples/gallery.rb +1 -1
  163. data/lib/spree/testing_support/translations.rb +25 -0
  164. data/solidus_core.gemspec +7 -4
  165. metadata +91 -370
  166. data/script/rails +0 -10
  167. data/spec/fixtures/thinking-cat.jpg +0 -0
  168. data/spec/helpers/base_helper_spec.rb +0 -168
  169. data/spec/helpers/products_helper_spec.rb +0 -202
  170. data/spec/helpers/taxons_helper_spec.rb +0 -43
  171. data/spec/jobs/promotion_code_batch_job_spec.rb +0 -96
  172. data/spec/lib/calculated_adjustments_spec.rb +0 -133
  173. data/spec/lib/i18n_spec.rb +0 -97
  174. data/spec/lib/search/base_spec.rb +0 -91
  175. data/spec/lib/search/variant_spec.rb +0 -115
  176. data/spec/lib/spree/app_configuration_spec.rb +0 -140
  177. data/spec/lib/spree/core/class_constantizer_spec.rb +0 -91
  178. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -73
  179. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -126
  180. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -195
  181. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +0 -94
  182. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -21
  183. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -18
  184. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -48
  185. data/spec/lib/spree/core/current_store_spec.rb +0 -33
  186. data/spec/lib/spree/core/environment_extension_spec.rb +0 -46
  187. data/spec/lib/spree/core/importer/order_spec.rb +0 -484
  188. data/spec/lib/spree/core/role_configuration_spec.rb +0 -155
  189. data/spec/lib/spree/core/stock_configuration_spec.rb +0 -95
  190. data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +0 -61
  191. data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +0 -20
  192. data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +0 -14
  193. data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +0 -44
  194. data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +0 -14
  195. data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +0 -14
  196. data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +0 -14
  197. data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +0 -39
  198. data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +0 -14
  199. data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +0 -14
  200. data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +0 -14
  201. data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +0 -14
  202. data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +0 -14
  203. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +0 -376
  204. data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +0 -14
  205. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +0 -40
  206. data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +0 -32
  207. data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +0 -14
  208. data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +0 -32
  209. data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +0 -14
  210. data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +0 -14
  211. data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +0 -14
  212. data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +0 -14
  213. data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +0 -32
  214. data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +0 -14
  215. data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +0 -14
  216. data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +0 -14
  217. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +0 -20
  218. data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +0 -14
  219. data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +0 -14
  220. data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +0 -20
  221. data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +0 -14
  222. data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +0 -20
  223. data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +0 -14
  224. data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +0 -14
  225. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +0 -44
  226. data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +0 -14
  227. data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +0 -59
  228. data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +0 -14
  229. data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +0 -35
  230. data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +0 -14
  231. data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +0 -28
  232. data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +0 -14
  233. data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +0 -43
  234. data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +0 -14
  235. data/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb +0 -14
  236. data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +0 -20
  237. data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +0 -14
  238. data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +0 -14
  239. data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +0 -14
  240. data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +0 -14
  241. data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +0 -14
  242. data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +0 -24
  243. data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +0 -56
  244. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +0 -14
  245. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +0 -14
  246. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +0 -14
  247. data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +0 -20
  248. data/spec/lib/spree/core/testing_support/preferences_spec.rb +0 -61
  249. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  250. data/spec/lib/spree/core/version_spec.rb +0 -19
  251. data/spec/lib/spree/event/subscriber_spec.rb +0 -85
  252. data/spec/lib/spree/event_spec.rb +0 -130
  253. data/spec/lib/spree/localized_number_spec.rb +0 -45
  254. data/spec/lib/spree/migrations_spec.rb +0 -32
  255. data/spec/lib/spree/money_spec.rb +0 -298
  256. data/spec/lib/spree/permission_sets/default_customer_spec.rb +0 -22
  257. data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
  258. data/spec/lib/spree/promo/environment_spec.rb +0 -53
  259. data/spec/lib/tasks/dummy_task.rake +0 -12
  260. data/spec/lib/tasks/dummy_task_spec.rb +0 -30
  261. data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +0 -21
  262. data/spec/mailers/carton_mailer_spec.rb +0 -44
  263. data/spec/mailers/order_mailer_spec.rb +0 -117
  264. data/spec/mailers/promotion_code_batch_mailer_spec.rb +0 -47
  265. data/spec/mailers/reimbursement_mailer_spec.rb +0 -36
  266. data/spec/mailers/test_mailer_spec.rb +0 -13
  267. data/spec/models/spree/ability_spec.rb +0 -279
  268. data/spec/models/spree/address_spec.rb +0 -399
  269. data/spec/models/spree/adjustment_reason_spec.rb +0 -11
  270. data/spec/models/spree/adjustment_spec.rb +0 -339
  271. data/spec/models/spree/asset_spec.rb +0 -25
  272. data/spec/models/spree/calculator/default_tax_spec.rb +0 -260
  273. data/spec/models/spree/calculator/distributed_amount_spec.rb +0 -82
  274. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -39
  275. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -52
  276. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -158
  277. data/spec/models/spree/calculator/free_shipping_spec.rb +0 -8
  278. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -20
  279. data/spec/models/spree/calculator/percent_per_item_spec.rb +0 -12
  280. data/spec/models/spree/calculator/price_sack_spec.rb +0 -35
  281. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -70
  282. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -44
  283. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -18
  284. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -56
  285. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -25
  286. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -44
  287. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -99
  288. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -197
  289. data/spec/models/spree/calculator_spec.rb +0 -43
  290. data/spec/models/spree/carton_spec.rb +0 -145
  291. data/spec/models/spree/classification_spec.rb +0 -126
  292. data/spec/models/spree/concerns/display_money_spec.rb +0 -44
  293. data/spec/models/spree/concerns/ordered_property_value_list_spec.rb +0 -52
  294. data/spec/models/spree/concerns/user_address_book_spec.rb +0 -358
  295. data/spec/models/spree/concerns/user_methods_spec.rb +0 -122
  296. data/spec/models/spree/country_spec.rb +0 -154
  297. data/spec/models/spree/credit_card_spec.rb +0 -373
  298. data/spec/models/spree/customer_return_spec.rb +0 -294
  299. data/spec/models/spree/distributed_amounts_handler_spec.rb +0 -83
  300. data/spec/models/spree/exchange_spec.rb +0 -76
  301. data/spec/models/spree/fulfilment_changer_spec.rb +0 -340
  302. data/spec/models/spree/gallery/product_gallery_spec.rb +0 -21
  303. data/spec/models/spree/gallery/variant_gallery_spec.rb +0 -21
  304. data/spec/models/spree/gateway/bogus_simple.rb +0 -14
  305. data/spec/models/spree/gateway/bogus_spec.rb +0 -14
  306. data/spec/models/spree/gateway_spec.rb +0 -14
  307. data/spec/models/spree/image_spec.rb +0 -25
  308. data/spec/models/spree/inventory_unit_spec.rb +0 -309
  309. data/spec/models/spree/line_item_spec.rb +0 -240
  310. data/spec/models/spree/option_type_spec.rb +0 -16
  311. data/spec/models/spree/option_value_spec.rb +0 -52
  312. data/spec/models/spree/order/address_spec.rb +0 -52
  313. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  314. data/spec/models/spree/order/callbacks_spec.rb +0 -44
  315. data/spec/models/spree/order/checkout_spec.rb +0 -740
  316. data/spec/models/spree/order/finalizing_spec.rb +0 -92
  317. data/spec/models/spree/order/number_generator_spec.rb +0 -47
  318. data/spec/models/spree/order/outstanding_balance_integration_spec.rb +0 -138
  319. data/spec/models/spree/order/payment_spec.rb +0 -280
  320. data/spec/models/spree/order/risk_assessment_spec.rb +0 -70
  321. data/spec/models/spree/order/state_machine_spec.rb +0 -122
  322. data/spec/models/spree/order/totals_spec.rb +0 -26
  323. data/spec/models/spree/order/validations_spec.rb +0 -17
  324. data/spec/models/spree/order_cancellations_spec.rb +0 -233
  325. data/spec/models/spree/order_capturing_spec.rb +0 -16
  326. data/spec/models/spree/order_contents_spec.rb +0 -362
  327. data/spec/models/spree/order_inventory_spec.rb +0 -285
  328. data/spec/models/spree/order_merger_spec.rb +0 -162
  329. data/spec/models/spree/order_mutex_spec.rb +0 -89
  330. data/spec/models/spree/order_promotion_spec.rb +0 -33
  331. data/spec/models/spree/order_shipping_spec.rb +0 -247
  332. data/spec/models/spree/order_spec.rb +0 -1687
  333. data/spec/models/spree/order_taxation_spec.rb +0 -128
  334. data/spec/models/spree/order_update_attributes_spec.rb +0 -49
  335. data/spec/models/spree/order_updater_spec.rb +0 -556
  336. data/spec/models/spree/payment/cancellation_spec.rb +0 -84
  337. data/spec/models/spree/payment_create_spec.rb +0 -195
  338. data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +0 -10
  339. data/spec/models/spree/payment_method/check_spec.rb +0 -80
  340. data/spec/models/spree/payment_method/credit_card_spec.rb +0 -68
  341. data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +0 -20
  342. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -325
  343. data/spec/models/spree/payment_method_spec.rb +0 -408
  344. data/spec/models/spree/payment_spec.rb +0 -1270
  345. data/spec/models/spree/permission_sets/base_spec.rb +0 -14
  346. data/spec/models/spree/permission_sets/configuration_display.rb +0 -79
  347. data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -49
  348. data/spec/models/spree/permission_sets/dashboard_display_spec.rb +0 -23
  349. data/spec/models/spree/permission_sets/order_display_spec.rb +0 -56
  350. data/spec/models/spree/permission_sets/order_management_spec.rb +0 -43
  351. data/spec/models/spree/permission_sets/product_display_spec.rb +0 -57
  352. data/spec/models/spree/permission_sets/product_management_spec.rb +0 -39
  353. data/spec/models/spree/permission_sets/promotion_display_spec.rb +0 -41
  354. data/spec/models/spree/permission_sets/promotion_management_spec.rb +0 -29
  355. data/spec/models/spree/permission_sets/restricted_stock_display_spec.rb +0 -42
  356. data/spec/models/spree/permission_sets/restricted_stock_management_spec.rb +0 -42
  357. data/spec/models/spree/permission_sets/stock_display_spec.rb +0 -25
  358. data/spec/models/spree/permission_sets/stock_management_spec.rb +0 -23
  359. data/spec/models/spree/permission_sets/user_display_spec.rb +0 -39
  360. data/spec/models/spree/permission_sets/user_management_spec.rb +0 -58
  361. data/spec/models/spree/preference_spec.rb +0 -79
  362. data/spec/models/spree/preferences/configuration_spec.rb +0 -27
  363. data/spec/models/spree/preferences/preferable_spec.rb +0 -334
  364. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -62
  365. data/spec/models/spree/preferences/static_model_preferences_spec.rb +0 -79
  366. data/spec/models/spree/preferences/statically_configurable_spec.rb +0 -67
  367. data/spec/models/spree/preferences/store_spec.rb +0 -40
  368. data/spec/models/spree/price_spec.rb +0 -150
  369. data/spec/models/spree/product/scopes_spec.rb +0 -164
  370. data/spec/models/spree/product_duplicator_spec.rb +0 -92
  371. data/spec/models/spree/product_filter_spec.rb +0 -28
  372. data/spec/models/spree/product_property_spec.rb +0 -20
  373. data/spec/models/spree/product_spec.rb +0 -584
  374. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -126
  375. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -198
  376. data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +0 -298
  377. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -61
  378. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -87
  379. data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +0 -71
  380. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -128
  381. data/spec/models/spree/promotion/rules/nth_order_spec.rb +0 -72
  382. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -54
  383. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -96
  384. data/spec/models/spree/promotion/rules/product_spec.rb +0 -193
  385. data/spec/models/spree/promotion/rules/store_spec.rb +0 -35
  386. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -227
  387. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -33
  388. data/spec/models/spree/promotion/rules/user_role_spec.rb +0 -88
  389. data/spec/models/spree/promotion/rules/user_spec.rb +0 -39
  390. data/spec/models/spree/promotion_action_spec.rb +0 -44
  391. data/spec/models/spree/promotion_category_spec.rb +0 -19
  392. data/spec/models/spree/promotion_code/batch_builder_spec.rb +0 -107
  393. data/spec/models/spree/promotion_code_batch_spec.rb +0 -54
  394. data/spec/models/spree/promotion_code_spec.rb +0 -206
  395. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -132
  396. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -419
  397. data/spec/models/spree/promotion_handler/page_spec.rb +0 -45
  398. data/spec/models/spree/promotion_handler/shipping_spec.rb +0 -96
  399. data/spec/models/spree/promotion_rule_spec.rb +0 -34
  400. data/spec/models/spree/promotion_spec.rb +0 -945
  401. data/spec/models/spree/refund_spec.rb +0 -200
  402. data/spec/models/spree/reimbursement/credit_spec.rb +0 -38
  403. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -144
  404. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -85
  405. data/spec/models/spree/reimbursement_performer_spec.rb +0 -33
  406. data/spec/models/spree/reimbursement_spec.rb +0 -278
  407. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -52
  408. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -56
  409. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -48
  410. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -110
  411. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -111
  412. data/spec/models/spree/return_authorization_spec.rb +0 -226
  413. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -79
  414. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -59
  415. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -86
  416. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -35
  417. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -31
  418. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -42
  419. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -66
  420. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  421. data/spec/models/spree/return_item_spec.rb +0 -785
  422. data/spec/models/spree/returns_calculator_spec.rb +0 -16
  423. data/spec/models/spree/shipment_spec.rb +0 -914
  424. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  425. data/spec/models/spree/shipping_manifest_spec.rb +0 -110
  426. data/spec/models/spree/shipping_method_spec.rb +0 -292
  427. data/spec/models/spree/shipping_rate_spec.rb +0 -154
  428. data/spec/models/spree/shipping_rate_tax_spec.rb +0 -79
  429. data/spec/models/spree/state_spec.rb +0 -43
  430. data/spec/models/spree/stock/allocator/on_hand_first_spec.rb +0 -146
  431. data/spec/models/spree/stock/availability_spec.rb +0 -143
  432. data/spec/models/spree/stock/availability_validator_spec.rb +0 -140
  433. data/spec/models/spree/stock/content_item_spec.rb +0 -70
  434. data/spec/models/spree/stock/differentiator_spec.rb +0 -41
  435. data/spec/models/spree/stock/estimator_spec.rb +0 -241
  436. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -34
  437. data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +0 -58
  438. data/spec/models/spree/stock/location_filter/active_spec.rb +0 -22
  439. data/spec/models/spree/stock/location_sorter/default_first_spec.rb +0 -22
  440. data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +0 -21
  441. data/spec/models/spree/stock/package_spec.rb +0 -182
  442. data/spec/models/spree/stock/quantifier_spec.rb +0 -113
  443. data/spec/models/spree/stock/shipping_rate_selector_spec.rb +0 -18
  444. data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +0 -18
  445. data/spec/models/spree/stock/simple_coordinator_spec.rb +0 -264
  446. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -31
  447. data/spec/models/spree/stock/splitter/base_spec.rb +0 -22
  448. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -48
  449. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -31
  450. data/spec/models/spree/stock/splitter_chain_spec.rb +0 -66
  451. data/spec/models/spree/stock_item_spec.rb +0 -348
  452. data/spec/models/spree/stock_location_spec.rb +0 -288
  453. data/spec/models/spree/stock_movement_spec.rb +0 -58
  454. data/spec/models/spree/stock_quantities_spec.rb +0 -249
  455. data/spec/models/spree/store_credit_category_spec.rb +0 -19
  456. data/spec/models/spree/store_credit_event_spec.rb +0 -328
  457. data/spec/models/spree/store_credit_spec.rb +0 -900
  458. data/spec/models/spree/store_selector/by_server_name_spec.rb +0 -28
  459. data/spec/models/spree/store_selector/legacy_spec.rb +0 -46
  460. data/spec/models/spree/store_spec.rb +0 -156
  461. data/spec/models/spree/tax/order_adjuster_spec.rb +0 -35
  462. data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +0 -59
  463. data/spec/models/spree/tax/tax_location_spec.rb +0 -79
  464. data/spec/models/spree/tax/taxation_integration_spec.rb +0 -815
  465. data/spec/models/spree/tax_calculator/default_spec.rb +0 -56
  466. data/spec/models/spree/tax_category_spec.rb +0 -50
  467. data/spec/models/spree/tax_rate_spec.rb +0 -317
  468. data/spec/models/spree/taxon_spec.rb +0 -197
  469. data/spec/models/spree/taxonomy_spec.rb +0 -15
  470. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +0 -29
  471. data/spec/models/spree/unit_cancel_spec.rb +0 -126
  472. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +0 -31
  473. data/spec/models/spree/user_last_url_storer_spec.rb +0 -60
  474. data/spec/models/spree/user_spec.rb +0 -247
  475. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +0 -33
  476. data/spec/models/spree/variant/price_selector_spec.rb +0 -90
  477. data/spec/models/spree/variant/pricing_options_spec.rb +0 -204
  478. data/spec/models/spree/variant/scopes_spec.rb +0 -94
  479. data/spec/models/spree/variant/vat_price_generator_spec.rb +0 -77
  480. data/spec/models/spree/variant_property_rule_condition_spec.rb +0 -17
  481. data/spec/models/spree/variant_property_rule_spec.rb +0 -85
  482. data/spec/models/spree/variant_property_rule_value_spec.rb +0 -20
  483. data/spec/models/spree/variant_spec.rb +0 -862
  484. data/spec/models/spree/wallet_payment_source_spec.rb +0 -77
  485. data/spec/models/spree/wallet_spec.rb +0 -155
  486. data/spec/models/spree/zone_spec.rb +0 -248
  487. data/spec/rails_helper.rb +0 -46
  488. data/spec/shared_examples/calculator_shared_examples.rb +0 -10
  489. data/spec/spec_helper.rb +0 -36
  490. data/spec/support/big_decimal.rb +0 -7
  491. data/spec/support/concerns/default_price.rb +0 -44
  492. data/spec/support/concerns/payment_source.rb +0 -66
  493. data/spec/support/concerns/working_factories.rb +0 -15
  494. data/spec/support/dummy_ability.rb +0 -7
@@ -1,1687 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Spree::Order, type: :model do
6
- let(:store) { create(:store) }
7
- let(:user) { create(:user, email: "spree@example.com") }
8
- let(:order) { create(:order, user: user, store: store) }
9
- let(:promotion) do
10
- FactoryBot.create(
11
- :promotion,
12
- :with_order_adjustment,
13
- code: "discount"
14
- )
15
- end
16
- let(:code) { promotion.codes.first }
17
-
18
- describe '#finalize!' do
19
- context 'with event notifications' do
20
- it 'sends an email' do
21
- expect(Spree::Config.order_mailer_class).to receive(:confirm_email).and_call_original
22
- order.finalize!
23
- end
24
-
25
- it 'marks the order as confirmation_delivered' do
26
- expect do
27
- order.finalize!
28
- end.to change(order, :confirmation_delivered).to true
29
- end
30
-
31
- # These specs show how notifications can be removed, one at a time or
32
- # all the ones set by MailerSubscriber module
33
- context 'when removing the default email notification subscription' do
34
- before do
35
- Spree::Event.unsubscribe Spree::MailerSubscriber.order_finalized_handler
36
- end
37
-
38
- after do
39
- Spree::MailerSubscriber.subscribe!
40
- end
41
-
42
- it 'does not send the email' do
43
- expect(Spree::Config.order_mailer_class).not_to receive(:confirm_email)
44
- order.finalize!
45
- end
46
- end
47
-
48
- context 'when removing all the email notification subscriptions' do
49
- before do
50
- Spree::MailerSubscriber.unsubscribe!
51
- end
52
-
53
- after do
54
- Spree::MailerSubscriber.subscribe!
55
- end
56
-
57
- it 'does not send the email' do
58
- expect(Spree::Config.order_mailer_class).not_to receive(:confirm_email)
59
- order.finalize!
60
- end
61
- end
62
- end
63
- end
64
-
65
- context '#store' do
66
- it { is_expected.to respond_to(:store) }
67
-
68
- context 'when there is no store assigned' do
69
- subject { Spree::Order.new }
70
-
71
- context 'when there is no default store' do
72
- it "will not be valid" do
73
- expect(subject).not_to be_valid
74
- end
75
- end
76
-
77
- context "when there is a default store" do
78
- let!(:store) { create(:store) }
79
-
80
- it { is_expected.to be_valid }
81
- end
82
- end
83
-
84
- context 'when a store is assigned' do
85
- subject { Spree::Order.new(store: create(:store)) }
86
- it { is_expected.to be_valid }
87
- end
88
- end
89
-
90
- describe "#cancel!" do
91
- subject { order.cancel! }
92
-
93
- context "with captured store credit" do
94
- let!(:store_credit_payment_method) { create(:store_credit_payment_method) }
95
- let(:order_total) { 500.00 }
96
- let(:store_credit) { create(:store_credit, amount: order_total) }
97
- let(:order) { create(:order_with_line_items, user: store_credit.user, line_items_price: order_total) }
98
-
99
- before do
100
- order.add_store_credit_payments
101
- order.finalize!
102
- order.capture_payments!
103
- end
104
-
105
- it "cancels the order" do
106
- expect{ subject }.to change{ order.can_cancel? }.from(true).to(false)
107
- expect(order).to be_canceled
108
- end
109
-
110
- it "places the order into the canceled scope" do
111
- expect{ subject }.to change{ Spree::Order.canceled.include?(order) }.from(false).to(true)
112
- end
113
-
114
- it "removes the order from the not_canceled scope" do
115
- expect{ subject }.to change{ Spree::Order.not_canceled.include?(order) }.from(true).to(false)
116
- end
117
- end
118
-
119
- context "with fully refunded payment" do
120
- let(:order) { create(:completed_order_with_totals) }
121
- let(:payment_amount) { 50 }
122
- let(:payment) { create(:payment, order: order, amount: payment_amount, state: 'completed') }
123
-
124
- before do
125
- create(:refund, payment: payment, amount: payment_amount)
126
- end
127
-
128
- it "cancels the order" do
129
- expect{ subject }.to change{ order.can_cancel? }.from(true).to(false)
130
- expect(order).to be_canceled
131
- end
132
- end
133
- end
134
-
135
- context "#canceled_by" do
136
- let(:admin_user) { create :admin_user }
137
- let(:order) { create :order }
138
-
139
- before do
140
- allow(order).to receive(:cancel!)
141
- end
142
-
143
- subject { order.canceled_by(admin_user) }
144
-
145
- it 'should cancel the order' do
146
- expect(order).to receive(:cancel!)
147
- subject
148
- end
149
-
150
- it 'should save canceler_id' do
151
- subject
152
- expect(order.reload.canceler_id).to eq(admin_user.id)
153
- end
154
-
155
- it 'should save canceled_at' do
156
- subject
157
- expect(order.reload.canceled_at).to_not be_nil
158
- end
159
-
160
- it 'should have canceler' do
161
- subject
162
- expect(order.reload.canceler).to eq(admin_user)
163
- end
164
- end
165
-
166
- context "#create" do
167
- let!(:store) { create :store }
168
- let(:order) { Spree::Order.create }
169
-
170
- it "should assign an order number" do
171
- expect(order.number).not_to be_nil
172
- end
173
-
174
- it 'should create a randomized 22 character token' do
175
- expect(order.guest_token.size).to eq(22)
176
- end
177
- end
178
-
179
- context "creates shipments cost" do
180
- let(:shipment) { double }
181
-
182
- before { allow(order).to receive_messages shipments: [shipment] }
183
-
184
- it "update and persist totals" do
185
- expect(order.updater).to receive :update
186
-
187
- Spree::Deprecation.silence do
188
- order.set_shipments_cost
189
- end
190
- end
191
- end
192
-
193
- context "insufficient_stock_lines" do
194
- let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true }
195
-
196
- before { allow(order).to receive_messages(line_items: [line_item]) }
197
-
198
- it "should return line_item that has insufficient stock on hand" do
199
- expect(order.insufficient_stock_lines.size).to eq(1)
200
- expect(order.insufficient_stock_lines.include?(line_item)).to be true
201
- end
202
- end
203
-
204
- describe '#ensure_line_item_variants_are_not_deleted' do
205
- subject { order.ensure_line_item_variants_are_not_deleted }
206
-
207
- let(:order) { create :order_with_line_items }
208
-
209
- context 'when variant is destroyed' do
210
- before do
211
- allow(order).to receive(:restart_checkout_flow)
212
- order.line_items.first.variant.discard
213
- end
214
-
215
- it 'should restart checkout flow' do
216
- expect(order).to receive(:restart_checkout_flow).once
217
- subject
218
- end
219
-
220
- it 'should have error message' do
221
- subject
222
- expect(order.errors[:base]).to include(I18n.t('spree.deleted_variants_present'))
223
- end
224
-
225
- it 'should be false' do
226
- expect(subject).to be_falsey
227
- end
228
- end
229
-
230
- context 'when no variants are destroyed' do
231
- it 'should not restart checkout' do
232
- expect(order).to receive(:restart_checkout_flow).never
233
- subject
234
- end
235
-
236
- it 'should be true' do
237
- expect(subject).to be_truthy
238
- end
239
- end
240
- end
241
-
242
- context "empty!" do
243
- let!(:order) { create(:order) }
244
-
245
- before do
246
- create(:line_item, order: order)
247
- create(:shipment, order: order)
248
- create(:adjustment, adjustable: order, order: order)
249
- promotion.activate(order: order, promotion_code: code)
250
- order.recalculate
251
-
252
- # Make sure we are asserting changes
253
- expect(order.line_items).not_to be_empty
254
- expect(order.shipments).not_to be_empty
255
- expect(order.adjustments).not_to be_empty
256
- expect(order.promotions).not_to be_empty
257
- expect(order.item_total).not_to eq 0
258
- expect(order.item_count).not_to eq 0
259
- expect(order.shipment_total).not_to eq 0
260
- expect(order.adjustment_total).not_to eq 0
261
- end
262
-
263
- it "clears out line items, adjustments and update totals" do
264
- order.empty!
265
- expect(order.line_items).to be_empty
266
- expect(order.shipments).to be_empty
267
- expect(order.adjustments).to be_empty
268
- expect(order.promotions).to be_empty
269
- expect(order.item_total).to eq 0
270
- expect(order.item_count).to eq 0
271
- expect(order.shipment_total).to eq 0
272
- expect(order.adjustment_total).to eq 0
273
- end
274
- end
275
-
276
- context '#outstanding_balance' do
277
- let(:order) { create(:order_ready_to_ship, line_items_count: 3) }
278
- let(:payment) { order.payments.first }
279
-
280
- it "should handle refunds properly" do
281
- order.cancellations.short_ship([order.inventory_units.first])
282
- expect(order.outstanding_balance).to be_negative
283
- expect(order.payment_state).to eq('credit_owed')
284
- create(:refund, amount: order.outstanding_balance.abs, payment: payment, transaction_id: nil)
285
- order.reload
286
- expect(order.outstanding_balance).to eq(0)
287
- expect(order.payment_state).to eq('paid')
288
- end
289
- end
290
-
291
- context "#display_outstanding_balance" do
292
- it "returns the value as a spree money" do
293
- allow(order).to receive(:outstanding_balance) { 10.55 }
294
- expect(order.display_outstanding_balance).to eq(Spree::Money.new(10.55))
295
- end
296
- end
297
-
298
- context "#display_item_total" do
299
- it "returns the value as a spree money" do
300
- allow(order).to receive(:item_total) { 10.55 }
301
- expect(order.display_item_total).to eq(Spree::Money.new(10.55))
302
- end
303
- end
304
-
305
- context "#display_adjustment_total" do
306
- it "returns the value as a spree money" do
307
- order.adjustment_total = 10.55
308
- expect(order.display_adjustment_total).to eq(Spree::Money.new(10.55))
309
- end
310
- end
311
-
312
- context "#display_total" do
313
- it "returns the value as a spree money" do
314
- order.total = 10.55
315
- expect(order.display_total).to eq(Spree::Money.new(10.55))
316
- end
317
- end
318
-
319
- context "#currency" do
320
- context "when object currency is ABC" do
321
- before { order.currency = "ABC" }
322
-
323
- it "returns the currency from the object" do
324
- expect(order.currency).to eq("ABC")
325
- end
326
- end
327
-
328
- context "when object currency is nil" do
329
- before { order.currency = nil }
330
-
331
- it "returns the globally configured currency" do
332
- expect(order.currency).to eq("USD")
333
- end
334
- end
335
- end
336
-
337
- describe '#merge!' do
338
- let(:order1) { create(:order_with_line_items) }
339
- let(:order2) { create(:order_with_line_items) }
340
-
341
- it 'merges the orders' do
342
- order1.merge!(order2)
343
- expect(order1.line_items.count).to eq(2)
344
- expect(order2.destroyed?).to be_truthy
345
- end
346
-
347
- describe 'order_merger_class customization' do
348
- before do
349
- class TestOrderMerger
350
- def initialize(order)
351
- @order = order
352
- end
353
-
354
- def merge!(other_order, user = nil)
355
- [@order, other_order, user]
356
- end
357
- end
358
- Spree::Config.order_merger_class = TestOrderMerger
359
- end
360
-
361
- let(:user) { build(:user) }
362
-
363
- it 'uses the configured order merger' do
364
- expect(order1.merge!(order2, user)).to eq([order1, order2, user])
365
- end
366
- end
367
- end
368
-
369
- context ".register_update_hook", partial_double_verification: false do
370
- let(:order) { create(:order) }
371
-
372
- before { Spree::Order.register_update_hook :foo }
373
- after { Spree::Order.update_hooks.clear }
374
-
375
- it "calls hooks during #recalculate" do
376
- expect(order).to receive :foo
377
- order.recalculate
378
- end
379
-
380
- it "calls hook during #finalize!" do
381
- expect(order).to receive :foo
382
- order.finalize!
383
- end
384
- end
385
-
386
- context "ensure shipments will be updated" do
387
- subject(:order) { create :order }
388
- before do
389
- Spree::Shipment.create!(order: order)
390
- end
391
-
392
- ['payment', 'confirm'].each do |order_state|
393
- context "when ther order is in the #{order_state} state" do
394
- before do
395
- order.state = order_state
396
- order.shipments.create!
397
- end
398
-
399
- it "destroys current shipments" do
400
- order.ensure_updated_shipments
401
- expect(order.shipments).to be_empty
402
- end
403
-
404
- it "puts order back in address state" do
405
- order.ensure_updated_shipments
406
- expect(order.state).to eql "cart"
407
- end
408
-
409
- it "resets shipment_total" do
410
- order.update_column(:shipment_total, 5)
411
- order.ensure_updated_shipments
412
- expect(order.shipment_total).to eq(0)
413
- end
414
-
415
- it "does nothing if any shipments are ready" do
416
- shipment = create(:shipment, order: subject, state: "ready")
417
- expect { subject.ensure_updated_shipments }.not_to change { subject.reload.shipments.pluck(:id) }
418
- expect { shipment.reload }.not_to raise_error
419
- end
420
-
421
- it "does nothing if any shipments are shipped" do
422
- shipment = create(:shipment, order: subject, state: "shipped")
423
- expect { subject.ensure_updated_shipments }.not_to change { subject.reload.shipments.pluck(:id) }
424
- expect { shipment.reload }.not_to raise_error
425
- end
426
- end
427
- end
428
-
429
- context 'when the order is in address state' do
430
- before do
431
- order.state = 'address'
432
- order.shipments.create!
433
- end
434
-
435
- it "destroys current shipments" do
436
- order.ensure_updated_shipments
437
- expect(order.shipments).to be_empty
438
- end
439
-
440
- it "resets shipment_total" do
441
- order.update_column(:shipment_total, 5)
442
- order.ensure_updated_shipments
443
- expect(order.shipment_total).to eq(0)
444
- end
445
-
446
- it "puts the order in the cart state" do
447
- order.ensure_updated_shipments
448
- expect(order.state).to eq "cart"
449
- end
450
- end
451
-
452
- context 'when the order is completed' do
453
- before do
454
- order.state = 'complete'
455
- order.completed_at = Time.current
456
- order.update_column(:shipment_total, 5)
457
- order.shipments.create!
458
- end
459
-
460
- it "does not destroy the current shipments" do
461
- expect {
462
- order.ensure_updated_shipments
463
- }.not_to change { order.shipments }
464
- end
465
-
466
- it "does not reset the shipment total" do
467
- expect {
468
- order.ensure_updated_shipments
469
- }.not_to change { order.shipment_total }
470
- end
471
-
472
- it "does not put the order back in the address state" do
473
- expect {
474
- order.ensure_updated_shipments
475
- }.not_to change { order.state }
476
- end
477
- end
478
-
479
- context "except when order is completed, that's OrderInventory job" do
480
- it "doesn't touch anything" do
481
- allow(order).to receive_messages completed?: true
482
- order.update_column(:shipment_total, 5)
483
- order.shipments.create!
484
-
485
- expect {
486
- order.ensure_updated_shipments
487
- }.not_to change { order.shipment_total }
488
-
489
- expect {
490
- order.ensure_updated_shipments
491
- }.not_to change { order.shipments }
492
-
493
- expect {
494
- order.ensure_updated_shipments
495
- }.not_to change { order.state }
496
- end
497
- end
498
- end
499
-
500
- describe "#tax_address" do
501
- let(:order) { build(:order, ship_address: ship_address, bill_address: bill_address, store: store) }
502
- let(:store) { build(:store) }
503
-
504
- before { stub_spree_preferences(tax_using_ship_address: tax_using_ship_address) }
505
- subject { order.tax_address }
506
-
507
- context "when the order has no addresses" do
508
- let(:ship_address) { nil }
509
- let(:bill_address) { nil }
510
-
511
- context "when tax_using_ship_address is true" do
512
- let(:tax_using_ship_address) { true }
513
-
514
- it 'returns the stores default cart tax location' do
515
- expect(subject).to eq(store.default_cart_tax_location)
516
- end
517
- end
518
-
519
- context "when tax_using_ship_address is not true" do
520
- let(:tax_using_ship_address) { false }
521
-
522
- it 'returns the stores default cart tax location' do
523
- expect(subject).to eq(store.default_cart_tax_location)
524
- end
525
- end
526
- end
527
-
528
- context "when the order has addresses" do
529
- let(:ship_address) { build(:address) }
530
- let(:bill_address) { build(:address) }
531
-
532
- context "when tax_using_ship_address is true" do
533
- let(:tax_using_ship_address) { true }
534
-
535
- it 'returns ship_address' do
536
- expect(subject).to eq(order.ship_address)
537
- end
538
- end
539
-
540
- context "when tax_using_ship_address is not true" do
541
- let(:tax_using_ship_address) { false }
542
-
543
- it "returns bill_address" do
544
- expect(subject).to eq(order.bill_address)
545
- end
546
- end
547
- end
548
- end
549
-
550
- describe "#restart_checkout_flow" do
551
- context "when in cart state" do
552
- let(:order) { create(:order_with_totals, state: "cart") }
553
-
554
- it "remains in cart state" do
555
- expect { order.restart_checkout_flow }.not_to change { order.state }
556
- end
557
- end
558
- it "updates the state column to the first checkout_steps value" do
559
- order = create(:order_with_totals, state: "delivery")
560
- expect(order.checkout_steps).to eql %w(address delivery payment confirm complete)
561
- expect{ order.restart_checkout_flow }.to change{ order.state }.from("delivery").to("address")
562
- end
563
-
564
- context "without line items" do
565
- it "updates the state column to cart" do
566
- order = create(:order, state: "delivery")
567
- expect{ order.restart_checkout_flow }.to change{ order.state }.from("delivery").to("cart")
568
- end
569
- end
570
- end
571
-
572
- # Regression tests for https://github.com/spree/spree/issues/4072
573
- context "#state_changed" do
574
- let(:order) { FactoryBot.create(:order) }
575
-
576
- it "logs state changes" do
577
- order.update_column(:payment_state, 'balance_due')
578
- order.payment_state = 'paid'
579
- expect(order.state_changes).to be_empty
580
- Spree::Deprecation.silence do
581
- order.state_changed('payment')
582
- end
583
- state_change = order.state_changes.find_by(name: 'payment')
584
- expect(state_change.previous_state).to eq('balance_due')
585
- expect(state_change.next_state).to eq('paid')
586
- end
587
-
588
- it "does not do anything if state does not change" do
589
- order.update_column(:payment_state, 'balance_due')
590
- expect(order.state_changes).to be_empty
591
- Spree::Deprecation.silence do
592
- order.state_changed('payment')
593
- end
594
- expect(order.state_changes).to be_empty
595
- end
596
- end
597
-
598
- # Regression test for https://github.com/spree/spree/issues/4199
599
- context "#available_payment_methods" do
600
- it "includes frontend payment methods" do
601
- payment_method = Spree::PaymentMethod::Check.create!({
602
- name: "Fake",
603
- active: true,
604
- available_to_users: true,
605
- available_to_admin: false
606
- })
607
- expect(order.available_payment_methods).to include(payment_method)
608
- end
609
-
610
- it "includes 'both' payment methods" do
611
- payment_method = Spree::PaymentMethod::Check.create!({
612
- name: "Fake",
613
- active: true,
614
- available_to_users: true,
615
- available_to_admin: true
616
- })
617
- expect(order.available_payment_methods).to include(payment_method)
618
- end
619
-
620
- it "does not include a payment method twice" do
621
- payment_method = Spree::PaymentMethod::Check.create!({
622
- name: "Fake",
623
- active: true,
624
- available_to_users: true,
625
- available_to_admin: true
626
- })
627
- expect(order.available_payment_methods.count).to eq(1)
628
- expect(order.available_payment_methods).to include(payment_method)
629
- end
630
-
631
- it "does not include inactive payment methods" do
632
- Spree::PaymentMethod::Check.create!({
633
- name: "Fake",
634
- active: false,
635
- available_to_users: true,
636
- available_to_admin: true
637
- })
638
- expect(order.available_payment_methods.count).to eq(0)
639
- end
640
-
641
- context "with more than one payment method" do
642
- subject { order.available_payment_methods }
643
-
644
- let!(:first_method) {
645
- FactoryBot.create(:payment_method, available_to_users: true,
646
- available_to_admin: true)
647
- }
648
- let!(:second_method) {
649
- FactoryBot.create(:payment_method, available_to_users: true,
650
- available_to_admin: true)
651
- }
652
-
653
- before do
654
- second_method.move_to_top
655
- end
656
-
657
- it "respects the order of methods based on position" do
658
- expect(subject).to eq([second_method, first_method])
659
- end
660
- end
661
-
662
- context 'when the order has a store' do
663
- let(:order) { create(:order) }
664
-
665
- let!(:store_with_payment_methods) do
666
- create(:store,
667
- payment_methods: [payment_method_with_store])
668
- end
669
- let!(:payment_method_with_store) { create(:payment_method) }
670
- let!(:store_without_payment_methods) { create(:store) }
671
- let!(:payment_method_without_store) { create(:payment_method) }
672
-
673
- context 'when the store has payment methods' do
674
- before { order.update!(store: store_with_payment_methods) }
675
-
676
- it 'returns only the matching payment methods for that store' do
677
- expect(order.available_payment_methods).to match_array(
678
- [payment_method_with_store]
679
- )
680
- end
681
-
682
- context 'and the store has an extra payment method unavailable to users' do
683
- let!(:admin_only_payment_method) do
684
- create(:payment_method,
685
- available_to_users: false,
686
- available_to_admin: true)
687
- end
688
-
689
- before do
690
- store_with_payment_methods.payment_methods << admin_only_payment_method
691
- end
692
-
693
- it 'returns only the payment methods available to users for that store' do
694
- expect(order.available_payment_methods).to match_array(
695
- [payment_method_with_store]
696
- )
697
- end
698
- end
699
- end
700
-
701
- context 'when the store does not have payment methods' do
702
- before { order.update!(store: store_without_payment_methods) }
703
-
704
- it 'returns all matching payment methods regardless of store' do
705
- expect(order.available_payment_methods).to match_array(
706
- [payment_method_with_store, payment_method_without_store]
707
- )
708
- end
709
- end
710
- end
711
- end
712
-
713
- context "#apply_shipping_promotions" do
714
- it "calls out to the Shipping promotion handler" do
715
- expect_any_instance_of(Spree::PromotionHandler::Shipping).to(
716
- receive(:activate)
717
- ).and_call_original
718
-
719
- expect(order.updater).to receive(:update).and_call_original
720
-
721
- order.apply_shipping_promotions
722
- end
723
- end
724
-
725
- context "#products" do
726
- before :each do
727
- @variant1 = mock_model(Spree::Variant, product: "product1")
728
- @variant2 = mock_model(Spree::Variant, product: "product2")
729
- @line_items = [mock_model(Spree::LineItem, product: "product1", variant: @variant1, variant_id: @variant1.id, quantity: 1),
730
- mock_model(Spree::LineItem, product: "product2", variant: @variant2, variant_id: @variant2.id, quantity: 2)]
731
- allow(order).to receive_messages(line_items: @line_items)
732
- end
733
-
734
- it "contains?" do
735
- expect(order.contains?(@variant1)).to be true
736
- end
737
-
738
- it "gets the quantity of a given variant" do
739
- expect(order.quantity_of(@variant1)).to eq(1)
740
-
741
- @variant3 = mock_model(Spree::Variant, product: "product3")
742
- expect(order.quantity_of(@variant3)).to eq(0)
743
- end
744
-
745
- it "can find a line item matching a given variant" do
746
- expect(order.find_line_item_by_variant(@variant1)).not_to be_nil
747
- expect(order.find_line_item_by_variant(mock_model(Spree::Variant))).to be_nil
748
- end
749
-
750
- context "match line item with options", partial_double_verification: false do
751
- before do
752
- Spree::Order.register_line_item_comparison_hook(:foos_match)
753
- end
754
-
755
- after do
756
- # reset to avoid test pollution
757
- Spree::Order.line_item_comparison_hooks = Set.new
758
- end
759
-
760
- it "matches line item when options match" do
761
- allow(order).to receive(:foos_match).and_return(true)
762
- expect(order.line_item_options_match(@line_items.first, { foos: { bar: :zoo } })).to be true
763
- end
764
-
765
- it "does not match line item without options" do
766
- allow(order).to receive(:foos_match).and_return(false)
767
- expect(order.line_item_options_match(@line_items.first, {})).to be false
768
- end
769
- end
770
- end
771
-
772
- describe "#generate_order_number" do
773
- let(:order) { build(:order) }
774
-
775
- context "with default app configuration" do
776
- it 'calls the default order number generator' do
777
- expect_any_instance_of(Spree::Order::NumberGenerator).to receive(:generate)
778
- order.generate_order_number
779
- end
780
- end
781
-
782
- context "with order number generator configured" do
783
- class TruthNumberGenerator
784
- def initialize(options = {}); end
785
-
786
- def generate
787
- '42'
788
- end
789
- end
790
-
791
- before do
792
- expect(Spree::Config).to receive(:order_number_generator) do
793
- TruthNumberGenerator.new
794
- end
795
- end
796
-
797
- it 'calls the configured order number generator' do
798
- order.generate_order_number
799
- expect(order.number).to eq '42'
800
- end
801
- end
802
-
803
- context "with number already present" do
804
- before do
805
- order.number = '123'
806
- end
807
-
808
- it 'does not generate new number' do
809
- order.generate_order_number
810
- expect(order.number).to eq '123'
811
- end
812
- end
813
-
814
- context "passing options" do
815
- it 'is deprecated' do
816
- expect(Spree::Deprecation).to receive(:warn)
817
- order.generate_order_number(length: 2)
818
- end
819
- end
820
- end
821
-
822
- context "#associate_user!" do
823
- let!(:user) { FactoryBot.create(:user) }
824
-
825
- it "should associate a user with a persisted order" do
826
- order = FactoryBot.create(:order_with_line_items, created_by: nil)
827
- order.user = nil
828
- order.email = nil
829
- order.associate_user!(user)
830
- expect(order.user).to eq(user)
831
- expect(order.email).to eq(user.email)
832
- expect(order.created_by).to eq(user)
833
-
834
- # verify that the changes we made were persisted
835
- order.reload
836
- expect(order.user).to eq(user)
837
- expect(order.email).to eq(user.email)
838
- expect(order.created_by).to eq(user)
839
- end
840
-
841
- it "should not overwrite the created_by if it already is set" do
842
- creator = create(:user)
843
- order = FactoryBot.create(:order_with_line_items, created_by: creator)
844
-
845
- order.user = nil
846
- order.email = nil
847
- order.associate_user!(user)
848
- expect(order.user).to eq(user)
849
- expect(order.email).to eq(user.email)
850
- expect(order.created_by).to eq(creator)
851
-
852
- # verify that the changes we made were persisted
853
- order.reload
854
- expect(order.user).to eq(user)
855
- expect(order.email).to eq(user.email)
856
- expect(order.created_by).to eq(creator)
857
- end
858
-
859
- it "should associate a user with a non-persisted order" do
860
- order = Spree::Order.new
861
-
862
- expect do
863
- order.associate_user!(user)
864
- end.to change { [order.user, order.email] }.from([nil, nil]).to([user, user.email])
865
- end
866
-
867
- it "should not persist an invalid address" do
868
- address = Spree::Address.new
869
- order.user = nil
870
- order.email = nil
871
- order.ship_address = address
872
- expect do
873
- order.associate_user!(user)
874
- end.not_to change { address.persisted? }.from(false)
875
- end
876
- end
877
-
878
- context "#assign_default_user_addresses" do
879
- let(:order) { Spree::Order.new }
880
-
881
- subject { order.assign_default_user_addresses }
882
-
883
- context "when no user is associated to the order" do
884
- it "does not associate any bill address" do
885
- expect { subject }.not_to change { order.bill_address }.from(nil)
886
- end
887
-
888
- it "does not associate any ship address" do
889
- expect { subject }.not_to change { order.ship_address }.from(nil)
890
- end
891
- end
892
-
893
- context "when user is associated to the order" do
894
- let(:user) { build_stubbed(:user) }
895
- let(:bill_address) { nil }
896
- let(:ship_address) { nil }
897
-
898
- before do
899
- order.associate_user!(user)
900
- user.bill_address = bill_address
901
- user.ship_address = ship_address
902
- end
903
-
904
- context "but has no bill address associated" do
905
- it "does not associate any bill address" do
906
- expect { subject }.not_to change { order.bill_address }.from(nil)
907
- end
908
- end
909
-
910
- context "and has an invalid bill address associated " do
911
- let(:bill_address) { build(:address, firstname: nil) } # invalid address
912
-
913
- it "does not associate any bill address" do
914
- expect { subject }.not_to change { order.bill_address }.from(nil)
915
- end
916
- end
917
-
918
- context "and has a valid address associated " do
919
- let(:bill_address) { build(:address) }
920
-
921
- it "does associate user bill address" do
922
- expect { subject }.to change { order.bill_address }.from(nil).to(bill_address)
923
- end
924
- end
925
-
926
- context "but has no ship address associated" do
927
- it "does not associate any ship address" do
928
- expect { subject }.not_to change { order.ship_address }.from(nil)
929
- end
930
- end
931
-
932
- context "and has an invalid ship address associated " do
933
- let(:ship_address) { build(:address, firstname: nil) } # invalid address
934
-
935
- it "does not associate any ship address" do
936
- expect { subject }.not_to change { order.ship_address }.from(nil)
937
- end
938
- end
939
-
940
- context "and has a valid ship address associated" do
941
- let(:ship_address) { build(:address) }
942
-
943
- it "does associate user ship address" do
944
- expect { subject }.to change { order.ship_address }.from(nil).to(ship_address)
945
- end
946
-
947
- context 'when checkout step does not include delivery' do
948
- before do
949
- expect(order).to receive(:checkout_steps) { %w[some step] }
950
- end
951
-
952
- it "does not associate any ship address" do
953
- expect { subject }.not_to change { order.ship_address }.from(nil)
954
- end
955
- end
956
- end
957
- end
958
- end
959
-
960
- context "#can_ship?" do
961
- let(:order) { Spree::Order.create }
962
-
963
- it "should be true for order in the 'complete' state" do
964
- allow(order).to receive_messages(complete?: true)
965
- expect(order.can_ship?).to be true
966
- end
967
-
968
- it "should be true for order in the 'resumed' state" do
969
- allow(order).to receive_messages(resumed?: true)
970
- expect(order.can_ship?).to be true
971
- end
972
-
973
- it "should be true for an order in the 'awaiting return' state" do
974
- allow(order).to receive_messages(awaiting_return?: true)
975
- expect(order.can_ship?).to be true
976
- end
977
-
978
- it "should be true for an order in the 'returned' state" do
979
- allow(order).to receive_messages(returned?: true)
980
- expect(order.can_ship?).to be true
981
- end
982
-
983
- it "should be false if the order is neither in the 'complete' nor 'resumed' state" do
984
- allow(order).to receive_messages(resumed?: false, complete?: false)
985
- expect(order.can_ship?).to be false
986
- end
987
- end
988
-
989
- context "#completed?" do
990
- it "should indicate if order is completed" do
991
- order.completed_at = nil
992
- expect(order.completed?).to be false
993
-
994
- order.completed_at = Time.current
995
- expect(order.completed?).to be true
996
- end
997
- end
998
-
999
- context "#allow_checkout?" do
1000
- it "should be true if there are line_items in the order" do
1001
- allow(order).to receive_message_chain(:line_items, count: 1)
1002
- expect(order.checkout_allowed?).to be true
1003
- end
1004
- it "should be false if there are no line_items in the order" do
1005
- allow(order).to receive_message_chain(:line_items, count: 0)
1006
- expect(order.checkout_allowed?).to be false
1007
- end
1008
- end
1009
-
1010
- context "#amount" do
1011
- before do
1012
- @order = create(:order, user: user)
1013
- @order.line_items = [create(:line_item, price: 1.0, quantity: 2),
1014
- create(:line_item, price: 1.0, quantity: 1)]
1015
- end
1016
- it "should return the correct lum sum of items" do
1017
- expect(@order.amount).to eq(3.0)
1018
- end
1019
- end
1020
-
1021
- context "#backordered?" do
1022
- it 'is backordered if one of the shipments is backordered' do
1023
- allow(order).to receive_messages(shipments: [mock_model(Spree::Shipment, backordered?: false),
1024
- mock_model(Spree::Shipment, backordered?: true)])
1025
- expect(order).to be_backordered
1026
- end
1027
- end
1028
-
1029
- context "#can_cancel?" do
1030
- it "should be false for completed order in the canceled state" do
1031
- order.state = 'canceled'
1032
- order.shipment_state = 'ready'
1033
- order.completed_at = Time.current
1034
- expect(order.can_cancel?).to be false
1035
- end
1036
-
1037
- it "should be true for completed order with no shipment" do
1038
- order.state = 'complete'
1039
- order.shipment_state = nil
1040
- order.completed_at = Time.current
1041
- expect(order.can_cancel?).to be true
1042
- end
1043
- end
1044
-
1045
- context "#tax_total" do
1046
- it "adds included tax and additional tax" do
1047
- allow(order).to receive_messages(additional_tax_total: 10, included_tax_total: 20)
1048
-
1049
- expect(order.tax_total).to eq 30
1050
- end
1051
- end
1052
-
1053
- # Regression test for https://github.com/spree/spree/issues/4923
1054
- context "locking" do
1055
- let(:order) { Spree::Order.create } # need a persisted in order to test locking
1056
-
1057
- it 'can lock' do
1058
- order.with_lock {}
1059
- end
1060
- end
1061
-
1062
- describe "#item_total_excluding_vat" do
1063
- it "sums all of the line items' pre tax amounts" do
1064
- subject.line_items = [
1065
- Spree::LineItem.new(price: 10, quantity: 2, included_tax_total: 15.0),
1066
- Spree::LineItem.new(price: 30, quantity: 1, included_tax_total: 16.0)
1067
- ]
1068
- # (2*10)-15 + 30-16 = 5 + 14 = 19
1069
- expect(subject.item_total_excluding_vat).to eq 19.0
1070
- end
1071
- end
1072
-
1073
- context "#refund_total" do
1074
- let(:order) { create(:order_with_line_items) }
1075
- let!(:payment) { create(:payment_with_refund, order: order, amount: 5, refund_amount: 3) }
1076
- let!(:payment2) { create(:payment_with_refund, order: order, amount: 5, refund_amount: 2.5) }
1077
-
1078
- it "sums the reimbursment refunds on the order" do
1079
- expect(order.refund_total).to eq(5.5)
1080
- end
1081
- end
1082
-
1083
- describe '#quantity' do
1084
- # Uses a persisted record, as the quantity is retrieved via a DB count
1085
- let(:order) { create :order_with_line_items, line_items_count: 3 }
1086
-
1087
- it 'sums the quantity of all line items' do
1088
- expect(order.quantity).to eq 3
1089
- end
1090
- end
1091
-
1092
- describe '#has_non_reimbursement_related_refunds?' do
1093
- subject do
1094
- order.has_non_reimbursement_related_refunds?
1095
- end
1096
-
1097
- context 'no refunds exist' do
1098
- it { is_expected.to eq false }
1099
- end
1100
-
1101
- context 'a non-reimbursement related refund exists' do
1102
- let(:order) { refund.payment.order }
1103
- let(:refund) { create(:refund, reimbursement_id: nil, amount: 5) }
1104
-
1105
- it { is_expected.to eq true }
1106
- end
1107
-
1108
- context 'an old-style refund exists' do
1109
- let(:order) { create(:order_ready_to_ship) }
1110
- let(:payment) { order.payments.first.tap { |p| allow(p).to receive_messages(profiles_supported?: false) } }
1111
- let!(:refund_payment) {
1112
- build(:payment, amount: -1, order: order, state: 'completed', source: payment).tap do |p|
1113
- allow(p).to receive_messages(profiles_supported?: false)
1114
- p.save!
1115
- end
1116
- }
1117
-
1118
- it { is_expected.to eq true }
1119
- end
1120
-
1121
- context 'a reimbursement related refund exists' do
1122
- let(:order) { refund.payment.order }
1123
- let(:refund) { create(:refund, reimbursement_id: 123, amount: 5, payment_amount: 14) }
1124
-
1125
- it { is_expected.to eq false }
1126
- end
1127
- end
1128
-
1129
- describe "#create_proposed_shipments" do
1130
- subject(:order) { create(:order) }
1131
- it "assigns the coordinator returned shipments to its shipments" do
1132
- shipment = build(:shipment)
1133
- allow_any_instance_of(Spree::Stock::SimpleCoordinator).to receive(:shipments).and_return([shipment])
1134
- subject.create_proposed_shipments
1135
- expect(subject.shipments).to eq [shipment]
1136
- end
1137
-
1138
- it "raises an error if any shipments are ready" do
1139
- shipment = create(:shipment, order: subject, state: "ready")
1140
-
1141
- expect {
1142
- expect {
1143
- subject.create_proposed_shipments
1144
- }.to raise_error(Spree::Order::CannotRebuildShipments)
1145
- }.not_to change { subject.reload.shipments.pluck(:id) }
1146
-
1147
- expect { shipment.reload }.not_to raise_error
1148
- end
1149
-
1150
- it "raises an error if any shipments are shipped" do
1151
- shipment = create(:shipment, order: subject, state: "shipped")
1152
- expect {
1153
- expect {
1154
- subject.create_proposed_shipments
1155
- }.to raise_error(Spree::Order::CannotRebuildShipments)
1156
- }.not_to change { subject.reload.shipments.pluck(:id) }
1157
-
1158
- expect { shipment.reload }.not_to raise_error
1159
- end
1160
- end
1161
-
1162
- describe "#all_inventory_units_returned?" do
1163
- let(:order) { create(:order_with_line_items, line_items_count: 3) }
1164
-
1165
- subject { order.all_inventory_units_returned? }
1166
-
1167
- context "all inventory units are returned" do
1168
- before { order.inventory_units.update_all(state: 'returned') }
1169
-
1170
- it "is true" do
1171
- expect(subject).to eq true
1172
- end
1173
- end
1174
-
1175
- context "some inventory units are returned" do
1176
- before do
1177
- order.inventory_units.first.update_attribute(:state, 'returned')
1178
- end
1179
-
1180
- it "is false" do
1181
- expect(subject).to eq false
1182
- end
1183
- end
1184
-
1185
- context "no inventory units are returned" do
1186
- it "is false" do
1187
- expect(subject).to eq false
1188
- end
1189
- end
1190
- end
1191
-
1192
- context "store credit" do
1193
- shared_examples "check total store credit from payments" do
1194
- context "with valid payments" do
1195
- let(:order) { payment.order }
1196
- let!(:payment) { create(:store_credit_payment) }
1197
- let!(:second_payment) { create(:store_credit_payment, order: order) }
1198
-
1199
- subject { order }
1200
-
1201
- it "returns the sum of the payment amounts" do
1202
- expect(subject.total_applicable_store_credit).to eq(payment.amount + second_payment.amount)
1203
- end
1204
- end
1205
-
1206
- context "without valid payments" do
1207
- let(:order) { create(:order) }
1208
-
1209
- subject { order }
1210
-
1211
- it "returns 0" do
1212
- expect(subject.total_applicable_store_credit).to be_zero
1213
- end
1214
- end
1215
- end
1216
-
1217
- describe "#add_store_credit_payments" do
1218
- let(:order_total) { 500.00 }
1219
-
1220
- before { create(:store_credit_payment_method) }
1221
-
1222
- subject { order.add_store_credit_payments }
1223
-
1224
- context "there is no store credit" do
1225
- let(:order) { create(:order, total: order_total) }
1226
-
1227
- context "there is a credit card payment" do
1228
- let!(:cc_payment) { create(:payment, order: order, amount: order_total) }
1229
-
1230
- before do
1231
- # callbacks recalculate total based on line items
1232
- # this ensures the total is what we expect
1233
- order.update_column(:total, order_total)
1234
- subject
1235
- order.reload
1236
- end
1237
-
1238
- it "charges the outstanding balance to the credit card" do
1239
- expect(order.errors.messages).to be_empty
1240
- expect(order.payments.count).to eq 1
1241
- expect(order.payments.first.source).to be_a(Spree::CreditCard)
1242
- expect(order.payments.first.amount).to eq order_total
1243
- end
1244
- end
1245
- end
1246
-
1247
- context 'there is store credit in another currency' do
1248
- let(:order) { create(:order_with_totals, user: user, line_items_price: order_total).tap(&:recalculate) }
1249
- let!(:store_credit_usd) { create(:store_credit, user: user, amount: 1, currency: 'USD') }
1250
- let!(:store_credit_gbp) { create(:store_credit, user: user, amount: 1, currency: 'GBP') }
1251
- let(:user) { create(:user) }
1252
-
1253
- it 'only adds the credit in the matching currency' do
1254
- expect {
1255
- order.add_store_credit_payments
1256
- }.to change {
1257
- order.payments.count
1258
- }.by(1)
1259
-
1260
- applied_store_credits = order.payments.store_credits.map(&:source)
1261
- expect(applied_store_credits).to match_array([store_credit_usd])
1262
- end
1263
- end
1264
-
1265
- context "there is enough store credit to pay for the entire order" do
1266
- let(:store_credit) { create(:store_credit, amount: order_total) }
1267
- let(:order) { create(:order_with_totals, user: store_credit.user, line_items_price: order_total).tap(&:recalculate) }
1268
-
1269
- context "there are no other payments" do
1270
- before do
1271
- subject
1272
- order.reload
1273
- end
1274
-
1275
- it "creates a store credit payment for the full amount" do
1276
- expect(order.errors.messages).to be_empty
1277
- expect(order.payments.count).to eq 1
1278
- expect(order.payments.first).to be_store_credit
1279
- expect(order.payments.first.amount).to eq order_total
1280
- end
1281
- end
1282
-
1283
- context "there is a credit card payment" do
1284
- it "invalidates the credit card payment" do
1285
- cc_payment = create(:payment, order: order)
1286
- expect { subject }.to change { cc_payment.reload.state }.to 'invalid'
1287
- end
1288
- end
1289
- end
1290
-
1291
- context "the available store credit is not enough to pay for the entire order" do
1292
- let(:order_total) { 500 }
1293
- let(:store_credit_total) { order_total - 100 }
1294
- let(:store_credit) { create(:store_credit, amount: store_credit_total) }
1295
- let(:order) { create(:order_with_totals, user: store_credit.user, line_items_price: order_total).tap(&:recalculate) }
1296
-
1297
- context "there are no other payments" do
1298
- it "adds an error to the model" do
1299
- expect(subject).to be false
1300
- expect(order.errors.full_messages).to include(I18n.t('spree.store_credit.errors.unable_to_fund'))
1301
- end
1302
- end
1303
-
1304
- context "there is a completed credit card payment" do
1305
- let!(:cc_payment) { create(:payment, order: order, state: "completed", amount: 100) }
1306
-
1307
- it "successfully creates the store credit payments" do
1308
- expect { subject }.to change { order.payments.count }.from(1).to(2)
1309
- expect(order.errors).to be_empty
1310
- end
1311
- end
1312
-
1313
- context "there is a credit card payment" do
1314
- let!(:cc_payment) { create(:payment, order: order, state: "checkout") }
1315
-
1316
- before do
1317
- subject
1318
- end
1319
-
1320
- it "charges the outstanding balance to the credit card" do
1321
- expect(order.errors.messages).to be_empty
1322
- expect(order.payments.count).to eq 2
1323
- expect(order.payments.first.source).to be_a(Spree::CreditCard)
1324
- expect(order.payments.first.amount).to eq 100
1325
- end
1326
-
1327
- # see associated comment in order_decorator#add_store_credit_payments
1328
- context "the store credit is already in the pending state" do
1329
- before do
1330
- order.payments.store_credits.last.authorize!
1331
- order.add_store_credit_payments
1332
- end
1333
-
1334
- it "charges the outstanding balance to the credit card" do
1335
- expect(order.errors.messages).to be_empty
1336
- expect(order.payments.count).to eq 2
1337
- expect(order.payments.first.source).to be_a(Spree::CreditCard)
1338
- expect(order.payments.first.amount).to eq 100
1339
- end
1340
- end
1341
- end
1342
- end
1343
-
1344
- context "there are multiple store credits" do
1345
- context "they have different credit type priorities" do
1346
- let(:amount_difference) { 100 }
1347
- let!(:primary_store_credit) { create(:store_credit, amount: (order_total - amount_difference)) }
1348
- let!(:secondary_store_credit) { create(:store_credit, amount: order_total, user: primary_store_credit.user, credit_type: create(:secondary_credit_type)) }
1349
- let(:order) { create(:order_with_totals, user: primary_store_credit.user, line_items_price: order_total).tap(&:recalculate) }
1350
-
1351
- before do
1352
- subject
1353
- order.reload
1354
- end
1355
-
1356
- it "uses the primary store credit type over the secondary" do
1357
- primary_payment = order.payments.detect{ |x| x.source == primary_store_credit }
1358
- secondary_payment = order.payments.detect{ |x| x.source == secondary_store_credit }
1359
-
1360
- expect(order.payments.size).to eq 2
1361
- expect(primary_payment.source).to eq primary_store_credit
1362
- expect(secondary_payment.source).to eq secondary_store_credit
1363
- expect(primary_payment.amount).to eq(order_total - amount_difference)
1364
- expect(secondary_payment.amount).to eq(amount_difference)
1365
- end
1366
- end
1367
- end
1368
- end
1369
-
1370
- describe "#covered_by_store_credit" do
1371
- subject do
1372
- order.covered_by_store_credit
1373
- end
1374
-
1375
- let(:order) { create(:order_with_line_items, user: user, store: store) }
1376
-
1377
- context "order doesn't have an associated user" do
1378
- let(:user) { nil }
1379
- it { is_expected.to eq(false) }
1380
- end
1381
-
1382
- context "order has an associated user" do
1383
- context "user has enough store credit to pay for the order" do
1384
- let!(:credit) { create(:store_credit, user: user, amount: 1000) }
1385
- it { is_expected.to eq(true) }
1386
- end
1387
-
1388
- context "user does not have enough store credit to pay for the order" do
1389
- let!(:credit) { create(:store_credit, user: user, amount: 1) }
1390
- it { is_expected.to eq(false) }
1391
- end
1392
- end
1393
- end
1394
-
1395
- describe "#total_available_store_credit" do
1396
- subject do
1397
- order.total_available_store_credit
1398
- end
1399
-
1400
- context "order does not have an associated user" do
1401
- let(:user) { nil }
1402
- it { is_expected.to eq(0) }
1403
- end
1404
-
1405
- context "order has an associated user" do
1406
- let!(:credit) { create(:store_credit, user: user, amount: 25) }
1407
- it { is_expected.to eq(25) }
1408
- end
1409
- end
1410
-
1411
- describe "#order_total_after_store_credit" do
1412
- let(:order_total) { 100.0 }
1413
-
1414
- subject { create(:order, total: order_total) }
1415
-
1416
- before do
1417
- allow(subject).to receive_messages(total_applicable_store_credit: applicable_store_credit)
1418
- end
1419
-
1420
- context "order's user has store credits" do
1421
- let(:applicable_store_credit) { 10.0 }
1422
-
1423
- it "deducts the applicable store credit" do
1424
- expect(subject.order_total_after_store_credit).to eq(order_total - applicable_store_credit)
1425
- end
1426
- end
1427
-
1428
- context "order's user does not have any store credits" do
1429
- let(:applicable_store_credit) { 0.0 }
1430
-
1431
- it "returns the order total" do
1432
- expect(subject.order_total_after_store_credit).to eq order_total
1433
- end
1434
- end
1435
- end
1436
-
1437
- describe "#total_applicable_store_credit" do
1438
- context "order is in the confirm state" do
1439
- before { order.update(state: 'confirm') }
1440
- include_examples "check total store credit from payments"
1441
- end
1442
-
1443
- context "order is completed" do
1444
- before { order.update(state: 'complete') }
1445
- include_examples "check total store credit from payments"
1446
- end
1447
-
1448
- context "order is in any state other than confirm or complete" do
1449
- context "the associated user has store credits" do
1450
- let(:store_credit) { create(:store_credit) }
1451
- let(:order) { create(:order, user: store_credit.user) }
1452
-
1453
- subject { order }
1454
-
1455
- context "the store credit is more than the order total" do
1456
- let(:order_total) { store_credit.amount - 1 }
1457
-
1458
- before { order.update(total: order_total) }
1459
-
1460
- it "returns the order total" do
1461
- expect(subject.total_applicable_store_credit).to eq order_total
1462
- end
1463
- end
1464
-
1465
- context "the store credit is less than the order total" do
1466
- let(:order_total) { store_credit.amount * 10 }
1467
-
1468
- before { order.update(total: order_total) }
1469
-
1470
- it "returns the store credit amount" do
1471
- expect(subject.total_applicable_store_credit).to eq store_credit.amount
1472
- end
1473
- end
1474
- end
1475
-
1476
- context "the associated user does not have store credits" do
1477
- let(:order) { create(:order) }
1478
-
1479
- subject { order }
1480
-
1481
- it "returns 0" do
1482
- expect(subject.total_applicable_store_credit).to be_zero
1483
- end
1484
- end
1485
-
1486
- context "the order does not have an associated user" do
1487
- subject { create(:order, user: nil) }
1488
-
1489
- it "returns 0" do
1490
- expect(subject.total_applicable_store_credit).to be_zero
1491
- end
1492
- end
1493
- end
1494
- end
1495
-
1496
- describe "#display_total_applicable_store_credit" do
1497
- let(:total_applicable_store_credit) { 10.00 }
1498
-
1499
- subject { create(:order) }
1500
-
1501
- before { allow(subject).to receive_messages(total_applicable_store_credit: total_applicable_store_credit) }
1502
-
1503
- it "returns a money instance" do
1504
- expect(subject.display_total_applicable_store_credit).to be_a(Spree::Money)
1505
- end
1506
-
1507
- it "returns a negative amount" do
1508
- expect(subject.display_total_applicable_store_credit.money.cents).to eq(total_applicable_store_credit * -100.0)
1509
- end
1510
- end
1511
-
1512
- describe "#record_ip_address" do
1513
- let(:ip_address) { "127.0.0.1" }
1514
-
1515
- subject { -> { order.record_ip_address(ip_address) } }
1516
-
1517
- it "updates the last used IP address" do
1518
- expect(subject).to change(order, :last_ip_address).to(ip_address)
1519
- end
1520
-
1521
- # IP address tracking should not raise validation exceptions
1522
- context "with an invalid order" do
1523
- before { allow(order).to receive(:valid?).and_return(false) }
1524
-
1525
- it "updates the IP address" do
1526
- expect(subject).to change(order, :last_ip_address).to(ip_address)
1527
- end
1528
- end
1529
- end
1530
-
1531
- describe "#display_order_total_after_store_credit" do
1532
- let(:order_total_after_store_credit) { 10.00 }
1533
-
1534
- subject { create(:order) }
1535
-
1536
- before { allow(subject).to receive_messages(order_total_after_store_credit: order_total_after_store_credit) }
1537
-
1538
- it "returns a money instance" do
1539
- expect(subject.display_order_total_after_store_credit).to be_a(Spree::Money)
1540
- end
1541
-
1542
- it "returns the order_total_after_store_credit amount" do
1543
- expect(subject.display_order_total_after_store_credit.money.cents).to eq(order_total_after_store_credit * 100.0)
1544
- end
1545
- end
1546
-
1547
- describe "#display_total_available_store_credit" do
1548
- let(:total_available_store_credit) { 10.00 }
1549
-
1550
- subject { create(:order) }
1551
-
1552
- before { allow(subject).to receive_messages(total_available_store_credit: total_available_store_credit) }
1553
-
1554
- it "returns a money instance" do
1555
- expect(subject.display_total_available_store_credit).to be_a(Spree::Money)
1556
- end
1557
-
1558
- it "returns the total_available_store_credit amount" do
1559
- expect(subject.display_total_available_store_credit.money.cents).to eq(total_available_store_credit * 100.0)
1560
- end
1561
- end
1562
-
1563
- describe "#display_store_credit_remaining_after_capture" do
1564
- let(:total_available_store_credit) { 10.00 }
1565
- let(:total_applicable_store_credit) { 5.00 }
1566
-
1567
- subject { create(:order) }
1568
-
1569
- before do
1570
- allow(subject).to receive_messages(total_available_store_credit: total_available_store_credit,
1571
- total_applicable_store_credit: total_applicable_store_credit)
1572
- end
1573
-
1574
- it "returns a money instance" do
1575
- expect(subject.display_store_credit_remaining_after_capture).to be_a(Spree::Money)
1576
- end
1577
-
1578
- it "returns all of the user's available store credit minus what's applied to the order amount" do
1579
- amount_remaining = total_available_store_credit - total_applicable_store_credit
1580
- expect(subject.display_store_credit_remaining_after_capture.money.cents).to eq(amount_remaining * 100.0)
1581
- end
1582
- end
1583
-
1584
- context 'when not capturing at order completion' do
1585
- let!(:store_credit_payment_method) do
1586
- create(
1587
- :store_credit_payment_method,
1588
- auto_capture: false, # not capturing at completion time
1589
- )
1590
- end
1591
-
1592
- describe '#after_cancel' do
1593
- let(:user) { create(:user) }
1594
- let!(:store_credit) do
1595
- create(:store_credit, amount: 100, user: user)
1596
- end
1597
- let(:order) do
1598
- create(
1599
- :order_with_line_items,
1600
- user: user,
1601
- line_items_count: 1,
1602
- # order will be $20 total:
1603
- line_items_price: 10,
1604
- shipment_cost: 10
1605
- )
1606
- end
1607
-
1608
- before do
1609
- order.contents.advance
1610
- order.complete!
1611
- end
1612
-
1613
- it 'releases the pending store credit authorization' do
1614
- expect {
1615
- order.cancel!
1616
- }.to change {
1617
- store_credit.reload.amount_authorized
1618
- }.from(20).to(0)
1619
-
1620
- expect(store_credit.amount_remaining).to eq 100
1621
- end
1622
- end
1623
- end
1624
- end
1625
-
1626
- context 'update_params_payment_source' do
1627
- subject { described_class.new }
1628
-
1629
- it 'is deprecated' do
1630
- subject.instance_variable_set('@updating_params', {})
1631
- expect(Spree::Deprecation).to receive(:warn)
1632
- subject.send(:update_params_payment_source)
1633
- end
1634
- end
1635
-
1636
- describe "#validate_payments_attributes" do
1637
- let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1638
- subject do
1639
- order.validate_payments_attributes(attributes)
1640
- end
1641
-
1642
- context "with empty array" do
1643
- let(:attributes) { [] }
1644
- it "doesn't error" do
1645
- subject
1646
- end
1647
- end
1648
-
1649
- context "with no payment method specified" do
1650
- let(:attributes) { [ActionController::Parameters.new({})] }
1651
- it "doesn't error" do
1652
- subject
1653
- end
1654
- end
1655
-
1656
- context "with valid payment method" do
1657
- let(:payment_method) { create(:check_payment_method) }
1658
- it "doesn't error" do
1659
- subject
1660
- end
1661
- end
1662
-
1663
- context "with inactive payment method" do
1664
- let(:payment_method) { create(:check_payment_method, active: false) }
1665
-
1666
- it "raises RecordNotFound" do
1667
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1668
- end
1669
- end
1670
-
1671
- context "with unavailable payment method" do
1672
- let(:payment_method) { create(:check_payment_method, available_to_users: false) }
1673
-
1674
- it "raises RecordNotFound" do
1675
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1676
- end
1677
- end
1678
-
1679
- context "with soft-deleted payment method" do
1680
- let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1681
-
1682
- it "raises RecordNotFound" do
1683
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1684
- end
1685
- end
1686
- end
1687
- end