solidus_core 3.2.7 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/controllers/spree/base_controller.rb +1 -1
  4. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +4 -0
  5. data/app/models/concerns/spree/default_price.rb +0 -6
  6. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  7. data/app/models/concerns/spree/user_methods.rb +2 -2
  8. data/app/models/spree/address.rb +1 -1
  9. data/app/models/spree/calculator/flat_fee.rb +21 -0
  10. data/app/models/spree/country.rb +1 -1
  11. data/app/models/spree/credit_card.rb +1 -1
  12. data/app/models/spree/customer_return.rb +1 -1
  13. data/app/models/spree/line_item.rb +2 -2
  14. data/app/models/spree/option_type.rb +1 -1
  15. data/app/models/spree/option_value.rb +1 -1
  16. data/app/models/spree/order/number_generator.rb +7 -1
  17. data/app/models/spree/order.rb +4 -3
  18. data/app/models/spree/order_promotion.rb +1 -1
  19. data/app/models/spree/order_updater.rb +11 -2
  20. data/app/models/spree/payment/processing.rb +58 -55
  21. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  22. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  23. data/app/models/spree/payment_method.rb +16 -10
  24. data/app/models/spree/price.rb +1 -1
  25. data/app/models/spree/product.rb +3 -4
  26. data/app/models/spree/product_property.rb +1 -1
  27. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  28. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  29. data/app/models/spree/promotion.rb +2 -2
  30. data/app/models/spree/promotion_code.rb +1 -1
  31. data/app/models/spree/property.rb +1 -1
  32. data/app/models/spree/return_authorization.rb +1 -1
  33. data/app/models/spree/shipment.rb +2 -2
  34. data/app/models/spree/state.rb +1 -1
  35. data/app/models/spree/stock_item.rb +1 -1
  36. data/app/models/spree/stock_location.rb +1 -1
  37. data/app/models/spree/stock_movement.rb +2 -2
  38. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  39. data/app/models/spree/tax/tax_helpers.rb +2 -2
  40. data/app/models/spree/tax_calculator/default.rb +31 -0
  41. data/app/models/spree/tax_rate.rb +8 -1
  42. data/app/models/spree/taxon.rb +1 -1
  43. data/app/models/spree/taxonomy.rb +1 -1
  44. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  45. data/app/models/spree/variant.rb +25 -5
  46. data/app/models/spree/zone.rb +1 -1
  47. data/config/locales/en.yml +13 -2
  48. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  49. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  50. data/db/seeds.rb +4 -1
  51. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  52. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  53. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  54. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  55. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  56. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  57. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  58. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  59. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +11 -9
  60. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +8 -9
  61. data/lib/generators/solidus/install/install_generator.rb +213 -190
  62. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -4
  63. data/lib/generators/solidus/update/update_generator.rb +2 -14
  64. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  65. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  66. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  67. data/lib/generators/spree/dummy/dummy_generator.rb +10 -8
  68. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -12
  69. data/lib/spree/app_configuration.rb +23 -0
  70. data/lib/spree/bus.rb +3 -3
  71. data/lib/spree/core/controller_helpers/current_host.rb +5 -1
  72. data/lib/spree/core/product_duplicator.rb +1 -1
  73. data/lib/spree/core/search/base.rb +17 -8
  74. data/lib/spree/core/version.rb +2 -2
  75. data/lib/spree/core.rb +1 -20
  76. data/lib/spree/migrations.rb +12 -10
  77. data/lib/spree/permitted_attributes.rb +4 -1
  78. data/lib/spree/rails_compatibility.rb +0 -17
  79. data/lib/spree/testing_support/common_rake.rb +7 -6
  80. data/lib/spree/testing_support/dummy_app.rb +5 -5
  81. data/lib/spree/testing_support/factories/address_factory.rb +9 -11
  82. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  83. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  84. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  85. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  86. data/lib/spree/testing_support/factory_bot.rb +1 -1
  87. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  88. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  89. data/solidus_core.gemspec +2 -2
  90. metadata +34 -23
  91. data/lib/generators/solidus/install/install_generator/bundler_context.rb +0 -105
  92. data/lib/generators/solidus/install/install_generator/install_frontend.rb +0 -61
  93. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +0 -48
