solidus_core 4.3.5 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +2 -2
  3. data/app/mailers/spree/base_mailer.rb +1 -1
  4. data/app/mailers/spree/carton_mailer.rb +1 -1
  5. data/app/mailers/spree/order_mailer.rb +3 -3
  6. data/app/mailers/spree/reimbursement_mailer.rb +1 -1
  7. data/app/models/concerns/spree/active_storage_adapter/normalization.rb +1 -1
  8. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  9. data/app/models/concerns/spree/display_money.rb +1 -1
  10. data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
  11. data/app/models/concerns/spree/user_address_book.rb +4 -4
  12. data/app/models/concerns/spree/user_methods.rb +3 -3
  13. data/app/models/spree/address.rb +6 -6
  14. data/app/models/spree/adjustment.rb +13 -66
  15. data/app/models/spree/calculator/returns/default_refund_amount.rb +1 -1
  16. data/app/models/spree/carton.rb +2 -2
  17. data/app/models/spree/credit_card.rb +6 -6
  18. data/app/models/spree/deprecated_configurable_class.rb +40 -0
  19. data/app/models/spree/fulfilment_changer.rb +4 -4
  20. data/app/models/spree/inventory_unit.rb +2 -2
  21. data/app/models/spree/line_item.rb +1 -4
  22. data/app/models/spree/null_promotion_adjuster.rb +13 -0
  23. data/app/models/spree/null_promotion_advertiser.rb +9 -0
  24. data/app/models/spree/null_promotion_finder.rb +9 -0
  25. data/app/models/spree/null_promotion_handler.rb +44 -0
  26. data/app/models/spree/order.rb +15 -22
  27. data/app/models/spree/order_cancellations.rb +8 -8
  28. data/app/models/spree/order_mutex.rb +2 -2
  29. data/app/models/spree/order_shipping.rb +9 -9
  30. data/app/models/spree/order_updater.rb +6 -10
  31. data/app/models/spree/payment/processing.rb +2 -2
  32. data/app/models/spree/payment.rb +2 -2
  33. data/app/models/spree/payment_create.rb +1 -1
  34. data/app/models/spree/payment_method/store_credit.rb +1 -1
  35. data/app/models/spree/payment_source.rb +5 -1
  36. data/app/models/spree/permission_set.rb +11 -0
  37. data/app/models/spree/product.rb +7 -28
  38. data/app/models/spree/refund.rb +1 -1
  39. data/app/models/spree/reimbursement.rb +4 -4
  40. data/app/models/spree/reimbursement_performer.rb +3 -3
  41. data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
  42. data/app/models/spree/reimbursement_type/credit.rb +1 -1
  43. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
  44. data/app/models/spree/reimbursement_type/store_credit.rb +1 -1
  45. data/app/models/spree/return_item.rb +9 -9
  46. data/app/models/spree/role.rb +3 -1
  47. data/app/models/spree/role_permission.rb +8 -0
  48. data/app/models/spree/shipment.rb +7 -7
  49. data/app/models/spree/shipping_category.rb +2 -0
  50. data/app/models/spree/shipping_rate.rb +1 -1
  51. data/app/models/spree/{order_contents.rb → simple_order_contents.rb} +4 -11
  52. data/app/models/spree/stock/estimator.rb +1 -1
  53. data/app/models/spree/stock/inventory_unit_builder.rb +1 -1
  54. data/app/models/spree/stock/package.rb +2 -2
  55. data/app/models/spree/stock/simple_coordinator.rb +1 -1
  56. data/app/models/spree/stock_location.rb +5 -5
  57. data/app/models/spree/store.rb +1 -1
  58. data/app/models/spree/store_credit.rb +15 -15
  59. data/app/models/spree/store_credit_event.rb +3 -3
  60. data/app/models/spree/tax_calculator/default.rb +2 -2
  61. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
  62. data/app/models/spree/tax_category.rb +3 -1
  63. data/app/models/spree/tax_rate.rb +3 -3
  64. data/app/models/spree/taxonomy.rb +2 -2
  65. data/app/models/spree/unit_cancel.rb +1 -2
  66. data/app/models/spree/variant/vat_price_generator.rb +1 -1
  67. data/app/models/spree/variant.rb +7 -2
  68. data/app/models/spree/wallet.rb +2 -2
  69. data/app/views/spree/order_mailer/cancel_email.html.erb +1 -1
  70. data/app/views/spree/order_mailer/cancel_email.text.erb +1 -1
  71. data/app/views/spree/order_mailer/confirm_email.html.erb +5 -5
  72. data/app/views/spree/order_mailer/confirm_email.text.erb +5 -5
  73. data/config/locales/en.yml +4 -90
  74. data/db/default/spree/permission_sets.rb +10 -0
  75. data/db/default/spree/return_reasons.rb +3 -1
  76. data/db/default/spree/states.rb +1 -1
  77. data/db/migrate/20160101010000_solidus_one_four.rb +0 -127
  78. data/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb +9 -0
  79. data/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb +9 -0
  80. data/db/migrate/20240821173641_add_description_to_spree_roles.rb +5 -0
  81. data/db/migrate/20240904152041_add_privilege_and_category_to_spree_permission_sets.rb +6 -0
  82. data/db/seeds.rb +1 -0
  83. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
  84. data/lib/generators/solidus/update/update_generator.rb +1 -1
  85. data/lib/generators/spree/dummy/templates/rails/test.rb +6 -1
  86. data/lib/spree/app_configuration.rb +53 -84
  87. data/lib/spree/core/class_constantizer.rb +2 -2
  88. data/lib/spree/core/controller_helpers/payment_parameters.rb +1 -1
  89. data/lib/spree/core/engine.rb +1 -0
  90. data/lib/spree/core/environment/calculators.rb +35 -3
  91. data/lib/spree/core/environment/promotions.rb +25 -4
  92. data/lib/spree/core/environment_extension.rb +16 -2
  93. data/lib/spree/core/importer/order.rb +5 -5
  94. data/lib/spree/core/importer/product.rb +3 -3
  95. data/lib/spree/core/nested_class_set.rb +28 -0
  96. data/lib/spree/core/null_promotion_configuration.rb +84 -0
  97. data/lib/spree/core/product_filters.rb +1 -1
  98. data/lib/spree/core/search/variant.rb +2 -2
  99. data/lib/spree/core/state_machines/order.rb +0 -1
  100. data/lib/spree/core/validators/email.rb +1 -1
  101. data/lib/spree/core/version.rb +2 -2
  102. data/lib/spree/core.rb +2 -6
  103. data/lib/spree/deprecator.rb +9 -0
  104. data/lib/spree/i18n.rb +1 -1
  105. data/lib/spree/mailer_previews/carton_preview.rb +1 -1
  106. data/lib/spree/permission_sets/base.rb +13 -1
  107. data/lib/spree/permission_sets/configuration_display.rb +10 -0
  108. data/lib/spree/permission_sets/configuration_management.rb +10 -0
  109. data/lib/spree/permission_sets/dashboard_display.rb +12 -0
  110. data/lib/spree/permission_sets/default_customer.rb +11 -1
  111. data/lib/spree/permission_sets/order_display.rb +10 -0
  112. data/lib/spree/permission_sets/order_management.rb +10 -0
  113. data/lib/spree/permission_sets/product_display.rb +10 -0
  114. data/lib/spree/permission_sets/product_management.rb +10 -0
  115. data/lib/spree/permission_sets/restricted_stock_display.rb +10 -0
  116. data/lib/spree/permission_sets/restricted_stock_management.rb +10 -0
  117. data/lib/spree/permission_sets/stock_display.rb +10 -0
  118. data/lib/spree/permission_sets/stock_management.rb +10 -0
  119. data/lib/spree/permission_sets/super_user.rb +10 -0
  120. data/lib/spree/permission_sets/user_display.rb +10 -0
  121. data/lib/spree/permission_sets/user_management.rb +10 -0
  122. data/lib/spree/permission_sets.rb +0 -2
  123. data/lib/spree/permitted_attributes.rb +2 -2
  124. data/lib/spree/preferences/store.rb +2 -2
  125. data/lib/spree/testing_support/capybara_ext.rb +1 -1
  126. data/lib/spree/testing_support/dummy_ability.rb +7 -0
  127. data/lib/spree/testing_support/dummy_app/database.yml +2 -2
  128. data/lib/spree/testing_support/dummy_app/migrations.rb +8 -15
  129. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +2 -2
  130. data/lib/spree/testing_support/dummy_app.rb +17 -12
  131. data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -2
  132. data/lib/spree/testing_support/factories/calculator_factory.rb +1 -5
  133. data/lib/spree/testing_support/factories/carton_factory.rb +2 -2
  134. data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
  135. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +3 -3
  136. data/lib/spree/testing_support/factories/order_factory.rb +5 -24
  137. data/lib/spree/testing_support/factories/product_factory.rb +1 -1
  138. data/lib/spree/testing_support/factories/shipment_factory.rb +1 -1
  139. data/lib/spree/testing_support/factories/stock_item_factory.rb +5 -1
  140. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  141. data/lib/spree/testing_support/factories/user_factory.rb +1 -1
  142. data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
  143. data/lib/spree/testing_support/order_walkthrough.rb +3 -3
  144. data/lib/spree/testing_support/shared_examples/calculator.rb +10 -0
  145. data/lib/spree/testing_support/shared_examples/order_factory.rb +141 -0
  146. data/lib/spree/testing_support/shared_examples/working_factory.rb +15 -0
  147. data/lib/tasks/colorado_delivery_fee.rake +2 -2
  148. data/solidus_core.gemspec +7 -7
  149. metadata +60 -93
  150. data/app/jobs/spree/promotion_code_batch_job.rb +0 -26
  151. data/app/mailers/spree/promotion_code_batch_mailer.rb +0 -15
  152. data/app/models/spree/calculator/distributed_amount.rb +0 -33
  153. data/app/models/spree/calculator/flat_percent_item_total.rb +0 -23
  154. data/app/models/spree/calculator/flexi_rate.rb +0 -22
  155. data/app/models/spree/calculator/percent_on_line_item.rb +0 -13
  156. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -52
  157. data/app/models/spree/calculator/tiered_percent.rb +0 -62
  158. data/app/models/spree/line_item_action.rb +0 -8
  159. data/app/models/spree/order_promotion.rb +0 -27
  160. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -81
  161. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -98
  162. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -139
  163. data/app/models/spree/promotion/actions/free_shipping.rb +0 -59
  164. data/app/models/spree/promotion/order_adjustments_recalculator.rb +0 -92
  165. data/app/models/spree/promotion/rules/first_order.rb +0 -38
  166. data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +0 -36
  167. data/app/models/spree/promotion/rules/item_total.rb +0 -86
  168. data/app/models/spree/promotion/rules/minimum_quantity.rb +0 -59
  169. data/app/models/spree/promotion/rules/nth_order.rb +0 -45
  170. data/app/models/spree/promotion/rules/one_use_per_user.rb +0 -25
  171. data/app/models/spree/promotion/rules/option_value.rb +0 -50
  172. data/app/models/spree/promotion/rules/product.rb +0 -86
  173. data/app/models/spree/promotion/rules/store.rb +0 -26
  174. data/app/models/spree/promotion/rules/taxon.rb +0 -91
  175. data/app/models/spree/promotion/rules/user.rb +0 -34
  176. data/app/models/spree/promotion/rules/user_logged_in.rb +0 -20
  177. data/app/models/spree/promotion/rules/user_role.rb +0 -45
  178. data/app/models/spree/promotion.rb +0 -271
  179. data/app/models/spree/promotion_action.rb +0 -47
  180. data/app/models/spree/promotion_category.rb +0 -8
  181. data/app/models/spree/promotion_chooser.rb +0 -34
  182. data/app/models/spree/promotion_code/batch_builder.rb +0 -64
  183. data/app/models/spree/promotion_code.rb +0 -54
  184. data/app/models/spree/promotion_code_batch.rb +0 -27
  185. data/app/models/spree/promotion_handler/cart.rb +0 -75
  186. data/app/models/spree/promotion_handler/coupon.rb +0 -123
  187. data/app/models/spree/promotion_handler/page.rb +0 -26
  188. data/app/models/spree/promotion_handler/shipping.rb +0 -61
  189. data/app/models/spree/promotion_rule.rb +0 -55
  190. data/app/models/spree/promotion_rule_store.rb +0 -10
  191. data/app/models/spree/promotion_rule_taxon.rb +0 -8
  192. data/app/models/spree/promotion_rule_user.rb +0 -10
  193. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +0 -2
  194. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +0 -2
  195. data/bin/rails +0 -13
  196. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +0 -38
  197. data/db/migrate/20180202190713_create_promotion_rule_stores.rb +0 -12
  198. data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +0 -11
  199. data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +0 -42
  200. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +0 -20
  201. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +0 -5
  202. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +0 -6
  203. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +0 -13
  204. data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +0 -10
  205. data/db/migrate/20231031175215_add_promotion_order_promotion_foreign_key.rb +0 -10
  206. data/lib/solidus/migrations/promotions_with_code_handlers.rb +0 -66
  207. data/lib/spree/permission_sets/promotion_display.rb +0 -25
  208. data/lib/spree/permission_sets/promotion_management.rb +0 -25
  209. data/lib/spree/ransack_4_1_patch.rb +0 -16
  210. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  211. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -7
  212. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  213. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -98
