solidus_core 2.11.10 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/assets/javascripts/spree.js.erb +0 -51
  4. data/app/controllers/spree/base_controller.rb +1 -1
  5. data/app/helpers/spree/base_helper.rb +1 -1
  6. data/app/helpers/spree/products_helper.rb +2 -2
  7. data/app/helpers/spree/store_helper.rb +0 -11
  8. data/app/mailers/spree/carton_mailer.rb +1 -5
  9. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
  10. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  11. data/app/models/concerns/spree/adjustment_source.rb +0 -15
  12. data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
  13. data/app/models/concerns/spree/default_price.rb +39 -10
  14. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  15. data/app/models/concerns/spree/soft_deletable.rb +2 -4
  16. data/app/models/concerns/spree/user_address_book.rb +10 -37
  17. data/app/models/concerns/spree/user_methods.rb +38 -13
  18. data/app/models/spree/ability.rb +0 -37
  19. data/app/models/spree/address/name.rb +2 -20
  20. data/app/models/spree/address.rb +8 -186
  21. data/app/models/spree/adjustment.rb +7 -33
  22. data/app/models/spree/base.rb +0 -53
  23. data/app/models/spree/calculator/flat_fee.rb +21 -0
  24. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  25. data/app/models/spree/calculator.rb +0 -7
  26. data/app/models/spree/carton.rb +1 -1
  27. data/app/models/spree/country.rb +2 -7
  28. data/app/models/spree/credit_card.rb +1 -28
  29. data/app/models/spree/customer_return.rb +5 -7
  30. data/app/models/spree/image/active_storage_attachment.rb +2 -7
  31. data/app/models/spree/image/paperclip_attachment.rb +2 -2
  32. data/app/models/spree/image.rb +0 -7
  33. data/app/models/spree/inventory_unit.rb +0 -21
  34. data/app/models/spree/line_item.rb +6 -49
  35. data/app/models/spree/log_entry.rb +74 -1
  36. data/app/models/spree/option_type.rb +1 -1
  37. data/app/models/spree/option_value.rb +10 -1
  38. data/app/models/spree/order/number_generator.rb +7 -1
  39. data/app/models/spree/order.rb +82 -170
  40. data/app/models/spree/order_cancellations.rb +4 -24
  41. data/app/models/spree/order_contents.rb +2 -1
  42. data/app/models/spree/order_inventory.rb +1 -1
  43. data/app/models/spree/order_merger.rb +2 -2
  44. data/app/models/spree/order_promotion.rb +1 -1
  45. data/app/models/spree/order_shipping.rb +6 -9
  46. data/app/models/spree/order_taxation.rb +6 -4
  47. data/app/models/spree/order_updater.rb +17 -16
  48. data/app/models/spree/payment/cancellation.rb +1 -1
  49. data/app/models/spree/payment/processing.rb +58 -55
  50. data/app/models/spree/payment.rb +0 -3
  51. data/app/models/spree/payment_create.rb +1 -13
  52. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  53. data/app/models/spree/payment_method/credit_card.rb +1 -3
  54. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  55. data/app/models/spree/payment_method.rb +26 -110
  56. data/app/models/spree/price.rb +3 -3
  57. data/app/models/spree/product/scopes.rb +24 -33
  58. data/app/models/spree/product.rb +15 -42
  59. data/app/models/spree/product_property.rb +1 -1
  60. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
  61. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
  62. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  63. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  64. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  65. data/app/models/spree/promotion/rules/item_total.rb +50 -6
  66. data/app/models/spree/promotion/rules/product.rb +20 -8
  67. data/app/models/spree/promotion/rules/store.rb +4 -0
  68. data/app/models/spree/promotion/rules/taxon.rb +6 -15
  69. data/app/models/spree/promotion/rules/user.rb +4 -0
  70. data/app/models/spree/promotion.rb +39 -32
  71. data/app/models/spree/promotion_action.rb +6 -9
  72. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  73. data/app/models/spree/promotion_code.rb +11 -7
  74. data/app/models/spree/promotion_handler/cart.rb +26 -6
  75. data/app/models/spree/promotion_rule.rb +5 -0
  76. data/app/models/spree/property.rb +1 -1
  77. data/app/models/spree/refund.rb +8 -52
  78. data/app/models/spree/reimbursement.rb +5 -43
  79. data/app/models/spree/reimbursement_performer.rb +2 -8
  80. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  81. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  82. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  83. data/app/models/spree/return_authorization.rb +2 -5
  84. data/app/models/spree/return_item.rb +4 -24
  85. data/app/models/spree/shipment.rb +3 -56
  86. data/app/models/spree/shipping_method.rb +0 -25
  87. data/app/models/spree/shipping_rate.rb +0 -2
  88. data/app/models/spree/shipping_rate_tax.rb +1 -1
  89. data/app/models/spree/state.rb +1 -5
  90. data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
  91. data/app/models/spree/stock/availability.rb +11 -3
  92. data/app/models/spree/stock/quantifier.rb +12 -8
  93. data/app/models/spree/stock/simple_coordinator.rb +8 -26
  94. data/app/models/spree/stock/splitter/base.rb +2 -7
  95. data/app/models/spree/stock_item.rb +2 -8
  96. data/app/models/spree/stock_location.rb +2 -2
  97. data/app/models/spree/stock_movement.rb +2 -2
  98. data/app/models/spree/store.rb +0 -12
  99. data/app/models/spree/store_credit.rb +14 -1
  100. data/app/models/spree/store_credit_category.rb +0 -32
  101. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  102. data/app/models/spree/tax/item_tax.rb +3 -2
  103. data/app/models/spree/tax/order_tax.rb +3 -1
  104. data/app/models/spree/tax/tax_helpers.rb +2 -2
  105. data/app/models/spree/tax/tax_location.rb +4 -7
  106. data/app/models/spree/tax_calculator/default.rb +31 -0
  107. data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
  108. data/app/models/spree/tax_rate.rb +9 -27
  109. data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
  110. data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
  111. data/app/models/spree/taxon.rb +1 -12
  112. data/app/models/spree/taxonomy.rb +1 -1
  113. data/app/models/spree/user_address.rb +0 -5
  114. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  115. data/app/models/spree/variant/price_selector.rb +34 -4
  116. data/app/models/spree/variant.rb +52 -66
  117. data/app/models/spree/zone.rb +1 -1
  118. data/app/subscribers/spree/mailer_subscriber.rb +4 -0
  119. data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
  120. data/config/i18n-tasks.yml +134 -0
  121. data/config/locales/en.yml +406 -263
  122. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  123. data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
  124. data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
  125. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  126. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  127. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  128. data/db/seeds.rb +4 -1
  129. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  130. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  131. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  132. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  133. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  134. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  135. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  136. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  137. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
  138. data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
  139. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
  140. data/lib/generators/solidus/install/install_generator.rb +247 -149
  141. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
  142. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
  143. data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
  144. data/lib/generators/solidus/update/update_generator.rb +112 -0
  145. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  146. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  147. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  148. data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
  149. data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
  150. data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
  151. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  152. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  153. data/lib/spree/app_configuration.rb +134 -64
  154. data/lib/spree/bus.rb +20 -0
  155. data/lib/spree/core/class_constantizer.rb +2 -0
  156. data/lib/spree/core/controller_helpers/auth.rb +10 -15
  157. data/lib/spree/core/controller_helpers/current_host.rb +5 -3
  158. data/lib/spree/core/controller_helpers/order.rb +12 -32
  159. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  160. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  161. data/lib/spree/core/controller_helpers/search.rb +1 -1
  162. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  163. data/lib/spree/core/engine.rb +54 -50
  164. data/lib/spree/core/environment_extension.rb +0 -9
  165. data/lib/spree/core/product_filters.rb +1 -41
  166. data/lib/spree/core/role_configuration.rb +0 -14
  167. data/lib/spree/core/search/base.rb +18 -35
  168. data/lib/spree/core/state_machines/order.rb +2 -2
  169. data/lib/spree/core/state_machines.rb +2 -11
  170. data/lib/spree/core/stock_configuration.rb +18 -0
  171. data/lib/spree/core/validators/email.rb +5 -3
  172. data/lib/spree/core/version.rb +5 -1
  173. data/lib/spree/core/versioned_value.rb +75 -0
  174. data/lib/spree/core.rb +40 -11
  175. data/lib/spree/deprecation.rb +1 -1
  176. data/lib/spree/event/configuration.rb +0 -5
  177. data/lib/spree/event/subscriber.rb +0 -18
  178. data/lib/spree/event/subscriber_registry.rb +7 -7
  179. data/lib/spree/event.rb +1 -32
  180. data/lib/spree/i18n.rb +0 -22
  181. data/lib/spree/migrations.rb +13 -11
  182. data/lib/spree/money.rb +3 -18
  183. data/lib/spree/permission_sets/default_customer.rb +8 -1
  184. data/lib/spree/permitted_attributes.rb +17 -59
  185. data/lib/spree/preferences/configuration.rb +84 -0
  186. data/lib/spree/preferences/preferable.rb +13 -0
  187. data/lib/spree/preferences/preferable_class_methods.rb +37 -4
  188. data/lib/spree/preferences/preference_differentiator.rb +29 -0
  189. data/lib/spree/preferences/static_model_preferences.rb +25 -10
  190. data/lib/spree/rails_compatibility.rb +106 -0
  191. data/lib/spree/testing_support/blacklist_urls.rb +1 -1
  192. data/lib/spree/testing_support/bus_helpers.rb +101 -0
  193. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  194. data/lib/spree/testing_support/common_rake.rb +71 -23
  195. data/lib/spree/testing_support/controller_requests.rb +0 -82
  196. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
  197. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
  198. data/lib/spree/testing_support/dummy_app/database.yml +42 -22
  199. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  200. data/lib/spree/testing_support/dummy_app.rb +47 -34
  201. data/lib/spree/testing_support/factories/address_factory.rb +9 -6
  202. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  203. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  204. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
  205. data/lib/spree/testing_support/factories/order_factory.rb +8 -5
  206. data/lib/spree/testing_support/factories/product_factory.rb +4 -1
  207. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  208. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  209. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  210. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
  211. data/lib/spree/testing_support/factories/user_factory.rb +6 -0
  212. data/lib/spree/testing_support/factory_bot.rb +2 -2
  213. data/lib/spree/testing_support/order_walkthrough.rb +6 -8
  214. data/lib/spree/testing_support/preferences.rb +0 -25
  215. data/lib/spree/testing_support/silence_deprecations.rb +9 -0
  216. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  217. data/lib/tasks/payment_method.rake +29 -0
  218. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
  219. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
  220. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
  221. data/solidus_core.gemspec +14 -7
  222. metadata +127 -78
  223. data/app/mailers/spree/test_mailer.rb +0 -13
  224. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  225. data/app/models/spree/calculator/free_shipping.rb +0 -22
  226. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  227. data/app/models/spree/calculator/price_sack.rb +0 -28
  228. data/app/models/spree/gateway/bogus.rb +0 -13
  229. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  230. data/app/models/spree/gateway.rb +0 -14
  231. data/app/models/spree/order/checkout.rb +0 -244
  232. data/app/models/spree/order_capturing.rb +0 -50
  233. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  234. data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
  235. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
  236. data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
  237. data/lib/generators/spree/install/install_generator.rb +0 -15
  238. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  239. data/lib/spree/core/current_store.rb +0 -24
  240. data/lib/spree/paranoia_deprecations.rb +0 -41
  241. data/lib/spree/promo/environment.rb +0 -12
  242. data/lib/spree/testing_support/bar_ability.rb +0 -19
  243. data/lib/tasks/core.rake +0 -104
  244. data/lib/tasks/email.rake +0 -12
  245. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  246. data/lib/tasks/migrations/migrate_address_names.rake +0 -158
  247. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
  248. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  249. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  250. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  251. data/lib/tasks/order_capturing.rake +0 -27
  252. data/lib/tasks/upgrade.rake +0 -13