@@ -96,13 +96,15 @@ module Spree
96
96
  protected
97
97
 
98
98
  def inject_require_for(requirement)
99
- inject_into_file 'config/application.rb', %[
100
- begin
101
- require '#{requirement}'
102
- rescue LoadError
103
- # #{requirement} is not available.
104
- end
105
- ], before: /require '#{@lib_name}'/, verbose: true
99
+ inject_into_file 'config/application.rb', (
100
+ <<~RUBY
101
+ begin
102
+ require '#{requirement}'
103
+ rescue LoadError
104
+ # #{requirement} is not available.
105
+ end
106
+ RUBY
107
+ ), before: /require '#{@lib_name}'/, verbose: true
106
108
  end
107
109
 
108
110
  def dummy_path
@@ -118,7 +120,7 @@ end
118
120
  dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
119
121
  unless options[:pretend] || !File.exist?(dummy_application_path)
120
122
  contents = File.read(dummy_application_path)
121
- contents[(contents.index("module #{module_name}"))..-1]
123
+ contents[(contents.index("module #{module_name}"))..]
122
124
  end
123
125
  end
124
126
  end
@@ -1,6 +1,3 @@
1
- <% if agent_number = ENV['TC_AGENT_NUMBER']
2
- database_prefix = agent_number + '_'
3
- end %>
4
1
  <% db = case ENV['DB']
5
2
  when 'mysql'
6
3
  'mysql'
@@ -22,14 +19,11 @@ end %>
22
19
  <% db_username = ENV['DB_USERNAME'] %>
23
20
  <% db_password = ENV['DB_PASSWORD'] %>
24
21
 
25
-
26
-
27
-
28
22
  <% case ENV['DB']
29
23
  when 'mysql' %>
30
24
  development:
31
25
  adapter: mysql2
32
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
26
+ database: <%= options[:lib_name] %>_solidus_development
33
27
  <% unless db_username.blank? %>
34
28
  username: <%= db_username %>
35
29
  <% end %>
@@ -42,7 +36,7 @@ development:
42
36
  encoding: utf8
43
37
  test:
44
38
  adapter: mysql2
45
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
39
+ database: <%= options[:lib_name] %>_solidus_test
46
40
  <% unless db_username.blank? %>
47
41
  username: <%= db_username %>
48
42
  <% end %>
@@ -55,7 +49,7 @@ test:
55
49
  encoding: utf8
56
50
  production:
57
51
  adapter: mysql2
58
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
52
+ database: <%= options[:lib_name] %>_solidus_production
59
53
  <% unless db_username.blank? %>
60
54
  username: <%= db_username %>
61
55
  <% end %>
@@ -69,7 +63,7 @@ production:
69
63
  <% when 'postgres', 'postgresql' %>
70
64
  development:
71
65
  adapter: postgresql
72
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
66
+ database: <%= options[:lib_name] %>_solidus_development
73
67
  <% unless db_username.blank? %>
74
68
  username: <%= db_username %>
75
69
  <% end %>
@@ -82,7 +76,7 @@ development:
82
76
  min_messages: warning
83
77
  test:
84
78
  adapter: postgresql
85
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
79
+ database: <%= options[:lib_name] %>_solidus_test
86
80
  <% unless db_username.blank? %>
87
81
  username: <%= db_username %>
88
82
  <% end %>
@@ -95,7 +89,7 @@ test:
95
89
  min_messages: warning
96
90
  production:
97
91
  adapter: postgresql
98
- database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
92
+ database: <%= options[:lib_name] %>_solidus_production
99
93
  <% unless db_username.blank? %>
100
94
  username: <%= db_username %>
101
95
  <% end %>
@@ -193,7 +193,17 @@ module Spree
193
193
 
194
194
  # @!attribute [rw] mails_from