@@ -18,11 +18,23 @@ module Spree
18
18
  end
19
19
 
20
20
  # Activate permissions on the ability. Put your can and cannot statements here.
21
- # Must be overriden by subclasses
21
+ # Must be overridden by subclasses
22
22
  def activate!
23
23
  raise NotImplementedError.new
24
24
  end
25
25
 
26
+ # Provide the permission set privilege in the form of a :symbol.
27
+ # Must be overridden by subclasses.
28
+ def self.privilege
29
+ raise NotImplementedError, "Subclass #{name} must define a privilege using `self.privilege :symbol`"
30
+ end
31
+
32
+ # Provide the permission set category in the form of a :symbol.
33
+ # Must be overridden by subclasses.
34
+ def self.category
35
+ raise NotImplementedError, "Subclass #{name} must define a category using `self.category :symbol`"
36
+ end
37
+
26
38
  private
27
39
 
28
40
  attr_reader :ability
@@ -22,6 +22,16 @@ module Spree
22
22
  # - Reimbursement types
23
23
  # - Return reasons
24
24
  class ConfigurationDisplay < PermissionSets::Base
25
+ class << self
26
+ def privilege
27
+ :display
28
+ end
29
+
30
+ def category
31
+ :configuration
32
+ end
33
+ end
34
+
25
35
  def activate!