@@ -7,6 +7,7 @@ require 'rails'
7
7
  require 'active_record/railtie'
8
8
  require 'action_controller/railtie'
9
9
  require 'action_mailer/railtie'
10
+ require 'active_storage/engine'
10
11
 
11
12
  Rails.env = 'test'
12
13
 
@@ -37,7 +38,7 @@ module DummyApp
37
38
  ENV["LIB_NAME"] = lib_name
38
39
  DummyApp::Application.config.root = File.join(gem_root, 'spec', 'dummy')
39
40
 
40
- DummyApp::Application.initialize!
41
+ DummyApp::Application.initialize! unless DummyApp::Application.initialized?
41
42
 
42
43
  if auto_migrate
43
44
  DummyApp::Migrations.auto_migrate
@@ -45,37 +46,60 @@ module DummyApp
45
46
  end
46
47
 
47
48
  class Application < ::Rails::Application
48
- config.eager_load = false
49
- config.cache_classes = true
50
- config.cache_store = :memory_store
51
- config.serve_static_assets = true
52
- config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
53
- config.whiny_nils = true
54
- config.consider_all_requests_local = true
49
+ config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
50
+ # Make the test environment more production-like:
55
51
  config.action_controller.allow_forgery_protection = false
56
52
  config.action_controller.default_protect_from_forgery = false