195
195
  # @return [String] Email address used as +From:+ field in transactional emails.
196
+ # @deprecated Spree::Store#mail_from_address is used instead
196
197
  preference :mails_from, :string, default: 'solidus@example.com'
198
+ def mails_from=(value)
199
+ Spree::Deprecation.warn(<<~MSG) && preferences[:mail_from] = value
200
+ Solidus doesn't use `Spree::Config.mails_from` preference and it'll
201
+ removed on the next major release. Please, remove its definition in
202
+ `config/initializers/spree.rb`. Use the `Spree::Store#mail_from_address`
203
+ attribute for the default email address used as the 'From:' field in
204
+ transactional emails.
205
+ MSG
206
+ end
197
207
 
198
208
  # @!attribute [rw] max_level_in_taxons_menu
199
209
  # @return [Integer] maximum nesting level in taxons menu (default: +1+)
@@ -343,6 +353,9 @@ module Spree
343
353
  # promotion_chooser_class allows extensions to provide their own PromotionChooser
344
354
  class_name_attribute :promotion_chooser_class, default: 'Spree::PromotionChooser'
345
355
 
356
+ # promotion_adjuster_class allows extensions to provide their own Promotion Adjuster
357
+ class_name_attribute :promotion_adjuster_class, default: 'Spree::Promotion::OrderAdjustmentsRecalculator'
358
+
346
359
  class_name_attribute :allocator_class, default: 'Spree::Stock::Allocator::OnHandFirst'
347
360
 
348
361
  class_name_attribute :shipping_rate_sorter_class, default: 'Spree::Stock::ShippingRateSorter'
@@ -529,6 +542,15 @@ module Spree
529
542
  small: '400x400>',
530
543
  product: '680x680>',
531
544
  large: '1200x1200>' }
545
+
546
+ # Allows providing your own class for prioritizing store credit application
547
+ # to an order.
548
+ #
549
+ # @!attribute [rw] store_credit_prioritizer_class
550
+ # @return [Class] a class with the same public interfaces as
551
+ # Spree::StoreCreditPrioritizer.
552
+ class_name_attribute :store_credit_prioritizer_class, default: 'Spree::StoreCreditPrioritizer'
553
+
532
554
  # @!attribute [rw] taxon_image_style_default
533
555
  #
534
556
  # Defines which style to default to when style is not provided
@@ -642,6 +664,7 @@ module Spree
642
664
 
643
665
  env.calculators.tax_rates = %w[
644
666
  Spree::Calculator::DefaultTax
667
+ Spree::Calculator::FlatFee
645
668
  ]
646
669
 