26
36
  can [:read, :admin], Spree::TaxCategory
27
37
  can [:read, :admin], Spree::TaxRate
@@ -21,6 +21,16 @@ module Spree
21
21
  # - Reimbursement types
22
22
  # - Return reasons
23
23
  class ConfigurationManagement < PermissionSets::Base
24
+ class << self
25
+ def privilege
26
+ :management
27
+ end
28
+
29
+ def category
30
+ :configuration
31
+ end
32
+ end
33
+
24
34
  def activate!
25
35
  can :manage, Spree::TaxCategory
26
36
  can :manage, Spree::TaxRate
@@ -8,7 +8,19 @@ module Spree
8
8
  # which may or not contain sensitive information depending on
9
9
  # customizations.
10
10
  class DashboardDisplay < PermissionSets::Base
11
+ class << self
12
+ def privilege
13
+ :other
14
+ end
15
+
16
+ def category
17
+ :dashboard_display
18
+ end
19
+ end
20
+
11
21
  def activate!
22
+ Spree.deprecator.warn "The #{self.class.name} module is deprecated. " \
23
+ "If you still use dashboards, please copy all controllers and views from #{self.class.name} to your application."
12
24
  can [:admin, :home], :dashboards
13
25
  end
14
26
  end
@@ -32,6 +32,16 @@ module Spree
32
32
  # with the same user, as well as reading and updating the user record and