53
+ config.action_mailer.perform_caching = false
54
+ config.i18n.fallbacks = true
55
+
56
+ # In the test environment, we use the `caching: true` RSpec metadata to
57
+ # enable caching on select specs. See
58
+ # core/lib/spree/testing_support/caching.rb. See also
59
+ # https://github.com/solidusio/solidus/issues/4110
57
60
  config.action_controller.perform_caching = false
61
+
62
+ # It needs to be explicitly set from Rails 7
63
+ # https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-6-1-to-rails-7-0-spring
64
+ config.cache_classes = true
65
+
66
+ # Make debugging easier:
67
+ config.consider_all_requests_local = true
58
68
  config.action_dispatch.show_exceptions = false
59
69
  config.active_support.deprecation = :stderr
70
+ config.log_level = :debug
71
+
72
+ # Improve test suite performance:
73
+ config.eager_load = false
74
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
75
+ config.cache_store = :memory_store
76
+
77
+ # We don't use a web server, so we let Rails serve assets.
78
+ config.public_file_server.enabled = true
79
+
80
+ # We don't want to send email in the test environment.
60
81
  config.action_mailer.delivery_method = :test
61
- config.active_support.deprecation = :stderr
82
+
83
+ # No need to use credentials file in a test environment.
62
84
  config.secret_key_base = 'SECRET_TOKEN'
