solidus_core 2.4.2 → 2.5.0.beta1

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 (313) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -5
  3. data/Rakefile +23 -6
  4. data/app/helpers/spree/base_helper.rb +15 -10
  5. data/app/helpers/spree/checkout_helper.rb +1 -1
  6. data/app/helpers/spree/products_helper.rb +2 -2
  7. data/app/mailers/spree/carton_mailer.rb +2 -2
  8. data/app/mailers/spree/order_mailer.rb +4 -4
  9. data/app/mailers/spree/reimbursement_mailer.rb +2 -2
  10. data/app/mailers/spree/test_mailer.rb +1 -1
  11. data/app/models/concerns/spree/adjustment_source.rb +17 -11
  12. data/app/models/concerns/spree/calculated_adjustments.rb +2 -2
  13. data/app/models/spree/ability.rb +1 -1
  14. data/app/models/spree/address.rb +7 -0
  15. data/app/models/spree/adjustment.rb +6 -2
  16. data/app/models/spree/calculator.rb +1 -1
  17. data/app/models/spree/calculator/flexi_rate.rb +1 -0
  18. data/app/models/spree/calculator/free_shipping.rb +2 -0
  19. data/app/models/spree/calculator/percent_on_line_item.rb +6 -6
  20. data/app/models/spree/calculator/percent_per_item.rb +2 -0
  21. data/app/models/spree/calculator/returns/default_refund_amount.rb +4 -4
  22. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +1 -0
  23. data/app/models/spree/calculator/shipping/flat_rate.rb +1 -0
  24. data/app/models/spree/calculator/shipping/flexi_rate.rb +1 -0
  25. data/app/models/spree/calculator/shipping/per_item.rb +1 -0
  26. data/app/models/spree/calculator/shipping/price_sack.rb +1 -0
  27. data/app/models/spree/classification.rb +1 -1
  28. data/app/models/spree/customer_return.rb +1 -1
  29. data/app/models/spree/inventory_unit.rb +8 -2
  30. data/app/models/spree/log_entry.rb +0 -11
  31. data/app/models/spree/order.rb +31 -16
  32. data/app/models/spree/order_contents.rb +0 -14
  33. data/app/models/spree/order_shipping.rb +0 -5
  34. data/app/models/spree/order_updater.rb +0 -4
  35. data/app/models/spree/payment.rb +6 -1
  36. data/app/models/spree/payment/processing.rb +4 -4
  37. data/app/models/spree/payment_method.rb +8 -3
  38. data/app/models/spree/payment_method/credit_card.rb +1 -1
  39. data/app/models/spree/payment_method/store_credit.rb +4 -4
  40. data/app/models/spree/price.rb +7 -1
  41. data/app/models/spree/product.rb +34 -6
  42. data/app/models/spree/product/scopes.rb +2 -2
  43. data/app/models/spree/promotion.rb +1 -2
  44. data/app/models/spree/promotion/actions/create_adjustment.rb +3 -2
  45. data/app/models/spree/promotion/actions/create_item_adjustments.rb +7 -8
  46. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  47. data/app/models/spree/promotion/rules/taxon.rb +25 -24
  48. data/app/models/spree/promotion_action.rb +7 -1
  49. data/app/models/spree/promotion_chooser.rb +1 -1
  50. data/app/models/spree/promotion_code.rb +3 -3
  51. data/app/models/spree/promotion_handler/coupon.rb +8 -29
  52. data/app/models/spree/promotion_rule.rb +1 -1
  53. data/app/models/spree/refund.rb +3 -3
  54. data/app/models/spree/reimbursement.rb +1 -1
  55. data/app/models/spree/return_authorization.rb +2 -2
  56. data/app/models/spree/return_item.rb +3 -3
  57. data/app/models/spree/return_item/eligibility_validator/base_validator.rb +2 -2
  58. data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +1 -1
  59. data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +1 -1
  60. data/app/models/spree/return_item/eligibility_validator/order_completed.rb +1 -1
  61. data/app/models/spree/return_item/eligibility_validator/rma_required.rb +1 -1
  62. data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
  63. data/app/models/spree/shipment.rb +16 -6
  64. data/app/models/spree/shipping_method.rb +7 -0
  65. data/app/models/spree/shipping_rate.rb +6 -6
  66. data/app/models/spree/shipping_rate_tax.rb +2 -2
  67. data/app/models/spree/stock/availability_validator.rb +2 -2
  68. data/app/models/spree/stock/estimator.rb +9 -1
  69. data/app/models/spree/stock/inventory_unit_builder.rb +1 -2
  70. data/app/models/spree/stock/inventory_validator.rb +2 -2
  71. data/app/models/spree/stock/package.rb +1 -1
  72. data/app/models/spree/stock/simple_coordinator.rb +2 -2
  73. data/app/models/spree/stock_item.rb +6 -0
  74. data/app/models/spree/stock_location.rb +2 -2
  75. data/app/models/spree/store_credit.rb +19 -12
  76. data/app/models/spree/store_credit_category.rb +1 -1
  77. data/app/models/spree/store_credit_event.rb +7 -1
  78. data/app/models/spree/tax/shipping_rate_taxer.rb +1 -1
  79. data/app/models/spree/tax_calculator/shipping_rate.rb +12 -3
  80. data/app/models/spree/tax_rate.rb +10 -3
  81. data/app/models/spree/taxon.rb +14 -4
  82. data/app/models/spree/taxonomy.rb +1 -1
  83. data/app/models/spree/unit_cancel.rb +1 -1
  84. data/app/models/spree/variant.rb +33 -1
  85. data/app/models/spree/variant/price_selector.rb +1 -1
  86. data/app/models/spree/variant/pricing_options.rb +1 -1
  87. data/app/models/spree/variant/scopes.rb +1 -1
  88. data/app/models/spree/variant/vat_price_generator.rb +1 -1
  89. data/app/views/spree/carton_mailer/shipped_email.html.erb +6 -6
  90. data/app/views/spree/carton_mailer/shipped_email.text.erb +6 -6
  91. data/app/views/spree/order_mailer/cancel_email.html.erb +5 -5
  92. data/app/views/spree/order_mailer/cancel_email.text.erb +5 -5
  93. data/app/views/spree/order_mailer/confirm_email.html.erb +9 -9
  94. data/app/views/spree/order_mailer/confirm_email.text.erb +9 -9
  95. data/app/views/spree/order_mailer/inventory_cancellation_email.html.erb +3 -3
  96. data/app/views/spree/order_mailer/inventory_cancellation_email.text.erb +3 -3
  97. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +1 -1
  98. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +1 -1
  99. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +5 -5
  100. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +5 -5
  101. data/app/views/spree/shared/_error_messages.html.erb +2 -2
  102. data/app/views/spree/test_mailer/test_email.html.erb +2 -2
  103. data/app/views/spree/test_mailer/test_email.text.erb +2 -2
  104. data/config/initializers/assets.rb +3 -1
  105. data/config/locales/en.yml +44 -48
  106. data/db/default/spree/store_credit.rb +1 -1
  107. data/db/default/spree/stores.rb +7 -8
  108. data/db/migrate/20160101010000_solidus_one_four.rb +4 -46
  109. data/db/migrate/20170317035819_add_lft_and_rgt_indexes_to_taxons.rb +6 -0
  110. data/db/migrate/20170319191942_remove_order_id_from_inventory_units.rb +28 -0
  111. data/db/migrate/20170608074534_rename_bogus_gateways.rb +4 -2
  112. data/db/migrate/20170831201542_remove_default_tax_from_spree_zones.rb +1 -1
  113. data/lib/generators/spree/custom_user/custom_user_generator.rb +11 -22
  114. data/lib/generators/spree/install/install_generator.rb +10 -5
  115. data/lib/spree/app_configuration.rb +103 -5
  116. data/lib/spree/core.rb +3 -2
  117. data/lib/spree/core/active_merchant_dependencies.rb +11 -0
  118. data/lib/spree/core/controller_helpers/auth.rb +3 -1
  119. data/lib/spree/core/controller_helpers/common.rb +3 -7
  120. data/lib/spree/core/engine.rb +18 -100
  121. data/lib/spree/core/environment.rb +3 -3
  122. data/lib/spree/core/importer/order.rb +0 -1
  123. data/lib/spree/core/permalinks.rb +9 -15
  124. data/lib/spree/core/product_filters.rb +5 -3
  125. data/lib/spree/core/role_configuration.rb +23 -7
  126. data/lib/spree/core/search/base.rb +16 -13
  127. data/lib/spree/core/version.rb +1 -1
  128. data/lib/spree/paranoia_deprecations.rb +19 -0
  129. data/lib/spree/permission_sets.rb +0 -4
  130. data/lib/spree/permitted_attributes.rb +0 -3
  131. data/lib/spree/preferences/preferable.rb +70 -34
  132. data/lib/spree/preferences/preferable_class_methods.rb +22 -0
  133. data/lib/spree/testing_support/authorization_helpers.rb +2 -0
  134. data/lib/spree/testing_support/common_rake.rb +0 -1
  135. data/lib/spree/testing_support/dummy_app.rb +100 -0
  136. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +10 -0
  137. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +10 -0
  138. data/lib/spree/testing_support/dummy_app/assets/stylesheets/spree/backend/all.css +9 -0
  139. data/lib/spree/testing_support/dummy_app/assets/stylesheets/spree/frontend/all.css +9 -0
  140. data/lib/spree/testing_support/dummy_app/database.yml +31 -0
  141. data/lib/spree/testing_support/dummy_app/migrations.rb +35 -0
  142. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +60 -0
  143. data/lib/spree/testing_support/dummy_app/views/layouts/application.html.erb +1 -0
  144. data/lib/spree/testing_support/factories.rb +1 -1
  145. data/lib/spree/testing_support/factories/address_factory.rb +2 -2
  146. data/lib/spree/testing_support/factories/adjustment_factory.rb +2 -2
  147. data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +1 -1
  148. data/lib/spree/testing_support/factories/calculator_factory.rb +1 -1
  149. data/lib/spree/testing_support/factories/carton_factory.rb +1 -1
  150. data/lib/spree/testing_support/factories/country_factory.rb +1 -1
  151. data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
  152. data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
  153. data/lib/spree/testing_support/factories/image_factory.rb +1 -1
  154. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +13 -4
  155. data/lib/spree/testing_support/factories/line_item_factory.rb +1 -1
  156. data/lib/spree/testing_support/factories/option_type_factory.rb +1 -1
  157. data/lib/spree/testing_support/factories/option_value_factory.rb +1 -1
  158. data/lib/spree/testing_support/factories/order_factory.rb +5 -1
  159. data/lib/spree/testing_support/factories/order_promotion_factory.rb +1 -1
  160. data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
  161. data/lib/spree/testing_support/factories/payment_method_factory.rb +1 -1
  162. data/lib/spree/testing_support/factories/price_factory.rb +1 -1
  163. data/lib/spree/testing_support/factories/product_factory.rb +1 -1
  164. data/lib/spree/testing_support/factories/product_option_type_factory.rb +1 -1
  165. data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
  166. data/lib/spree/testing_support/factories/promotion_category_factory.rb +1 -1
  167. data/lib/spree/testing_support/factories/promotion_code_factory.rb +2 -2
  168. data/lib/spree/testing_support/factories/promotion_factory.rb +1 -1
  169. data/lib/spree/testing_support/factories/property_factory.rb +1 -1
  170. data/lib/spree/testing_support/factories/refund_factory.rb +1 -1
  171. data/lib/spree/testing_support/factories/refund_reason_factory.rb +1 -1
  172. data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
  173. data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +1 -1
  174. data/lib/spree/testing_support/factories/return_authorization_factory.rb +1 -1
  175. data/lib/spree/testing_support/factories/return_item_factory.rb +1 -1
  176. data/lib/spree/testing_support/factories/return_reason_factory.rb +1 -1
  177. data/lib/spree/testing_support/factories/role_factory.rb +1 -1
  178. data/lib/spree/testing_support/factories/shipment_factory.rb +1 -2
  179. data/lib/spree/testing_support/factories/shipping_category_factory.rb +1 -1
  180. data/lib/spree/testing_support/factories/shipping_method_factory.rb +2 -2
  181. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +1 -1
  182. data/lib/spree/testing_support/factories/state_factory.rb +1 -7
  183. data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
  184. data/lib/spree/testing_support/factories/stock_location_factory.rb +1 -1
  185. data/lib/spree/testing_support/factories/stock_movement_factory.rb +1 -1
  186. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  187. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +1 -1
  188. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +1 -1
  189. data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -1
  190. data/lib/spree/testing_support/factories/store_credit_type_factory.rb +2 -2
  191. data/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb +1 -1
  192. data/lib/spree/testing_support/factories/store_factory.rb +1 -1
  193. data/lib/spree/testing_support/factories/tax_category_factory.rb +1 -2
  194. data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
  195. data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
  196. data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
  197. data/lib/spree/testing_support/factories/user_factory.rb +4 -10
  198. data/lib/spree/testing_support/factories/variant_factory.rb +1 -1
  199. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +1 -1
  200. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +1 -1
  201. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +1 -1
  202. data/lib/spree/testing_support/factories/zone_factory.rb +2 -4
  203. data/lib/spree/testing_support/flash.rb +2 -2
  204. data/lib/spree/testing_support/order_walkthrough.rb +9 -9
  205. data/lib/spree/testing_support/preferences.rb +4 -0
  206. data/lib/spree/testing_support/sequences.rb +3 -12
  207. data/solidus_core.gemspec +12 -8
  208. data/spec/helpers/base_helper_spec.rb +19 -3
  209. data/spec/helpers/products_helper_spec.rb +1 -1
  210. data/spec/lib/calculated_adjustments_spec.rb +20 -0
  211. data/spec/lib/i18n_spec.rb +4 -69
  212. data/spec/lib/search/base_spec.rb +1 -0
  213. data/spec/lib/search/variant_spec.rb +4 -4
  214. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +6 -6
  215. data/spec/lib/spree/core/importer/order_spec.rb +2 -2
  216. data/spec/lib/spree/core/role_configuration_spec.rb +6 -9
  217. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +12 -8
  218. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +1 -1
  219. data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +1 -1
  220. data/spec/mailers/carton_mailer_spec.rb +3 -7
  221. data/spec/mailers/order_mailer_spec.rb +7 -11
  222. data/spec/mailers/reimbursement_mailer_spec.rb +1 -5
  223. data/spec/mailers/test_mailer_spec.rb +0 -4
  224. data/spec/models/spree/ability_spec.rb +2 -1
  225. data/spec/models/spree/address_spec.rb +32 -19
  226. data/spec/models/spree/app_configuration_spec.rb +1 -1
  227. data/spec/models/spree/calculator/distributed_amount_spec.rb +1 -1
  228. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +8 -10
  229. data/spec/models/spree/calculator/percent_per_item_spec.rb +4 -4
  230. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +10 -3
  231. data/spec/models/spree/classification_spec.rb +19 -0
  232. data/spec/models/spree/credit_card_spec.rb +1 -1
  233. data/spec/models/spree/customer_return_spec.rb +17 -6
  234. data/spec/models/spree/distributed_amounts_handler_spec.rb +1 -1
  235. data/spec/models/spree/exchange_spec.rb +1 -1
  236. data/spec/models/spree/inventory_unit_spec.rb +3 -7
  237. data/spec/models/spree/line_item_spec.rb +6 -6
  238. data/spec/models/spree/option_value_spec.rb +11 -6
  239. data/spec/models/spree/order/callbacks_spec.rb +2 -2
  240. data/spec/models/spree/order/checkout_spec.rb +31 -31
  241. data/spec/models/spree/order/risk_assessment_spec.rb +9 -9
  242. data/spec/models/spree/order_contents_spec.rb +1 -9
  243. data/spec/models/spree/order_inventory_spec.rb +2 -2
  244. data/spec/models/spree/order_mutex_spec.rb +3 -1
  245. data/spec/models/spree/order_shipping_spec.rb +7 -4
  246. data/spec/models/spree/order_spec.rb +36 -13
  247. data/spec/models/spree/order_taxation_spec.rb +7 -7
  248. data/spec/models/spree/order_updater_spec.rb +6 -4
  249. data/spec/models/spree/payment/cancellation_spec.rb +1 -1
  250. data/spec/models/spree/payment_create_spec.rb +2 -2
  251. data/spec/models/spree/payment_method/store_credit_spec.rb +13 -13
  252. data/spec/models/spree/payment_spec.rb +23 -4
  253. data/spec/models/spree/preferences/preferable_spec.rb +44 -0
  254. data/spec/models/spree/preferences/statically_configurable_spec.rb +1 -0
  255. data/spec/models/spree/price_spec.rb +6 -4
  256. data/spec/models/spree/product/scopes_spec.rb +1 -1
  257. data/spec/models/spree/product_spec.rb +49 -9
  258. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +13 -3
  259. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +146 -134
  260. data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +6 -6
  261. data/spec/models/spree/promotion/rules/taxon_spec.rb +14 -14
  262. data/spec/models/spree/promotion_code_spec.rb +31 -19
  263. data/spec/models/spree/promotion_handler/coupon_spec.rb +42 -17
  264. data/spec/models/spree/promotion_handler/shipping_spec.rb +1 -6
  265. data/spec/models/spree/promotion_spec.rb +14 -14
  266. data/spec/models/spree/refund_spec.rb +1 -1
  267. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +1 -1
  268. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +1 -1
  269. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +3 -2
  270. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +1 -1
  271. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +2 -2
  272. data/spec/models/spree/return_item_spec.rb +6 -6
  273. data/spec/models/spree/shipment_spec.rb +14 -10
  274. data/spec/models/spree/shipping_manifest_spec.rb +22 -9
  275. data/spec/models/spree/shipping_method_spec.rb +9 -5
  276. data/spec/models/spree/stock/availability_spec.rb +16 -2
  277. data/spec/models/spree/stock/estimator_spec.rb +11 -12
  278. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -4
  279. data/spec/models/spree/stock/package_spec.rb +3 -2
  280. data/spec/models/spree/stock/simple_coordinator_spec.rb +1 -24
  281. data/spec/models/spree/stock_item_spec.rb +6 -6
  282. data/spec/models/spree/stock_location_spec.rb +16 -3
  283. data/spec/models/spree/store_credit_spec.rb +12 -6
  284. data/spec/models/spree/tax/taxation_integration_spec.rb +6 -6
  285. data/spec/models/spree/tax_calculator/default_spec.rb +7 -7
  286. data/spec/models/spree/taxon_spec.rb +42 -19
  287. data/spec/models/spree/variant/vat_price_generator_spec.rb +1 -1
  288. data/spec/models/spree/variant_spec.rb +69 -11
  289. data/spec/rails_helper.rb +7 -13
  290. data/spec/spec_helper.rb +3 -12
  291. data/spec/support/concerns/default_price.rb +1 -1
  292. data/spec/support/dummy_ability.rb +2 -0
  293. metadata +144 -73
  294. data/Gemfile +0 -3
  295. data/app/models/spree/order_stock_location.rb +0 -15
  296. data/app/models/spree/stock_transfer.rb +0 -110
  297. data/app/models/spree/transfer_item.rb +0 -54
  298. data/lib/generators/spree/custom_user/templates/initializer.rb.tt +0 -1
  299. data/lib/spree/permission_sets/restricted_stock_transfer_display.rb +0 -17
  300. data/lib/spree/permission_sets/restricted_stock_transfer_management.rb +0 -52
  301. data/lib/spree/permission_sets/stock_transfer_display.rb +0 -10
  302. data/lib/spree/permission_sets/stock_transfer_management.rb +0 -11
  303. data/lib/spree/testing_support/factories/stock_transfer_factory.rb +0 -28
  304. data/lib/spree/testing_support/i18n.rb +0 -97
  305. data/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb +0 -12
  306. data/spec/models/spree/order_stock_location_spec.rb +0 -18
  307. data/spec/models/spree/permission_sets/restricted_stock_transfer_display_spec.rb +0 -49
  308. data/spec/models/spree/permission_sets/restricted_stock_transfer_management_spec.rb +0 -218
  309. data/spec/models/spree/permission_sets/stock_transfer_display_spec.rb +0 -23
  310. data/spec/models/spree/permission_sets/stock_transfer_management_spec.rb +0 -23
  311. data/spec/models/spree/stock_transfer_spec.rb +0 -308
  312. data/spec/models/spree/transfer_item_spec.rb +0 -275
  313. data/spec/support/test_gateway.rb +0 -2