33
33
  # their associated cards.
34
34
  class DefaultCustomer < PermissionSets::Base
35
+ class << self
36
+ def privilege
37
+ :other
38
+ end
39
+
40
+ def category
41
+ :default_customer
42
+ end
43
+ end
44
+
35
45
  def activate!
36
46
  can :read, Country
37
47
  can :read, OptionType
@@ -44,7 +54,7 @@ module Spree
44
54
  # via API, just like with show and update
45
55
  (order.guest_token.present? && token == order.guest_token)
46
56
  end
47
- can [:show, :update], Order, Order.where(user: user) do |order, token|
57
+ can [:show, :update], Order, Order.where(user:) do |order, token|
48
58
  order.user == user || (order.guest_token.present? && token == order.guest_token)
49
59
  end
50
60
  cannot :update, Order do |order|
@@ -22,6 +22,16 @@ module Spree
22
22
  # However, it does not allow any modifications to be made to any of these
23
23
  # resources.
24
24
  class OrderDisplay < PermissionSets::Base
25
+ class << self
26
+ def privilege
27
+ :display
28
+ end
29
+
30
+ def category
31
+ :order
32
+ end
33
+ end
34
+
25
35
  def activate!
26
36
  can [:read, :admin, :edit, :cart], Spree::Order
27
37
  can [:read, :admin], Spree::Payment
@@ -21,6 +21,16 @@ module Spree
21
21
  #
22
22
  # It also allows reading reimbursement types, but not modifying them.
23
23
  class OrderManagement < PermissionSets::Base
24
+ class << self
25
+ def privilege
26
+ :management
27
+ end
28
+
29
+ def category
30
+ :order
31
+ end
32
+ end
33
+
24
34
  def activate!
25
35
  can :read, Spree::ReimbursementType
26
36
  can :manage, Spree::Order
@@ -17,6 +17,16 @@ module Spree
17
17
  # - Taxonomies
18
18
  # - Taxons
19
19
  class ProductDisplay < PermissionSets::Base