63
85
 
64
- config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" if RAILS_6_OR_ABOVE
86
+ # Set the preview path within the dummy app:
65
87
  config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
66
- config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE
67
88
 
68
- config.storage_path = Rails.root.join('tmp', 'storage')
89
+ config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE
90
+ config.active_record.dump_schema_after_migration = false
69
91
 
70
- if ENV['ENABLE_ACTIVE_STORAGE']
92
+ # Configure active storage to use storage within tmp folder
93
+ unless (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
71
94
  initializer 'solidus.active_storage' do
72
95
  config.active_storage.service_configurations = {
73
96
  test: {
74
97
  service: 'Disk',
75
- root: config.storage_path
98
+ root: Rails.root.join('tmp', 'storage')
76
99
  }
77
100
  }
78
101
  config.active_storage.service = :test
102
+ config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', Spree::RailsCompatibility.variant_processor).to_sym
79
103
  end
80
104
  end
81
105
 
@@ -92,13 +116,10 @@ module DummyApp
92
116
  end
93
117
  config.paths['db/migrate'] = migration_dirs
94
118
  ActiveRecord::Migrator.migrations_paths = migration_dirs
119
+ ActiveRecord::Migration.verbose = false
95
120
 
96
- config.action_controller.include_all_helpers = false
97
-
98
- if config.respond_to?(:assets)
99
- config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__)
100
- config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__)
101
- end
121
+ config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__)
122
+ config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__)
102
123
 
103
124
  config.paths["config/database"] = File.expand_path('dummy_app/database.yml', __dir__)
104
125
  config.paths['app/views'] = File.expand_path('dummy_app/views', __dir__)
@@ -115,21 +136,13 @@ ActiveSupport.on_load(:action_controller) do
115
136
  end
116
137
 
117
138
  Spree.user_class = 'Spree::LegacyUser'
139
+ Spree.load_defaults(Spree.solidus_version)
118
140
  Spree.config do |config|