@@ -1,49 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe Spree::PermissionSets::RestrictedStockTransferDisplay do
4
- let(:ability) { Spree::Ability.new(user) }
5
- let(:user) { create :user }
6
-
7
- subject { ability }
8
-
9
- let!(:sl1) { create :stock_location, active: false }
10
- let!(:sl2) { create :stock_location, active: false }
11
-
12
- let!(:source_transfer) { create :stock_transfer, source_location: sl1 }
13
- let!(:other_source_transfer) { create :stock_transfer, source_location: sl2 }
14
- let!(:dest_transfer) { create :stock_transfer, source_location: sl2, destination_location: sl1 }
15
-
16
- before do
17
- user.stock_locations << sl1
18
- end
19
-
20
- context "when activated" do
21
- before do
22
- described_class.new(ability).activate!
23
- end
24
-
25
- it { is_expected.to be_able_to(:display, sl1) }
26
- it { is_expected.to_not be_able_to(:display, sl2) }
27
-
28
- it { is_expected.to be_able_to(:display, source_transfer) }
29
- it { is_expected.to_not be_able_to(:display, other_source_transfer) }
30
- it { is_expected.to be_able_to(:display, dest_transfer) }
31
-
32
- it { is_expected.to be_able_to(:admin, source_transfer) }
33
- it { is_expected.to_not be_able_to(:admin, other_source_transfer) }
34
- it { is_expected.to be_able_to(:admin, dest_transfer) }
35
- end
36
-
37
- context "when not activated" do
38
- it { is_expected.to_not be_able_to(:display, sl1) }
39
- it { is_expected.to_not be_able_to(:display, sl2) }
40
-
41
- it { is_expected.to_not be_able_to(:display, source_transfer) }
42
- it { is_expected.to_not be_able_to(:display, other_source_transfer) }
43
- it { is_expected.to_not be_able_to(:display, dest_transfer) }
44
-
45
- it { is_expected.to_not be_able_to(:admin, source_transfer) }
46
- it { is_expected.to_not be_able_to(:admin, other_source_transfer) }
47
- it { is_expected.to_not be_able_to(:admin, dest_transfer) }
48
- end
49
- end
@@ -1,218 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe Spree::PermissionSets::RestrictedStockTransferManagement do
4
- let(:ability) { Spree::Ability.new(user) }
5
-
6
- subject { ability }
7
-
8
- # Inactive stock locations will default to not being visible
9
- # for users without explicit permissions.
10
- let!(:source_location) { create :stock_location, active: false }
11
- let!(:destination_location) { create :stock_location, active: false }
12
-
13
- # This has the side effect of creating a stock item for each stock location above,
14
- # which is what we actually want.
15
- let!(:variant) { create :variant }
16
-
17
- let(:transfer_with_source) { create :stock_transfer, source_location: source_location }
18
- let(:transfer_with_destination) { create :stock_transfer, source_location: destination_location }
19
- let(:transfer_with_source_and_destination) do
20
- create :stock_transfer, source_location: source_location, destination_location: destination_location
21
- end
22
-
23
- let(:transfer_amount) { 1 }
24
- let(:source_transfer_item) do
25
- transfer_with_source.transfer_items.create(variant: variant, expected_quantity: transfer_amount)
26
- end
27
- let(:destination_transfer_item) do
28
- transfer_with_destination.transfer_items.create(variant: variant, expected_quantity: transfer_amount)
29
- end
30
- let(:source_and_destination_transfer_item) do
31
- transfer_with_source_and_destination.transfer_items.create(variant: variant, expected_quantity: transfer_amount)
32
- end
33
-
34
- context "when activated" do
35
- let(:user) { create :user, stock_locations: stock_locations }
36
- let(:stock_locations) { [] }
37
-
38
- before do
39
- user.stock_locations = stock_locations
40
- # When creating transfer_items for a stock transfer, stock items must have a count on hand
41
- # with an amount that would allow a transfer item to pass validations (meaning the count on hand has to be equal
42
- # to the expected_quantity for the transfer)
43
- variant.stock_items.update_all count_on_hand: transfer_amount
44
-
45
- described_class.new(ability).activate!
46
- end
47
-
48
- context "when the user is only associated with the source location" do
49
- let(:stock_locations) { [source_location] }
50
-
51
- it { is_expected.to be_able_to(:display, source_location) }
52
- it { is_expected.to_not be_able_to(:display, destination_location) }
53
-
54
- it { is_expected.to be_able_to(:display, Spree::StockTransfer) }
55
- it { is_expected.to be_able_to(:admin, Spree::StockTransfer) }
56
- it { is_expected.to be_able_to(:create, Spree::StockTransfer) }
57
-
58
- it { is_expected.to be_able_to(:transfer_from, source_location) }
59
- it { is_expected.to be_able_to(:transfer_to, source_location) }
60
-
61
- it { is_expected.to_not be_able_to(:transfer_from, destination_location) }
62
- it { is_expected.to_not be_able_to(:transfer_to, destination_location) }
63
-
64
- it { is_expected.to be_able_to(:display, transfer_with_source) }
65
- it { is_expected.to be_able_to(:display, transfer_with_source_and_destination) }
66
- it { is_expected.to_not be_able_to(:display, transfer_with_destination) }
67
-
68
- it { is_expected.to be_able_to(:manage, transfer_with_source) }
69
- it { is_expected.to be_able_to(:manage, transfer_with_source_and_destination) }
70
- it { is_expected.to_not be_able_to(:manage, transfer_with_destination) }
71
-
72
- it { is_expected.to be_able_to(:manage, source_transfer_item) }
73
- it { is_expected.to be_able_to(:manage, source_and_destination_transfer_item) }
74
- it { is_expected.to_not be_able_to(:manage, destination_transfer_item) }
75
-
76
- context "stock transfer has been shipped" do
77
- before do
78
- transfer_with_source_and_destination.update_attributes!(shipped_at: Time.current)
79
- described_class.new(ability).activate!
80
- end
81
-
82
- it { is_expected.to_not be_able_to(:manage, transfer_with_source_and_destination) }
83
- it { is_expected.to_not be_able_to(:manage, source_and_destination_transfer_item) }
84
- end
85
- end
86
-
87
- context "when the user is only associated with the destination location" do
88
- let(:stock_locations) { [destination_location] }
89
-
90
- it { is_expected.to be_able_to(:display, destination_location) }
91
- it { is_expected.to_not be_able_to(:display, source_location) }
92
-
93
- it { is_expected.to be_able_to(:display, Spree::StockTransfer) }
94
- it { is_expected.to be_able_to(:admin, Spree::StockTransfer) }
95
- it { is_expected.to be_able_to(:create, Spree::StockTransfer) }
96
-
97
- it { is_expected.to_not be_able_to(:transfer_from, source_location) }
98
- it { is_expected.to_not be_able_to(:transfer_to, source_location) }
99
-
100
- it { is_expected.to be_able_to(:transfer_from, destination_location) }
101
- it { is_expected.to be_able_to(:transfer_to, destination_location) }
102
-
103
- it { is_expected.to be_able_to(:display, transfer_with_destination) }
104
- it { is_expected.to_not be_able_to(:display, transfer_with_source) }
105
- it { is_expected.to_not be_able_to(:display, transfer_with_source_and_destination) }
106
-
107
- it { is_expected.to be_able_to(:manage, transfer_with_destination) }
108
- it { is_expected.to_not be_able_to(:manage, transfer_with_source) }
109
- it { is_expected.to_not be_able_to(:manage, transfer_with_source_and_destination) }
110
-
111
- it { is_expected.to be_able_to(:manage, destination_transfer_item) }
112
- it { is_expected.to_not be_able_to(:manage, source_transfer_item) }
113
- it { is_expected.to_not be_able_to(:manage, source_and_destination_transfer_item) }
114
-
115
- context "stock transfer has been shipped" do
116
- before do
117
- transfer_with_source_and_destination.update_attributes!(shipped_at: Time.current)
118
- described_class.new(ability).activate!
119
- end
120
-
121
- it { is_expected.to be_able_to(:manage, transfer_with_source_and_destination) }
122
- it { is_expected.to be_able_to(:manage, source_and_destination_transfer_item) }
123
- end
124
- end
125
-
126
- context "when the user is associated with both locations" do
127
- let(:stock_locations) { [source_location, destination_location] }
128
-
129
- it { is_expected.to be_able_to(:display, source_location) }
130
- it { is_expected.to be_able_to(:display, destination_location) }
131
-
132
- it { is_expected.to be_able_to(:display, Spree::StockTransfer) }
133
- it { is_expected.to be_able_to(:admin, Spree::StockTransfer) }
134
- it { is_expected.to be_able_to(:create, Spree::StockTransfer) }
135
-
136
- it { is_expected.to be_able_to(:transfer_from, source_location) }
137
- it { is_expected.to be_able_to(:transfer_to, source_location) }
138
-
139
- it { is_expected.to be_able_to(:transfer_from, destination_location) }
140
- it { is_expected.to be_able_to(:transfer_to, destination_location) }
141
-
142
- it { is_expected.to be_able_to(:display, transfer_with_source) }
143
- it { is_expected.to be_able_to(:display, transfer_with_source_and_destination) }
144
- it { is_expected.to be_able_to(:display, transfer_with_destination) }
145
-
146
- it { is_expected.to be_able_to(:manage, transfer_with_source) }
147
- it { is_expected.to be_able_to(:manage, transfer_with_destination) }
148
- it { is_expected.to be_able_to(:manage, transfer_with_source_and_destination) }
149
-
150
- it { is_expected.to be_able_to(:manage, source_transfer_item) }
151
- it { is_expected.to be_able_to(:manage, destination_transfer_item) }
152
- it { is_expected.to be_able_to(:manage, source_and_destination_transfer_item) }
153
-
154
- context "stock transfer has been shipped" do
155
- before do
156
- transfer_with_source_and_destination.update_attributes!(shipped_at: Time.current)
157
- described_class.new(ability).activate!
158
- end
159
-
160
- it { is_expected.to be_able_to(:manage, transfer_with_source_and_destination) }
161
- it { is_expected.to be_able_to(:manage, source_and_destination_transfer_item) }
162
- end
163
- end
164
-
165
- context "when the user is associated with neither location" do
166
- let(:stock_locations) { [] }
167
-
168
- it { is_expected.to_not be_able_to(:display, source_location) }
169
- it { is_expected.to_not be_able_to(:display, destination_location) }
170
-
171
- it { is_expected.to_not be_able_to(:display, Spree::StockTransfer) }
172
- it { is_expected.to_not be_able_to(:admin, Spree::StockTransfer) }
173
- it { is_expected.to_not be_able_to(:create, Spree::StockTransfer) }
174
-
175
- it { is_expected.to_not be_able_to(:transfer_from, source_location) }
176
- it { is_expected.to_not be_able_to(:transfer_to, source_location) }
177
-
178
- it { is_expected.to_not be_able_to(:transfer_from, destination_location) }
179
- it { is_expected.to_not be_able_to(:transfer_to, destination_location) }
180
-
181
- it { is_expected.to_not be_able_to(:manage, transfer_with_source) }
182
- it { is_expected.to_not be_able_to(:manage, transfer_with_destination) }
183
- it { is_expected.to_not be_able_to(:manage, transfer_with_source_and_destination) }
184
-
185
- it { is_expected.to_not be_able_to(:manage, source_transfer_item) }
186
- it { is_expected.to_not be_able_to(:manage, destination_transfer_item) }
187
- it { is_expected.to_not be_able_to(:manage, source_and_destination_transfer_item) }
188
- end
189
- end
190
-
191
- context "when not activated" do
192
- let(:user) { create :user }
193
-
194
- it { is_expected.to_not be_able_to(:display, Spree::StockTransfer) }
195
- it { is_expected.to_not be_able_to(:admin, Spree::StockTransfer) }
196
- it { is_expected.to_not be_able_to(:create, Spree::StockTransfer) }
197
-
198
- it { is_expected.to_not be_able_to(:display, source_location) }
199
- it { is_expected.to_not be_able_to(:display, destination_location) }
200
-
201
- it { is_expected.to_not be_able_to(:transfer_from, source_location) }
202
- it { is_expected.to_not be_able_to(:transfer_to, source_location) }
203
-
204
- it { is_expected.to_not be_able_to(:transfer_from, destination_location) }
205
- it { is_expected.to_not be_able_to(:transfer_to, destination_location) }
206
-
207
- it { is_expected.to_not be_able_to(:display, source_location) }
208
- it { is_expected.to_not be_able_to(:display, destination_location) }
209
-
210
- it { is_expected.to_not be_able_to(:manage, transfer_with_source) }
211
- it { is_expected.to_not be_able_to(:manage, transfer_with_destination) }
212
- it { is_expected.to_not be_able_to(:manage, transfer_with_source_and_destination) }
213
-
214
- it { is_expected.to_not be_able_to(:manage, source_transfer_item) }
215
- it { is_expected.to_not be_able_to(:manage, destination_transfer_item) }
216
- it { is_expected.to_not be_able_to(:manage, source_and_destination_transfer_item) }
217
- end
218
- end
@@ -1,23 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe Spree::PermissionSets::StockTransferDisplay do
4
- let(:ability) { DummyAbility.new }
5
-
6
- subject { ability }
7
-
8
- context "when activated" do
9
- before do
10
- described_class.new(ability).activate!
11
- end
12
-
13
- it { is_expected.to be_able_to(:display, Spree::StockTransfer) }
14
- it { is_expected.to be_able_to(:admin, Spree::StockTransfer) }
15
- it { is_expected.to be_able_to(:display, Spree::StockLocation) }
16
- end
17
-
18
- context "when not activated" do
19
- it { is_expected.not_to be_able_to(:display, Spree::StockTransfer) }
20
- it { is_expected.not_to be_able_to(:admin, Spree::StockTransfer) }
21
- it { is_expected.not_to be_able_to(:display, Spree::StockLocation) }
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe Spree::PermissionSets::StockTransferManagement do
4
- let(:ability) { DummyAbility.new }
5
-
6
- subject { ability }
7
-
8
- context "when activated" do
9
- before do
10
- described_class.new(ability).activate!
11
- end
12
-
13
- it { is_expected.to be_able_to(:manage, Spree::StockTransfer) }
14
- it { is_expected.to be_able_to(:manage, Spree::TransferItem) }
15
- it { is_expected.to be_able_to(:display, Spree::StockLocation) }
16
- end
17
-
18
- context "when not activated" do
19
- it { is_expected.to_not be_able_to(:manage, Spree::StockTransfer) }
20
- it { is_expected.to_not be_able_to(:manage, Spree::TransferItem) }
21
- it { is_expected.not_to be_able_to(:display, Spree::StockLocation) }
22
- end
23
- end
@@ -1,308 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module Spree
4
- RSpec.describe StockTransfer, type: :model do
5
- let(:destination_location) { create(:stock_location_with_items) }
6
- let(:source_location) { create(:stock_location_with_items) }
7
- let(:stock_item) { source_location.stock_items.order(:id).first }
8
- let(:variant) { stock_item.variant }
9
- let(:stock_transfer) do
10
- StockTransfer.create(description: 'PO123', source_location: source_location, destination_location: destination_location)
11
- end
12
-
13
- subject { stock_transfer }
14
-
15
- describe '#description' do
16
- subject { super().description }
17
- it { is_expected.to eq 'PO123' }
18
- end
19
-
20
- describe '#to_param' do
21
- subject { super().to_param }
22
- it { is_expected.to match /T\d+/ }
23
- end
24
-
25
- describe "transfer item building" do
26
- let(:stock_transfer) do
27
- variant = source_location.stock_items.first.variant
28
- stock_transfer = Spree::StockTransfer.new(
29
- number: "T123",
30
- source_location: source_location,
31
- destination_location: destination_location
32
- )
33
- stock_transfer.transfer_items.build(variant: variant, expected_quantity: 5)
34
- stock_transfer
35
- end
36
-
37
- subject { stock_transfer.save }
38
-
39
- it { is_expected.to eq true }
40
-
41
- it "creates the associated transfer item" do
42
- expect { subject }.to change { Spree::TransferItem.count }.by(1)
43
- end
44
- end
45
-
46
- describe "#receivable?" do
47
- subject { stock_transfer.receivable? }
48
-
49
- context "finalized" do
50
- before do
51
- stock_transfer.update_attributes(finalized_at: Time.current)
52
- end
53
-
54
- it { is_expected.to eq false }
55
- end
56
-
57
- context "shipped" do
58
- before do
59
- stock_transfer.update_attributes(shipped_at: Time.current)
60
- end
61
-
62
- it { is_expected.to eq false }
63
- end
64
-
65
- context "closed" do
66
- before do
67
- stock_transfer.update_attributes(closed_at: Time.current)
68
- end
69
-
70
- it { is_expected.to eq false }
71
- end
72
-
73
- context "finalized and closed" do
74
- before do
75
- stock_transfer.update_attributes(finalized_at: Time.current, closed_at: Time.current)
76
- end
77
-
78
- it { is_expected.to eq false }
79
- end
80
-
81
- context "shipped and closed" do
82
- before do
83
- stock_transfer.update_attributes(shipped_at: Time.current, closed_at: Time.current)
84
- end
85
-
86
- it { is_expected.to eq false }
87
- end
88
-
89
- context "finalized and shipped" do
90
- before do
91
- stock_transfer.update_attributes(finalized_at: Time.current, shipped_at: Time.current)
92
- end
93
-
94
- it { is_expected.to eq true }
95
- end
96
- end
97
-
98
- describe "#finalizable?" do
99
- subject { stock_transfer.finalizable? }
100
-
101
- context "finalized" do
102
- before do
103
- stock_transfer.update_attributes(finalized_at: Time.current)
104
- end
105
-
106
- it { is_expected.to eq false }
107
- end
108
-
109
- context "shipped" do
110
- before do
111
- stock_transfer.update_attributes(shipped_at: Time.current)
112
- end
113
-
114
- it { is_expected.to eq false }
115
- end
116
-
117
- context "closed" do
118
- before do
119
- stock_transfer.update_attributes(closed_at: Time.current)
120
- end
121
-
122
- it { is_expected.to eq false }
123
- end
124
-
125
- context "finalized and closed" do
126
- before do
127
- stock_transfer.update_attributes(finalized_at: Time.current, closed_at: Time.current)
128
- end
129
-
130
- it { is_expected.to eq false }
131
- end
132
-
133
- context "shipped and closed" do
134
- before do
135
- stock_transfer.update_attributes(shipped_at: Time.current, closed_at: Time.current)
136
- end
137
-
138
- it { is_expected.to eq false }
139
- end
140
-
141
- context "no action taken on stock transfer" do
142
- before do
143
- stock_transfer.update_attributes(finalized_at: nil, shipped_at: nil, closed_at: nil)
144
- end
145
-
146
- it { is_expected.to eq true }
147
- end
148
- end
149
-
150
- describe "#finalize" do
151
- let(:user) { create(:user) }
152
-
153
- subject { stock_transfer.finalize(user) }
154
-
155
- context "can be finalized" do
156
- it "sets a finalized_at date" do
157
- expect { subject }.to change { stock_transfer.finalized_at }
158
- end
159
-
160
- it "sets the finalized_by to the supplied user" do
161
- subject
162
- expect(stock_transfer.finalized_by).to eq user
163
- end
164
- end
165
-
166
- context "can't be finalized" do
167
- before do
168
- stock_transfer.update_attributes(finalized_at: Time.current)
169
- end
170
-
171
- it "doesn't set a finalized_at date" do
172
- expect { subject }.to_not change { stock_transfer.finalized_at }
173
- end
174
-
175
- it "doesn't set a finalized_by user" do
176
- expect { subject }.to_not change { stock_transfer.finalized_by }
177
- end
178
-
179
- it "adds an error message" do
180
- subject
181
- expect(stock_transfer.errors.full_messages).to include Spree.t(:stock_transfer_cannot_be_finalized)
182
- end
183
- end
184
- end
185
-
186
- describe "#close" do
187
- let(:user) { create(:user) }
188
- let(:stock_transfer) { create(:receivable_stock_transfer_with_items) }
189
-
190
- subject { stock_transfer.close(user) }
191
-
192
- context "can be closed" do
193
- it "sets a closed_at date" do
194
- expect { subject }.to change { stock_transfer.closed_at }
195
- end
196
-
197
- it "sets the closed_by to the supplied user" do
198
- subject
199
- expect(stock_transfer.closed_by).to eq user
200
- end
201
- end
202
-
203
- context "can't be closed" do
204
- before do
205
- stock_transfer.update_attributes(finalized_at: nil)
206
- end
207
-
208
- it "doesn't set a closed_at date" do
209
- expect { subject }.to_not change { stock_transfer.closed_at }
210
- end
211
-
212
- it "doesn't set a closed_by user" do
213
- expect { subject }.to_not change { stock_transfer.closed_by }
214
- end
215
-
216
- it "adds an error message" do
217
- subject
218
- expect(stock_transfer.errors.full_messages).to include Spree.t(:stock_transfer_must_be_receivable)
219
- end
220
- end
221
- end
222
-
223
- describe "destroying" do
224
- subject { stock_transfer.destroy }
225
-
226
- context "stock transfer is finalized" do
227
- before do
228
- stock_transfer.update_attributes!(finalized_at: Time.current)
229
- end
230
-
231
- it "doesn't destroy the stock transfer" do
232
- expect { subject }.to_not change { Spree::StockTransfer.count }
233
- end
234
-
235
- it "adds an error message to the model" do
236
- subject
237
- expect(stock_transfer.errors.full_messages).to include Spree.t('errors.messages.cannot_delete_finalized_stock_transfer')
238
- end
239
- end
240
-
241
- context "stock transfer is not finalized" do
242
- before do
243
- stock_transfer.update_attributes!(finalized_at: nil)
244
- end
245
-
246
- it "destroys the stock transfer" do
247
- expect { subject }.to change { Spree::StockTransfer.count }.by(-1)
248
- end
249
- end
250
- end
251
-
252
- describe '#ship' do
253
- let(:stock_transfer) { create(:stock_transfer, tracking_number: "ABC123") }
254
-
255
- context "tracking number is provided" do
256
- subject { stock_transfer.ship(tracking_number: "XYZ123") }
257
-
258
- it "updates the tracking number" do
259
- expect { subject }.to change { stock_transfer.tracking_number }.from("ABC123").to("XYZ123")
260
- end
261
- end
262
-
263
- context "tracking number is not provided" do
264
- subject { stock_transfer.ship }
265
-
266
- it "preserves the existing tracking number" do
267
- expect { subject }.to_not change { stock_transfer.tracking_number }.from("ABC123")
268
- end
269
- end
270
- end
271
-
272
- describe '#transfer' do
273
- let(:stock_transfer) { create(:stock_transfer_with_items) }
274
-
275
- before do
276
- stock_transfer.transfer_items.each { |item| item.update_attributes(expected_quantity: 1) }
277
- end
278
-
279
- subject { stock_transfer.transfer }
280
-
281
- context 'with enough stock' do
282
- it 'creates stock movements for transfer items' do
283
- expect{ subject }.to change{ Spree::StockMovement.count }.by(stock_transfer.transfer_items.count)
284
- end
285
- end
286
-
287
- context 'without enough stock' do
288
- before do
289
- stockless_variant = stock_transfer.transfer_items.last.variant
290
- stock_transfer.source_location.stock_item(stockless_variant).set_count_on_hand(0)
291
- end
292
-
293
- it 'rollsback the transaction' do
294
- expect{ subject }.to_not change{ Spree::StockMovement.count }
295
- end
296
-
297
- it 'adds errors' do
298
- subject
299
- expect(stock_transfer.errors.full_messages.join(', ')).to match /not enough inventory/
300
- end
301
-
302
- it 'returns false' do
303
- expect(subject).to eq false
304
- end
305
- end
306
- end
307
- end
308
- end