20
+ class << self
21
+ def privilege
22
+ :display
23
+ end
24
+
25
+ def category
26
+ :product
27
+ end
28
+ end
29
+
20
30
  def activate!
21
31
  can [:read, :admin, :edit], Spree::Product
22
32
  can [:read, :admin], Spree::Image
@@ -19,6 +19,16 @@ module Spree
19
19
  # - Classifications
20
20
  # - Prices
21
21
  class ProductManagement < PermissionSets::Base
22
+ class << self
23
+ def privilege
24
+ :management
25
+ end
26
+
27
+ def category
28
+ :product
29
+ end
30
+ end
31
+
22
32
  def activate!
23
33
  can :manage, Spree::Classification
24
34
  can :manage, Spree::Image
@@ -8,6 +8,16 @@ module Spree
8
8
  # locations, both of them limited to locations they have access to.
9
9
  # Permissions are also granted for the admin panel for items.
10
10
  class RestrictedStockDisplay < PermissionSets::Base
11
+ class << self
12
+ def privilege
13
+ :display
14
+ end
15
+
16
+ def category
17
+ :restricted_stock
18
+ end
19
+ end
20
+
11
21
  def activate!
12
22
  can [:read, :admin], Spree::StockItem, stock_location_id: location_ids
13
23
  can :read, Spree::StockLocation, id: location_ids
@@ -8,6 +8,16 @@ module Spree
8
8
  # access to their locations. Those locations are also readable by the
9
9
  # corresponding ability.
10
10
  class RestrictedStockManagement < PermissionSets::Base
11
+ class << self
12
+ def privilege
13
+ :management
14
+ end
15
+
16
+ def category
17
+ :restricted_stock
18
+ end
19
+ end
20
+
11
21
  def activate!
12
22
  can :manage, Spree::StockItem, stock_location_id: location_ids
13
23
  can :read, Spree::StockLocation, id: location_ids
@@ -7,6 +7,16 @@ module Spree
7
7
  # This permission set allows users to view information about stock items
8
8
  # (also from the admin panel) and stock locations.
9
9
  class StockDisplay < PermissionSets::Base
10
+ class << self
11
+ def privilege
12
+ :display
13
+ end
14
+
15
+ def category
16
+ :stock
17
+ end
18
+ end
19
+
10
20
  def activate!
11
21
  can [:read, :admin], Spree::StockItem
12
22
  can :read, Spree::StockLocation
@@ -7,6 +7,16 @@ module Spree
7
7
  # This permission set grants full control over all stock items and read
8
8
  # access to locations.
9
9
  class StockManagement < PermissionSets::Base
10
+ class << self
11
+ def privilege
12
+ :management
13
+ end
14
+
15
+ def category
16
+ :stock
17
+ end
18
+ end
19
+
10
20
  def activate!
11
21
  can :manage, Spree::StockItem
12
22
  can :read, Spree::StockLocation
@@ -8,6 +8,16 @@ module Spree
8
8
  #
9
9
  # It grants permission to perform any read or write action on any resource.
10
10
  class SuperUser < PermissionSets::Base
11
+ class << self
12
+ def privilege
13
+ :other
14
+ end
15
+
16
+ def category
17
+ :super_user
18
+ end
19
+ end
20
+
11
21
  def activate!
12
22
  can :manage, :all
13
23
  end
@@ -7,6 +7,16 @@ module Spree
7
7
  # This permission set allows users to view all related information about
8
8
  # users, roles and store credits, also from the admin panel.
9
9
  class UserDisplay < PermissionSets::Base
10
+ class << self
11
+ def privilege
12
+ :display
13
+ end
14
+
15
+ def category
16
+ :user
17
+ end
18
+ end
19
+
10
20
  def activate!
11
21
  can [:read, :admin, :edit, :addresses, :orders, :items], Spree.user_class
12
22
  can [:read, :admin], Spree::StoreCredit
@@ -12,6 +12,16 @@ module Spree
12
12
  # - Roles
13
13
  # - API keys
14
14
  class UserManagement < PermissionSets::Base
15
+ class << self
16
+ def privilege
17
+ :management
18
+ end
19
+
20
+ def category
21
+ :user
22
+ end
23
+ end
24
+
15
25
  def activate!
16
26
  can [:admin, :read, :create, :update, :save_in_address_book, :remove_from_address_book, :addresses, :orders, :items], Spree.user_class
17
27
 
@@ -9,8 +9,6 @@ require 'spree/permission_sets/order_display'
9
9
  require 'spree/permission_sets/order_management'
10
10
  require 'spree/permission_sets/product_display'
11
11
  require 'spree/permission_sets/product_management'