119
- config.use_legacy_address_state_validator = false
120
- config.mails_from = "store@example.com"
121
- config.raise_with_invalid_currency = false
122
- config.redirect_back_on_unauthorized = true
123
- config.run_order_validations_on_order_updater = true
124
- config.use_combined_first_and_last_name_in_address = true
125
- config.use_legacy_order_state_machine = false
126
- config.use_custom_cancancan_actions = false
127
- config.consider_actionless_promotion_active = false
128
- config.use_legacy_store_credit_reimbursement_category_name = false
129
-
130
- if ENV['ENABLE_ACTIVE_STORAGE']
131
- config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'
132
- config.taxon_attachment_module = 'Spree::Taxon::ActiveStorageAttachment'
141
+ config.use_legacy_events = (ENV['USE_LEGACY_EVENTS'] == 'true')
142
+
143
+ if (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
144
+ config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
145
+ config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
133
146
  end
134
147
  end
135
148
 
@@ -24,16 +24,19 @@ FactoryBot.define do
24
24
  phone { '555-555-0199' }
25
25
  alternative_phone { '555-555-0199' }
26
26
 
27
- state do |address|
28
- Spree::State.joins(:country).where('spree_countries.iso = (?)', country_iso_code).find_by(abbr: state_code) ||
29
- address.association(:state, country_iso: country_iso_code, state_code: state_code)
30
- end
31
-
32
27
  country do |address|
33
28
  if address.state
34
29
  address.state.country
35
30
  else
36
- address.association(:country, iso: country_iso_code)
31
+ Spree::Country.find_by(iso: country_iso_code) ||
32
+ address.association(:country, strategy: :create, iso: country_iso_code)
33
+ end
34
+ end
35
+
36
+ after(:build) do |address, evaluator|
37
+ if address&.country&.states_required? && address.state.nil? && address.state_name.nil?
38
+ address.state = address.country.states.find_by(abbr: evaluator.state_code) ||
39
+ create(:state, country_iso: address.country.iso, state_code: evaluator.state_code)
37
40
  end
38
41
  end
39
42
  end
@@ -17,6 +17,9 @@ FactoryBot.define do
17
17
  factory :default_tax_calculator, class: 'Spree::Calculator::DefaultTax' do
18
18
  end
19
19
 
20
+ factory :flat_fee_calculator, class: 'Spree::Calculator::FlatFee' do
21
+ end
22
+
20
23
  factory :shipping_calculator, class: 'Spree::Calculator::Shipping::FlatRate' do
21
24
  preferred_amount { 10.0 }
22
25
  end
@@ -20,7 +20,6 @@ FactoryBot.define do
20
20
  iso3 { carmen_country.alpha_3_code }
21
21
  numcode { carmen_country.numeric_code }
22
22
 
23
- # FIXME: We should set states required, but it causes failing tests
24
- # states_required { carmen_country.subregions? }
23
+ states_required { carmen_country.subregions? }
25
24
  end
26
25
  end
@@ -17,7 +17,7 @@ FactoryBot.define do
17
17
  stock_location { nil }
18
18
  end
19
19
 
20
- variant
20
+ association :variant, strategy: :create
21
21
  line_item do
22
22
  if order
23
23
  build(:line_item, variant: variant, order: order)
@@ -19,7 +19,7 @@ FactoryBot.define do
19
19
  ship_address
20
20
  completed_at { nil }
21
21
  email { user.try(:email) }
22
- store
22
+ association :store, strategy: :create
23
23
 
24
24
  transient do
25
25
  line_items_price { BigDecimal(10) }
@@ -30,7 +30,6 @@ FactoryBot.define do
30
30
  after(:build) do |order, evaluator|
31
31
  order.line_items << build(
32
32
  :line_item,
33
- order: order,
34
33
  price: evaluator.line_items_price
35
34
  )
36
35
  end
@@ -69,6 +68,7 @@ FactoryBot.define do
69
68
 
70
69
  factory :completed_order_with_promotion do
71
70
  transient do
71
+ completed_at { Time.current }
72
72
  promotion { nil }
73
73
  end
74
74
 
@@ -80,7 +80,7 @@ FactoryBot.define do
80
80
  order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
81
81
 
82
82
  # Complete the order after the promotion has been activated
83
- order.update_column(:completed_at, Time.current)
83
+ order.update_column(:completed_at, evaluator.completed_at)
84
84
  order.update_column(:state, "complete")
85
85
  end
86
86
  end
@@ -105,13 +105,16 @@ FactoryBot.define do
105
105
  end
106
106
 
107
107
  factory :completed_order_with_totals do
108
+ transient do
109
+ completed_at { Time.current }
110
+ end
108
111
  state { 'complete' }
109
112
 
110
- after(:create) do |order|
113
+ after(:create) do |order, evaluator|
111
114
  order.shipments.each do |shipment|
112
115
  shipment.inventory_units.update_all state: 'on_hand', pending: false
113
116
  end
114
- order.update_column(:completed_at, Time.current)
117
+ order.update_column(:completed_at, evaluator.completed_at)
115
118
  end
116
119
 
117
120
  factory :completed_order_with_pending_payment do
@@ -20,7 +20,10 @@ FactoryBot.define do
20
20
  sku { generate(:sku) }
21
21
  available_on { 1.year.ago }
22
22
  deleted_at { nil }
23
- shipping_category { |r| Spree::ShippingCategory.first || r.association(:shipping_category) }
23
+ shipping_category do |r|
24
+ Spree::ShippingCategory.first ||
25
+ r.association(:shipping_category, strategy: :create)
26
+ end
24
27
 
25
28
  # ensure stock item will be created for this products master
26
29
  before(:create) { create(:stock_location) if Spree::StockLocation.count == 0 }
@@ -22,23 +22,40 @@ FactoryBot.define do
22
22
  end
23
23
 
24
24
  trait :with_action do
25
- after(:create) do |promotion, _evaluator|
26
- promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new
25
+ transient do
26
+ promotion_action_class { Spree::Promotion::Actions::CreateAdjustment }
27
+ end
28
+
29
+ after(:create) do |promotion, evaluator|
30
+ promotion.actions << evaluator.promotion_action_class.new
27
31
  end
28
32
  end
29
33
 
30
- trait :with_line_item_adjustment do
34
+ trait :with_adjustable_action do
31
35
  transient do
32
- adjustment_rate { 10 }
36
+ preferred_amount { 10 }
37
+ calculator_class { Spree::Calculator::FlatRate }
38
+ promotion_action_class { Spree::Promotion::Actions::CreateItemAdjustments }
33
39
  end
34
40
 
35
41
  after(:create) do |promotion, evaluator|
36
- calculator = Spree::Calculator::FlatRate.new
37
- calculator.preferred_amount = evaluator.adjustment_rate
38
- Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promotion)
42
+ calculator = evaluator.calculator_class.new
43
+ calculator.preferred_amount = evaluator.preferred_amount
44
+ evaluator.promotion_action_class.create!(calculator: calculator, promotion: promotion)
39
45
  end