647
670
  env.payment_methods = %w[
data/lib/spree/bus.rb CHANGED
@@ -9,12 +9,12 @@ module Spree
9
9
  # It has some modifications to support internal usage of the legacy event
10
10
  # system {see Spree::AppConfiguration#use_legacy_events}.
11
11
  Bus = Omnes::Bus.new
12
- def Bus.publish(event, **kwargs)
12
+ Bus.define_singleton_method(:publish) do |*args, **kwargs, &block|
13
13
  if Spree::Config.use_legacy_events
14
- Spree::Event.fire(event, **kwargs)
14
+ Spree::Event.fire(*args, **kwargs, &block)
15
15
  else
16
16
  # Override caller_location to point to the actual event publisher
17
- super(event, **kwargs, caller_location: caller_locations(1)[0])
17
+ super(*args, **kwargs, caller_location: caller_locations(1)[0], &block)
18
18
  end
19
19
  end
20
20
  end
@@ -7,7 +7,11 @@ module Spree
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- Spree::RailsCompatibility.active_storage_set_current(self)
10
+ Spree::Deprecation.warn <<~MSG
11
+ 'Spree::Core::ControllerHelpers::CurrentHost' is deprecated.
12
+ Please, include 'ActiveStorage::SetCurrent' instead.
13
+ MSG
14
+ include ActiveStorage::SetCurrent
11
15
  end
12
16
  end
13
17
  end
@@ -45,7 +45,7 @@ module Spree
45
45
  new_master.sku = "COPY OF #{master.sku}"
46
46
  new_master.deleted_at = nil
47
47
  new_master.images = master.images.map { |image| duplicate_image image } if @include_images
48
- new_master.prices = master.prices.map(&:dup)
48
+ new_master.price = master.price
49
49
  end
50
50
  end
51
51
 
@@ -4,6 +4,12 @@ module Spree
4
4
  module Core
5
5
  module Search
6
6
  class Base
7
+ class InvalidOptions < ArgumentError
8
+ def initialize(option)
9
+ super("Invalid option passed to the searcher: '#{option}'")
10
+ end
11
+ end
12
+
7
13
  attr_accessor :properties
8
14
  attr_accessor :current_user
9
15
  attr_accessor :pricing_options
@@ -57,16 +63,19 @@ module Spree
57
63
  end
58
64
 
59
65
  def add_search_scopes(base_scope)
60
- if @properties[:search]
61
- @properties[:search].each do |name, scope_attribute|
62
- scope_name = name.to_sym
63
- if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
64
- base_scope = base_scope.send(scope_name, *scope_attribute)
65
- else
66
- base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
67
- end
66
+ return base_scope unless @properties[:search].present?
67
+ raise InvalidOptions.new(:search) unless @properties[:search].respond_to?(:each_pair)
68
+
69
+ @properties[:search].each_pair do |name, scope_attribute|
70
+ scope_name = name.to_sym
71
+
72
+ if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
73
+ base_scope = base_scope.send(scope_name, *scope_attribute)
74
+ else
75
+ base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
68
76
  end
69
77
  end
78
+
70
79
  base_scope
71
80
  end
72
81
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "3.2.7"
4
+ VERSION = "3.3.0"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
8
8
  end
9
9
 
10
10
  def self.previous_solidus_minor_version
11
- '3.1'
11
+ '3.2'
12
12
  end
13
13
 
14
14
  def self.solidus_gem_version
data/lib/spree/core.rb CHANGED
@@ -27,7 +27,7 @@ require 'spree/rails_compatibility'
27
27
  StateMachines::Machine.ignore_method_conflicts = true
28
28
 
29
29
  module Spree
30
- mattr_accessor :user_class
30
+ mattr_accessor :user_class, default: 'Spree::LegacyUser'
31
31
 
32
32
  def self.user_class
33
33
  if @@user_class.is_a?(Class)
@@ -84,24 +84,6 @@ module Spree
84
84
  end
85
85
  end
86
86
 
87
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")
88
- Spree::Deprecation.warn <<~HEREDOC
89
- Ruby 2.5 & Ruby 2.6 (both EOL) are deprecated and will not be supported anymore from the next Solidus version.
90
- Please, upgrade to a more recent Ruby version.
91
- Read more on the release notes for different Ruby versions here:
92
- https://www.ruby-lang.org/en/downloads/releases/
93
- HEREDOC
94
- end
95
-
96
- if Gem::Version.new(Rails.version) < Gem::Version.new('6.0')
97
- Spree::Deprecation.warn <<~HEREDOC
98
- Rails 5.2 (EOL) is deprecated and will not be supported anymore from the next Solidus version.
99
- Please, upgrade to a more recent Rails version.
100
- Read more on upgrading from Rails 5.2 to Rails 6.0 here:
101
- https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-2-to-rails-6-0
102
- HEREDOC
103
- end
104
-
105
87
  require 'spree/core/version'
106
88
 
107
89
  require 'spree/core/active_merchant_dependencies'
@@ -126,7 +108,6 @@ require 'spree/core/permalinks'
126
108
  require 'spree/core/product_duplicator'
127
109
  require 'spree/core/controller_helpers/auth'
128
110
  require 'spree/core/controller_helpers/common'
129
- require 'spree/core/controller_helpers/current_host'
130
111
  require 'spree/core/controller_helpers/order'
131
112
  require 'spree/core/controller_helpers/payment_parameters'
132
113
  require 'spree/core/controller_helpers/pricing'
@@ -23,16 +23,18 @@ module Spree
23
23
  # Shouldn't run on test mode because migrations inside engine don't have
24
24
  # engine name on the file name
25
25
  def check
26
- if File.directory?(app_dir)
27
- unless missing_migrations.empty?
28
- puts "[#{engine_name.capitalize} WARNING] Missing migrations."
29
- missing_migrations.each do |migration|
30
- puts "[#{engine_name.capitalize} WARNING] #{migration} from #{engine_name} is missing."
31
- end
32
- puts "[#{engine_name.capitalize} WARNING] Run `bundle exec rake railties:install:migrations` to get them.\n\n"
33
- true
34
- end
35
- end
26
+ return unless File.directory?(app_dir)
27
+ return if missing_migrations.empty?
28
+ return if ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK']
29
+
30
+ prefix = "[WARNING #{engine_name.capitalize}]"
31
+ warn <<~WARN
32
+ #{prefix} Missing migrations.
33
+ #{missing_migrations.map {|m| "#{prefix} - #{m}"}.join("\n")}
34
+ #{prefix}
35
+ #{prefix} Run `bin/rails railties:install:migrations` to get them.
36
+ #{prefix} You can silence this warning by setting the `SOLIDUS_SKIP_MIGRATIONS_CHECK` environment variable.
37
+ WARN
36
38
  end
37
39
 
38
40
  def missing_migrations
@@ -132,7 +132,10 @@ module Spree
132
132
  :name, :presentation, :cost_price, :lock_version,
133
133
  :position, :track_inventory,
134
134
  :product_id, :product, :price,
135
- :weight, :height, :width, :depth, :sku, :cost_currency, :tax_category_id, option_value_ids: [], options: [:name, :value]
135
+ :weight, :height, :width, :depth, :sku, :cost_currency,
136
+ :tax_category_id, :shipping_category_id,
137
+ option_value_ids: [],
138
+ options: [:name, :value]
136
139
  ]