12
- require 'spree/permission_sets/promotion_display'
13
- require 'spree/permission_sets/promotion_management'
14
12
  require 'spree/permission_sets/restricted_stock_display'
15
13
  require 'spree/permission_sets/restricted_stock_management'
16
14
  require 'spree/permission_sets/stock_display'
@@ -95,7 +95,7 @@ module Spree
95
95
  :number, :month, :year, :expiry, :verification_value,
96
96
  :first_name, :last_name, :cc_type, :gateway_customer_profile_id,
97
97
  :gateway_payment_profile_id, :last_digits, :name, :encrypted_data,
98
- :wallet_payment_source_id, address_attributes: address_attributes
98
+ :wallet_payment_source_id, address_attributes:
99
99
  ]
100
100
 
101
101
  @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]
@@ -153,7 +153,7 @@ module Spree
153
153
 
154
154
  @@checkout_payment_attributes = [
155
155
  payments_attributes: payment_attributes + [
156
- source_attributes: source_attributes
156
+ source_attributes:
157
157
  ]
158
158
  ]
159
159
 
@@ -19,7 +19,7 @@ module Spree::Preferences
19
19
 
20
20
  def exist?(key)
21
21
  @cache.exist?(key) ||
22
- should_persist? && Spree::Preference.where(key: key).exists?
22
+ should_persist? && Spree::Preference.where(key:).exists?
23
23
  end
24
24
 
25
25
  def get(key)
@@ -35,7 +35,7 @@ module Spree::Preferences
35
35
  # has been cleared from the cache
36
36
 
37
37
  # does it exist in the database?
38
- if preference = Spree::Preference.find_by(key: key)
38
+ if preference = Spree::Preference.find_by(key:)
39
39
  # it does exist
40
40
  val = preference.value
41
41
  else
@@ -23,7 +23,7 @@ module Spree
23
23
  field.dispatchEvent(event);
24
24
  JS
25
25
  else
26
- fill_in locator, with: with
26
+ fill_in locator, with:
27
27
  end
28
28
  end
29
29
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cancan'
4
+
5
+ class DummyAbility
6
+ include CanCan::Ability
7
+ end
@@ -9,8 +9,8 @@
9
9
 
10
10
  db_host =
11
11
  case adapter
12
- when 'mysql' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
13
- when 'postgres' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
12
+ when 'mysql2' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
13
+ when 'postgresql' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
14
14
  else ENV['DB_HOST']
15
15
  end
16
16
 
@@ -4,21 +4,6 @@ module DummyApp
4
4
  module Migrations
5
5
  extend self
6
6
 
7
- # Ensure database exists
8
- def database_exists?
9
- ActiveRecord::Base.connection
10
- rescue ActiveRecord::NoDatabaseError
11
- false
12
- else
13
- true
14
- end
15
-
16
- def needs_migration?
17
- return true if !database_exists?
18
-
19
- ActiveRecord::Base.connection.migration_context.needs_migration?
20
- end
21
-
22
7
  def auto_migrate
23
8
  if needs_migration?
24
9
  puts "Configuration changed. Re-running migrations"
@@ -35,6 +20,14 @@ module DummyApp
35
20
 
36
21
  private
37
22
 
23
+ def needs_migration?
24
+ ActiveRecord::Migration.check_all_pending!
25
+ rescue ActiveRecord::PendingMigrationError, ActiveRecord::NoDatabaseError
26
+ true
27
+ else
28
+ false
29
+ end
30
+
38
31
  def sh(cmd)
39
32
  puts cmd
40
33
  system cmd
@@ -10,8 +10,8 @@ module DummyApp
10
10
  require lib_name
11
11
  require 'spree/testing_support/dummy_app'
12
12
  DummyApp.setup(
13
- gem_root: gem_root,
14
- lib_name: lib_name,
13
+ gem_root:,
14
+ lib_name:,
15
15
  auto_migrate: false
16
16
  )
17
17
  end
@@ -20,6 +20,7 @@ end
20
20
 
21
21
  # @private
22
22
  class ApplicationRecord < ActiveRecord::Base
23
+ self.abstract_class = true
23
24
  end
24
25
 
25
26
  # @private
@@ -34,10 +35,19 @@ end
34
35
  module DummyApp
35
36
  def self.setup(gem_root:, lib_name:, auto_migrate: true)
36
37
  ENV["LIB_NAME"] = lib_name
37
- DummyApp::Application.config.root = File.join(gem_root, 'spec', 'dummy')
38
+ root = Pathname(gem_root).join('spec/dummy')
39
+ root.join("app/assets/config").mkpath
40
+ root.join("app/assets/config/manifest.js").write("// Intentionally empty\n")
38
41
 