40
46
  end
41
47
 
48
+ factory :promotion_with_action_adjustment, traits: [:with_adjustable_action]
49
+
50
+ trait :with_line_item_adjustment do
51
+ transient do
52
+ adjustment_rate { 10 }
53
+ end
54
+
55
+ with_adjustable_action
56
+ preferred_amount { adjustment_rate }
57
+ end
58
+
42
59
  factory :promotion_with_item_adjustment, traits: [:with_line_item_adjustment]
43
60
 
44
61
  trait :with_free_shipping do
@@ -52,14 +69,11 @@ FactoryBot.define do
52
69
  weighted_order_adjustment_amount { 10 }
53
70
  end
54
71
 
55
- after(:create) do |promotion, evaluator|
56
- calculator = Spree::Calculator::FlatRate.new
57
- calculator.preferred_amount = evaluator.weighted_order_adjustment_amount
58
- action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
59
- promotion.actions << action
60
- promotion.save!
61
- end
72
+ with_adjustable_action
73
+ preferred_amount { weighted_order_adjustment_amount }
74
+ promotion_action_class { Spree::Promotion::Actions::CreateAdjustment }
62
75
  end
76
+
63
77
  factory :promotion_with_order_adjustment, traits: [:with_order_adjustment]
64
78
 
65
79
  trait :with_item_total_rule do
@@ -18,7 +18,6 @@ FactoryBot.define do
18
18
 
19
19
  amount { 100.00 }
20
20
  transaction_id { generate(:refund_transaction_id) }
21
- perform_after_create { false }
22
21
  payment do
23
22
  association(:payment, state: 'completed', amount: payment_amount)
24
23
  end
@@ -17,9 +17,15 @@ FactoryBot.define do
17
17
  carmen_subregion do
18
18
  carmen_country = Carmen::Country.coded(country.iso)
19
19
 
20
- carmen_country.subregions.coded(state_code) ||
21
- carmen_country.subregions.sort_by(&:name).first ||
20
+ unless carmen_country.subregions?
22
21
  fail("Country #{country.iso} has no subregions")
22
+ end
23
+
24
+ carmen_regions = carmen_country.subregions
25
+ carmen_regions = carmen_regions.flat_map(&:subregions) if carmen_regions.first.subregions?
26
+ region_collection = Carmen::RegionCollection.new(carmen_regions)
27
+
28
+ region_collection.coded(state_code) || region_collection.sort_by(&:name).first
23
29
  end
24
30
  end
25
31
 
@@ -11,11 +11,11 @@ end
11
11
 
12
12
  FactoryBot.define do
13
13
  factory :store_credit, class: 'Spree::StoreCredit' do