137
140
 
138
141
  @@checkout_address_attributes = [
@@ -72,23 +72,6 @@ module Spree
72
72
  end
73
73
  end
74
74
 
75
- # Set current host for ActiveStorage in a controller
76
- #
77
- # Changed from `#host` to including a module in Rails 6
78
- #
79
- # See https://github.com/rails/rails/commit/e33c3cd8ccbecaca6c6af0438956431b02cb3fb2
80
- #
81
- # TODO: Remove when deprecating Rails 5.2
82
- def self.active_storage_set_current(controller)
83
- if version_gte?('6')
84
- controller.include ActiveStorage::SetCurrent
85
- else
86
- controller.before_action do
87
- ActiveStorage::Current.host = request.base_url
88
- end
89
- end
90
- end
91
-
92
75
  # Set current host for ActiveStorage
93
76
  #
94
77
  # Changed from `#host` to `#url_options` on Rails 7
@@ -9,28 +9,29 @@ class CommonRakeTasks
9
9
  namespace :common do
10
10
  task :test_app, :user_class do |_t, args|
11
11
  args.with_defaults(user_class: "Spree::LegacyUser")
12
- require ENV['LIB_NAME']
12
+ lib_name = ENV['LIB_NAME'] or
13
+ raise "Please provide a library name via the LIB_NAME environment variable."
14
+
15
+ require lib_name
13
16
 
14
17
  force_rails_environment_to_test
15
18
 
16
19
  Spree::DummyGenerator.start [
17
- "--lib-name=#{ENV['LIB_NAME']}",
20
+ "--lib-name=#{lib_name}",
18
21
  "--quiet",
19
22
  ]
20
23
 
21
24
  # While the dummy app is generated the current directory
22
25
  # within ruby is changed to that of the dummy app.
23
26
  sh({
24
- 'SKIP_SOLIDUS_BOLT' => '1',
25
- 'FRONTEND' => 'solidus_frontend',
27
+ 'FRONTEND' => ENV['FRONTEND'] || 'classic',
26
28
  }, [
27
29
  'bin/rails',
28
30
  'generate',
29
31
  'solidus:install',
30
32
  Dir.pwd, # use the current dir as Rails.root
31
- "--lib-name=#{ENV['LIB_NAME']}",
32
33
  "--auto-accept",
33
- "--with-authentication=false",
34
+ "--authentication=none",
34
35
  "--payment-method=none",
35
36
  "--migrate=false",
36
37
  "--seed=false",
@@ -38,7 +38,7 @@ module DummyApp
38
38
  ENV["LIB_NAME"] = lib_name
39
39
  DummyApp::Application.config.root = File.join(gem_root, 'spec', 'dummy')
40
40
 
41
- DummyApp::Application.initialize!
41
+ DummyApp::Application.initialize! unless DummyApp::Application.initialized?
42
42
 
43
43
  if auto_migrate
44
44
  DummyApp::Migrations.auto_migrate
@@ -90,7 +90,7 @@ module DummyApp
90
90
  config.active_record.dump_schema_after_migration = false
91
91
 
92
92
  # Configure active storage to use storage within tmp folder
93
- unless (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
93
+ unless ENV['DISABLE_ACTIVE_STORAGE']
94
94
  initializer 'solidus.active_storage' do
95
95
  config.active_storage.service_configurations = {
96
96
  test: {
@@ -116,6 +116,7 @@ module DummyApp
116
116
  end
117
117
  config.paths['db/migrate'] = migration_dirs
118
118
  ActiveRecord::Migrator.migrations_paths = migration_dirs
119
+ ActiveRecord::Migration.verbose = false
119
120
 
120
121
  config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__)
121
122
  config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__)
@@ -137,10 +138,9 @@ end
137
138
  Spree.user_class = 'Spree::LegacyUser'
138
139
  Spree.load_defaults(Spree.solidus_version)
139
140
  Spree.config do |config|
140
- config.mails_from = "store@example.com"
141
- config.use_legacy_events = (ENV['USE_LEGACY_EVENTS'] == 'true')
141
+ config.use_legacy_events = ENV['USE_LEGACY_EVENTS'].present?
142
142
 
143
- if (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
143
+ if ENV['DISABLE_ACTIVE_STORAGE']
144
144
  config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
145
145
  config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
146
146
  end
@@ -24,21 +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(
30
- :state,
31
- strategy: :create,
32
- country_iso: country_iso_code,
33
- state_code: state_code
34
- )
35
- end
36
-
37
27
  country do |address|
38
28
  if address.state
39
29
  address.state.country
40
30
  else
41
- address.association(:country, strategy: :create, 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)
42
40
  end
43
41
  end
44
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
@@ -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
@@ -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
 
@@ -37,7 +37,7 @@ 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
 
@@ -34,7 +34,7 @@ module Spree
34
34
  states
35
35
  else
36
36
  end_state_position = states.index(state.to_sym)
37
- states[0..end_state_position]
37
+ states[..end_state_position]
38
38
  end
39
39
 
40
40
  states_to_process.each do |state_to_process|
@@ -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
data/solidus_core.gemspec CHANGED
@@ -20,14 +20,14 @@ Gem::Specification.new do |s|
20
20
  f.match(%r{^(spec|script)/})
21
21
  end
22
22
 
23
- s.required_ruby_version = '>= 2.5.0'
23
+ s.required_ruby_version = '>= 2.7.0'
24
24
  s.required_rubygems_version = '>= 1.8.23'
25
25
 
26
26
  %w[
27
27
  actionmailer actionpack actionview activejob activemodel activerecord
28
28
  activesupport railties
29
29
  ].each do |rails_dep|
30
- s.add_dependency rails_dep, ['>= 5.2', '< 7.1.x']
30
+ s.add_dependency rails_dep, ['>= 6.0', '< 7.1.x']
31
31
  end
32
32
 
33
33
  s.add_dependency 'activemerchant', '~> 1.66'