42
+ DummyApp::Application.config.root = root
39
43
  DummyApp::Application.initialize! unless DummyApp::Application.initialized?
40
44
 
45
+ # Raise on deprecation warnings.
46
+ # NOTE: This needs to happen after the application is initialized.
47
+ if ENV['SOLIDUS_RAISE_DEPRECATIONS'].present?
48
+ Spree.deprecator.behavior = :raise
49
+ end
50
+
41
51
  if auto_migrate
42
52
  DummyApp::Migrations.auto_migrate
43
53
  end
@@ -46,11 +56,6 @@ module DummyApp
46
56
  class Application < ::Rails::Application
47
57
  config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
48
58
 
49
- if Rails.gem_version >= Gem::Version.new('7.1')
50
- config.action_controller.raise_on_missing_callback_actions = true
51
- config.action_dispatch.show_exceptions = :none
52
- end
53
-
54
59
  # Make the test environment more production-like:
55
60
  config.action_controller.allow_forgery_protection = false
56
61
  config.action_controller.default_protect_from_forgery = false
@@ -68,8 +73,13 @@ module DummyApp
68
73
  config.cache_classes = true
69
74
 
70
75
  # Make debugging easier:
76
+ if Rails.gem_version >= Gem::Version.new('7.1')
77
+ config.action_controller.raise_on_missing_callback_actions = true
78
+ config.action_dispatch.show_exceptions = :none
79
+ else
80
+ config.action_dispatch.show_exceptions = false
81
+ end
71
82
  config.consider_all_requests_local = true
72
- config.action_dispatch.show_exceptions = false # Should be :none for Rails 7.1+
73
83
  config.active_support.deprecation = :stderr
74
84
  config.log_level = :debug
75
85
 
@@ -148,8 +158,3 @@ Spree.config do |config|
148
158
  config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
149
159
  end
150
160
  end
151
-
152
- # Raise on deprecation warnings
153
- if ENV['SOLIDUS_RAISE_DEPRECATIONS'].present?
154
- Spree.deprecator.behavior = :raise
155
- end
@@ -7,7 +7,6 @@ FactoryBot.define do
7
7
  amount { 100.0 }
8
8
  label { 'Shipping' }
9
9
  association(:source, factory: :tax_rate)
10
- eligible { true }
11
10
 
12
11
  after(:build) do |adjustment|
13
12
  adjustments = adjustment.adjustable.adjustments
@@ -31,7 +30,7 @@ FactoryBot.define do
31
30
  adjustment.source.tax_categories = []
32
31
  end
33
32
  adjustment.source.save
34
- adjustment.recalculate
33
+ adjustment.update!(amount: adjustment.source.compute_amount(adjustment.adjustable))
35
34
  end
36
35
  end
37
36
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  FactoryBot.define do
4
- factory :calculator, aliases: [:flat_rate_calculator], class: 'Spree::Calculator::FlatRate' do
4
+ factory :flat_rate_calculator, aliases: [:calculator], class: 'Spree::Calculator::FlatRate' do
5
5
  preferred_amount { 10.0 }
6
6
  end
7
7
 
@@ -22,8 +22,4 @@ FactoryBot.define do
22
22
  factory :shipping_no_amount_calculator, class: 'Spree::Calculator::Shipping::FlatRate' do
23
23
  preferred_amount { 0 }
24
24
  end
25
-
26
- factory :percent_on_item_calculator, class: 'Spree::Calculator::PercentOnLineItem' do
27
- preferred_percent { 10 }
28
- end
29
25
  end
@@ -13,8 +13,8 @@ FactoryBot.define do
13
13
  # ensure the shipment uses the same stock location as the carton
14
14
  shipment: build(
15
15
  :shipment,
16
- stock_location: stock_location,
17
- shipping_method: shipping_method
16
+ stock_location:,
17
+ shipping_method:
18
18
  )
19
19
  )
20
20
  ]
@@ -7,13 +7,13 @@ FactoryBot.define do
7
7
  transient do
8
8
  line_items_count { 1 }
9
9
  return_items_count { line_items_count }
10
- shipped_order { create :shipped_order, line_items_count: line_items_count }
10
+ shipped_order { create :shipped_order, line_items_count: }
11
11
  return_authorization { create :return_authorization, order: shipped_order }
12
12
  end
13
13
 
14
14
  before(:create) do |customer_return, evaluator|
15
15
  evaluator.shipped_order.inventory_units.take(evaluator.return_items_count).each do |inventory_unit|