14
- user
15
- association :created_by, factory: :user
16
- association :category, factory: :store_credit_category
14
+ association :user, strategy: :create
15
+ association :created_by, factory: :user, strategy: :create
16
+ association :category, factory: :store_credit_category, strategy: :create
17
17
  amount { 150.00 }
18
18
  currency { "USD" }
19
- association :credit_type, factory: :primary_credit_type
19
+ association :credit_type, factory: :primary_credit_type, strategy: :create
20
20
  end
21
21
  end
@@ -21,6 +21,12 @@ FactoryBot.define do
21
21
  end
22
22
  end
23
23
 
24
+ trait :with_orders do
25
+ after(:create) do |user, _|
26
+ create(:order, user: user)
27
+ end
28
+ end
29
+
24
30
  factory :admin_user do
25
31
  after(:create) do |user, _|
26
32
  admin_role = Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')
@@ -37,14 +37,14 @@ module Spree
37
37
  Spree::Deprecation.warn(
38
38
  "Please do not cherry-pick factories, this is not well supported by FactoryBot, " \
39
39
  'follow the changelog instructions on how to migrate your current setup.',
40
- callsites[index..-1]
40
+ callsites[index..]
41
41
  )
42
42
  end
43
43
 
44
44
  def self.check_version
45
45
  require "factory_bot/version"
46
46
 
47
- requirement = Gem::Requirement.new("~> 4.8")
47
+ requirement = Gem::Requirement.new(">= 4.8")
48
48
  version = Gem::Version.new(::FactoryBot::VERSION)
49
49
 
50
50
  unless requirement.satisfied_by? version
@@ -3,11 +3,11 @@
3
3
  module Spree
4
4
  module TestingSupport
5
5
  class OrderWalkthrough
6
- def self.up_to(state)
7
- new.up_to(state)
6
+ def self.up_to(state, user: nil)
7
+ new.up_to(state, user: user)
8
8
  end
9
9
 
10
- def up_to(state)
10
+ def up_to(state, user: nil)
11
11
  # Need to create a valid zone too...
12
12
  @zone = ::FactoryBot.create(:zone)
13
13
  @country = ::FactoryBot.create(:country)
@@ -23,6 +23,7 @@ module Spree
23
23
  end
24
24
 
25
25
  order = Spree::Order.create!(
26
+ user: user,
26
27
  email: "solidus@example.com",
27
28
  store: Spree::Store.first || ::FactoryBot.create(:store)
28
29
  )
@@ -33,7 +34,7 @@ module Spree
33
34
  states
34
35
  else
35
36
  end_state_position = states.index(state.to_sym)
36
- states[0..end_state_position]
37
+ states[..end_state_position]
37
38
  end
38
39
 
39
40
  states_to_process.each do |state_to_process|
@@ -61,7 +62,7 @@ module Spree
61
62
  end
62
63
 
63
64
  def payment(order)
64
- credit_card = ::FactoryBot.create(:credit_card)
65
+ credit_card = ::FactoryBot.create(:credit_card, user: order.user)
65
66
  order.payments.create!(payment_method: credit_card.payment_method, amount: order.total, source: credit_card)
66
67
  # TODO: maybe look at some way of making this payment_state change automatic
67
68
  order.payment_state = 'paid'
@@ -82,6 +83,3 @@ module Spree
82
83
  end
83
84
  end
84
85
  end
85
-
86
- # @private
87
- OrderWalkthrough = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OrderWalkthrough', 'Spree::TestingSupport::OrderWalkthrough')
@@ -1,33 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/deprecation'
4
-
5
3
  module Spree
6
4
  module TestingSupport
7
5
  module Preferences
8
- # Resets all preferences to default values, you can
9
- # pass a block to override the defaults with a block
10
- #
11
- # reset_spree_preferences do |config|
12
- # config.track_inventory_levels = false
13
- # end
14
- #
15
- # @deprecated
16
- def reset_spree_preferences(&config_block)
17
- Spree::Config.instance_variables.
18
- reject { |iv| iv == :@events_configuration }.
19
- each { |iv| Spree::Config.remove_instance_variable(iv) }
20
- Spree::Config.preference_store = Spree::Config.default_preferences
21
-
22
- if defined?(Railties)
23
- Rails.application.config.spree = Spree::Config.environment
24
- end
25
-
26
- configure_spree_preferences(&config_block) if block_given?
27
- end
28
-
29
- deprecate :reset_spree_preferences, deprecator: Spree::Deprecation
30
-
31
6
  def configure_spree_preferences
32
7
  yield(Spree::Config) if block_given?
33
8
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.around(:each, silence_deprecations: true) do |example|
5
+ Spree::Deprecation.silence do
6
+ example.run
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :taxes do
4
+ desc "Creates all of the records necessary to start collecting the Colorado Delivery Fee"
5
+ task colorado_delivery_fee: :environment do
6
+ usa = Spree::Country.find_by!(iso: "US")
7
+ colorado = usa.states.find_by!(abbr: "CO")
8
+
9
+ ActiveRecord::Base.transaction do
10
+ zone = Spree::Zone.create!(
11
+ name: "Colorado",
12
+ description: "State-based zone containing only Colorado.",
13
+ states: [colorado]
14
+ )
15
+
16
+ calculator = Spree::Calculator::FlatFee.new
17
+ rate = Spree::TaxRate.create!(
18
+ name: "Colorado Delivery Fee",
19
+ calculator: calculator,
20
+ zone: zone,
21
+ amount: 0.27,
22
+ show_rate_in_label: false,
23
+ level: "order"
24
+ )
25
+ rate.tax_categories << Spree::TaxCategory.default if Spree::TaxCategory.default
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :payment_method do
4
+ desc "Deactivates old payment methods and fixes ActiveRecord::SubclassNotFound error, "\
5
+ "which happens after switching Payment Service Provider."
6
+ task deactivate_unsupported_payment_methods: :environment do
7
+ Spree::PaymentMethod.pluck(:id, :type).select do |id, type|
8
+ type.constantize
9
+ rescue NameError
10
+ fix_payment_method_record(id, type)
11
+ end
12
+ end
13
+
14
+ def fix_payment_method_record(id, previous_type)
15
+ connection = ActiveRecord::Base.connection
16
+ false_value = connection.quoted_false
17
+ connection.exec_update(<<-SQL
18
+ UPDATE spree_payment_methods
19
+ SET
20
+ type='#{Spree::PaymentMethod.name}',
21
+ type_before_removal='#{previous_type}',
22
+ active=#{false_value},
23
+ available_to_users=#{false_value},
24
+ available_to_admin=#{false_value}
25
+ WHERE id=#{id};
26
+ SQL
27
+ )
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :solidus do
4
+ desc 'Prints orders with invalid email (after fix for GHSA-qxmr-qxh6-2cc9)'
5
+ task check_orders_with_invalid_email: :environment do
6
+ matches = Spree::Order.find_each.reduce([]) do |matches, order|
7
+ order.email.nil? || Spree::EmailValidator::EMAIL_REGEXP.match?(order.email) ? matches : matches + [order]
8
+ end
9
+ if matches.any?
10
+ puts 'Email / ID / Number'
11
+ puts(matches.map do |order|
12
+ "#{order.email} / #{order.id} / #{order.number}"
13
+ end.join("\n"))
14
+ else
15
+ puts 'NO MATCHES'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :solidus do
4
+ desc "Delete Spree::Price records (including discarded) which amount field is NULL"
5
+ task delete_prices_with_nil_amount: :environment do
6
+ Spree::Price.with_discarded.where(amount: nil).delete_all
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :solidus do
4
+ desc "Split Promotions with 'any' match policy"
5
+ task split_promotions_with_any_match_policy: :environment do
6
+ Spree::Promotion.where(match_policy: :any).includes(:promotion_rules).all.each do |promotion|
7
+ if promotion.promotion_rules.length <= 1
8
+ promotion.update!(match_policy: :all)
9
+ elsif promotion.active?
10
+ promotion.rules.map do |rule|
11
+ new_promotion = promotion.dup
12
+ new_promotion.promotion_rules = [rule]
13
+ new_promotion.match_policy = "all"
14
+ new_promotion.promotion_actions = promotion.actions.map do |action|
15
+ new_action = action.dup
16
+ if action.respond_to?(:calculator)
17
+ new_action.calculator = action.calculator.dup
18
+ end
19
+ new_action.promotion = new_promotion
20
+ new_action.save!
21
+ new_action
22
+ end
23
+ new_promotion.expires_at = promotion.expires_at
24
+ new_promotion.starts_at = Time.current
25
+ new_promotion.save!
26
+ end
27
+ promotion.update!(expires_at: Time.current)
28
+ end
29
+ end
30
+
31
+ Spree::Order.where(completed_at: nil).each { |order| Spree::PromotionHandler::Cart.new(order).activate }
32
+ end
33
+ end