16
- customer_return.return_items << build(:return_item, inventory_unit: inventory_unit, return_authorization: evaluator.return_authorization)
16
+ customer_return.return_items << build(:return_item, inventory_unit:, return_authorization: evaluator.return_authorization)
17
17
  end
18
18
  end
19
19
 
@@ -10,15 +10,15 @@ FactoryBot.define do
10
10
  association :variant, strategy: :create
11
11
  line_item do
12
12
  if order
13
- build(:line_item, variant: variant, order: order)
13
+ build(:line_item, variant:, order:)
14
14
  else
15
- build(:line_item, variant: variant)
15
+ build(:line_item, variant:)
16
16
  end
17
17
  end
18
18
  state { 'on_hand' }
19
19
  shipment do
20
20
  if stock_location
21
- build(:shipment, state: 'pending', order: line_item.order, stock_location: stock_location)
21
+ build(:shipment, state: 'pending', order: line_item.order, stock_location:)
22
22
  else
23
23
  build(:shipment, state: 'pending', order: line_item.order)
24
24
  end
@@ -43,36 +43,17 @@ FactoryBot.define do
43
43
  evaluator.stock_location # must evaluate before creating line items
44
44
 
45
45
  evaluator.line_items_attributes.each do |attributes|
46
- attributes = { order: order, price: evaluator.line_items_price }.merge(attributes)
46
+ attributes = { order:, price: evaluator.line_items_price }.merge(attributes)
47
47
  create(:line_item, attributes)
48
48
  end
49
49
  order.line_items.reload
50
50
 
51
- create(:shipment, order: order, cost: evaluator.shipment_cost, shipping_method: evaluator.shipping_method, stock_location: evaluator.stock_location)
51
+ create(:shipment, order:, cost: evaluator.shipment_cost, shipping_method: evaluator.shipping_method, stock_location: evaluator.stock_location)
52
52
  order.shipments.reload
53
53
 
54
54
  order.recalculate
55
55
  end
56
56
 
57
- factory :completed_order_with_promotion do
58
- transient do
59
- completed_at { Time.current }
60
- promotion { nil }
61
- end
62
-
63
- after(:create) do |order, evaluator|
64
- promotion = evaluator.promotion || create(:promotion, code: "test")
65
- promotion_code = promotion.codes.first || create(:promotion_code, promotion: promotion)
66
-
67
- promotion.activate(order: order, promotion_code: promotion_code)
68
- order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
69
-
70
- # Complete the order after the promotion has been activated
71
- order.update_column(:completed_at, evaluator.completed_at)
72
- order.update_column(:state, "complete")
73
- end
74
- end
75
-
76
57
  factory :order_ready_to_complete do
77
58
  state { 'confirm' }
78
59
  payment_state { 'checkout' }
@@ -84,7 +65,7 @@ FactoryBot.define do
84
65
  after(:create) do |order, evaluator|
85
66
  create(evaluator.payment_type, {
86
67
  amount: order.total,
87
- order: order,
68
+ order:,
88
69
  state: order.payment_state
89
70
  })
90
71
 
@@ -107,7 +88,7 @@ FactoryBot.define do
107
88
 
108
89
  factory :completed_order_with_pending_payment do
109
90
  after(:create) do |order|
110
- create(:payment, amount: order.total, order: order, state: 'pending')
91
+ create(:payment, amount: order.total, order:, state: 'pending')
111
92
  end
112
93
  end
113
94
 
@@ -120,7 +101,7 @@ FactoryBot.define do
120
101
  end
121
102
 
122
103
  after(:create) do |order, evaluator|
123
- create(evaluator.payment_type, amount: order.total, order: order, state: 'completed')
104
+ create(evaluator.payment_type, amount: order.total, order:, state: 'completed')
124
105
  order.shipments.each do |shipment|
125
106
  shipment.update_column('state', 'ready')
126
107
  end
@@ -40,7 +40,7 @@ FactoryBot.define do
40
40
  end
41
41
 
42
42
  factory :product_with_option_types do
43
- after(:create) { |product| create(:product_option_type, product: product) }
43
+ after(:create) { |product| create(:product_option_type, product:) }
44
44
  end
45
45
  end
46
46
  end
@@ -15,7 +15,7 @@ FactoryBot.define do
15
15
  after(:create) do |shipment, evaluator|
16
16
  shipping_method = evaluator.shipping_method || create(:shipping_method, cost: evaluator.cost)
17
17
  shipment.shipping_rates.create!(
18
- shipping_method: shipping_method,
18
+ shipping_method:,
19
19
  cost: evaluator.cost,
20
20
  selected: true
21
21
  )