solidus_core 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) 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/ransackable_attributes.rb +24 -4
  6. data/app/models/concerns/spree/user_methods.rb +2 -2
  7. data/app/models/spree/address.rb +1 -1
  8. data/app/models/spree/calculator/flat_fee.rb +21 -0
  9. data/app/models/spree/country.rb +1 -1
  10. data/app/models/spree/credit_card.rb +1 -1
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/line_item.rb +2 -2
  13. data/app/models/spree/option_type.rb +1 -1
  14. data/app/models/spree/option_value.rb +1 -1
  15. data/app/models/spree/order/number_generator.rb +7 -1
  16. data/app/models/spree/order.rb +4 -3
  17. data/app/models/spree/order_promotion.rb +1 -1
  18. data/app/models/spree/order_updater.rb +11 -2
  19. data/app/models/spree/payment/processing.rb +58 -55
  20. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  21. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  22. data/app/models/spree/payment_method.rb +16 -10
  23. data/app/models/spree/price.rb +1 -1
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product_property.rb +1 -1
  26. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  27. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  28. data/app/models/spree/promotion.rb +2 -2
  29. data/app/models/spree/promotion_code.rb +1 -1
  30. data/app/models/spree/property.rb +1 -1
  31. data/app/models/spree/return_authorization.rb +1 -1
  32. data/app/models/spree/shipment.rb +2 -2
  33. data/app/models/spree/state.rb +1 -1
  34. data/app/models/spree/stock_item.rb +1 -1
  35. data/app/models/spree/stock_location.rb +1 -1
  36. data/app/models/spree/stock_movement.rb +2 -2
  37. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  38. data/app/models/spree/tax/tax_helpers.rb +2 -2
  39. data/app/models/spree/tax_calculator/default.rb +31 -0
  40. data/app/models/spree/tax_rate.rb +8 -1
  41. data/app/models/spree/taxon.rb +1 -1
  42. data/app/models/spree/taxonomy.rb +1 -1
  43. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  44. data/app/models/spree/variant.rb +25 -5
  45. data/app/models/spree/zone.rb +1 -1
  46. data/config/locales/en.yml +17 -2
  47. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  48. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  49. data/db/seeds.rb +4 -1
  50. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  51. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  52. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  53. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  54. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  55. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  56. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  57. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  58. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
  59. data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
  60. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
  61. data/lib/generators/solidus/install/install_generator.rb +233 -187
  62. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -4
  63. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  64. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  65. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  66. data/lib/generators/spree/dummy/dummy_generator.rb +10 -8
  67. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -12
  68. data/lib/spree/app_configuration.rb +23 -0
  69. data/lib/spree/core/controller_helpers/current_host.rb +5 -1
  70. data/lib/spree/core/engine.rb +1 -0
  71. data/lib/spree/core/search/base.rb +17 -8
  72. data/lib/spree/core/version.rb +2 -2
  73. data/lib/spree/core.rb +1 -21
  74. data/lib/spree/migrations.rb +12 -10
  75. data/lib/spree/permitted_attributes.rb +4 -1
  76. data/lib/spree/preferences/preferable.rb +5 -0
  77. data/lib/spree/preferences/preferable_class_methods.rb +2 -2
  78. data/lib/spree/preferences/static_model_preferences.rb +25 -8
  79. data/lib/spree/rails_compatibility.rb +0 -17
  80. data/lib/spree/testing_support/common_rake.rb +27 -7
  81. data/lib/spree/testing_support/dummy_app.rb +2 -2
  82. data/lib/spree/testing_support/factories/address_factory.rb +9 -11
  83. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  84. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  85. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  86. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  87. data/lib/spree/testing_support/factory_bot.rb +1 -1
  88. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  89. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  90. data/solidus_core.gemspec +2 -2
  91. metadata +37 -23
  92. data/lib/generators/solidus/install/install_generator/bundler_context.rb +0 -97
  93. data/lib/generators/solidus/install/install_generator/install_frontend.rb +0 -59
  94. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +0 -48
@@ -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[
@@ -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
@@ -87,6 +87,7 @@ module Spree
87
87
 
88
88
  config.after_initialize do
89
89
  Spree::Config.check_load_defaults_called('Spree::Config')
90
+ Spree::Config.static_model_preferences.validate!
90
91
  end
91
92
 
92
93
  config.after_initialize do
@@ -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.4"
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
@@ -14,7 +14,6 @@ require 'awesome_nested_set'
14
14
  require 'cancan'
15
15
  require 'friendly_id'
16
16
  require 'kaminari/activerecord'
17
- require 'mail'
18
17
  require 'monetize'
19
18
  require 'paperclip'
20
19
  require 'ransack'
@@ -28,7 +27,7 @@ require 'spree/rails_compatibility'
28
27
  StateMachines::Machine.ignore_method_conflicts = true
29
28
 
30
29
  module Spree
31
- mattr_accessor :user_class
30
+ mattr_accessor :user_class, default: 'Spree::LegacyUser'
32
31
 
33
32
  def self.user_class
34
33
  if @@user_class.is_a?(Class)
@@ -85,24 +84,6 @@ module Spree
85
84
  end
86
85
  end
87
86
 
88
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")
89
- Spree::Deprecation.warn <<~HEREDOC
90
- Ruby 2.5 & Ruby 2.6 (both EOL) are deprecated and will not be supported anymore from the next Solidus version.
91
- Please, upgrade to a more recent Ruby version.
92
- Read more on the release notes for different Ruby versions here:
93
- https://www.ruby-lang.org/en/downloads/releases/
94
- HEREDOC
95
- end
96
-
97
- if Gem::Version.new(Rails.version) < Gem::Version.new('6.0')
98
- Spree::Deprecation.warn <<~HEREDOC
99
- Rails 5.2 (EOL) is deprecated and will not be supported anymore from the next Solidus version.
100
- Please, upgrade to a more recent Rails version.
101
- Read more on upgrading from Rails 5.2 to Rails 6.0 here:
102
- https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-2-to-rails-6-0
103
- HEREDOC
104
- end
105
-
106
87
  require 'spree/core/version'
107
88
 
108
89
  require 'spree/core/active_merchant_dependencies'
@@ -127,7 +108,6 @@ require 'spree/core/permalinks'
127
108
  require 'spree/core/product_duplicator'
128
109
  require 'spree/core/controller_helpers/auth'
129
110
  require 'spree/core/controller_helpers/common'
130
- require 'spree/core/controller_helpers/current_host'
131
111
  require 'spree/core/controller_helpers/order'
132
112
  require 'spree/core/controller_helpers/payment_parameters'
133
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 = [
@@ -10,6 +10,9 @@ module Spree
10
10
  #
11
11
  # A class including Preferable must implement #preferences which should return
12
12
  # an object responding to .fetch(key), []=(key, val), and .delete(key).
13
+ # If #preferences is initialized with `default_preferences` and one of the
14
+ # preferences is another preference, it will cause a stack level too deep error.
15
+ # To avoid it do not memoize #preferences.
13
16
  #
14
17
  # It may also define a `#context_for_default` method. It should return an
15
18
  # array with the arguments to be provided to a proc used as the `default:`
@@ -111,6 +114,8 @@ module Spree
111
114
  end
112
115
 
113
116
  # @return [Hash{Symbol => Object}] Default for all preferences defined on this class
117
+ # This may raise an infinite loop error if any of the defaults are
118
+ # dependent on other preferences defaults.
114
119
  def default_preferences
115
120
  Hash[
116
121
  defined_preferences.map do |preference|
@@ -75,7 +75,7 @@ module Spree::Preferences
75
75
  # is a pending preference before going to default
76
76
  define_method preference_getter_method(name) do
77
77
  value = preferences.fetch(name) do
78
- default.call(*context_for_default)
78
+ instance_exec(*context_for_default, &default)
79
79
  end
80
80
  value = preference_encryptor.decrypt(value) if preference_encryptor.present?
81
81
  value
@@ -92,7 +92,7 @@ module Spree::Preferences
92
92
  end
93
93
 
94
94
  define_method preference_default_getter_method(name) do
95
- default.call(*context_for_default)
95
+ instance_exec(*context_for_default, &default)
96
96
  end
97
97
 
98
98
  define_method preference_type_getter_method(name) do
@@ -7,13 +7,8 @@ module Spree
7
7
  attr_reader :preferences
8
8
 
9
9
  def initialize(klass, hash)
10
- hash = hash.symbolize_keys
11
- hash.keys.each do |key|
12
- if !klass.defined_preferences.include?(key)
13
- raise "Preference #{key.inspect} is not defined on #{klass}"
14
- end
15
- end
16
- @preferences = hash
10
+ @klass = klass
11
+ @preferences = hash.symbolize_keys
17
12
  end
18
13
 
19
14
  def fetch(key, &block)
@@ -27,6 +22,8 @@ module Spree
27
22
  def to_hash
28
23
  @preferences.deep_dup
29
24
  end
25
+
26
+ delegate :keys, to: :@preferences
30
27
  end
31
28
 
32
29
  def initialize
@@ -36,12 +33,32 @@ module Spree
36
33
  end
37
34
 
38
35
  def add(klass, name, preferences)
39
- @store[klass.to_s][name] = Definition.new(klass, preferences)
36
+ @store[klass.to_s][name] = Definition.new(klass.to_s, preferences)
40
37
  end
41
38
 
42
39
  def for_class(klass)
43
40
  @store[klass.to_s]
44
41
  end
42
+
43
+ def validate!
44
+ @store.keys.map(&:constantize).each do |klass|
45
+ validate_for_class!(klass)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def validate_for_class!(klass)
52
+ for_class(klass).each do |name, preferences|
53
+ klass_keys = klass.defined_preferences.map(&:to_s)
54
+ extra_keys = preferences.keys.map(&:to_s) - klass_keys
55
+ next if extra_keys.empty?
56
+
57
+ raise \
58
+ "Unexpected keys found for #{klass} under #{name}: #{extra_keys.sort.join(', ')} " \
59
+ "(expected keys: #{klass_keys.sort.join(', ')})"
60
+ end
61
+ end
45
62
  end
46
63
  end
47
64
  end
@@ -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
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- unless defined?(Solidus::InstallGenerator)
4
- require 'generators/solidus/install/install_generator'
5
- end
6
-
7
3
  require 'generators/spree/dummy/dummy_generator'
8
4
 
9
5
  class CommonRakeTasks
@@ -13,12 +9,36 @@ class CommonRakeTasks
13
9
  namespace :common do
14
10
  task :test_app, :user_class do |_t, args|
15
11
  args.with_defaults(user_class: "Spree::LegacyUser")
16
- 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
17
16
 
18
17
  force_rails_environment_to_test
19
18
 
20
- Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"]
21
- Solidus::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--with-authentication=false", "--payment-method=none", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]
19
+ Spree::DummyGenerator.start [
20
+ "--lib-name=#{lib_name}",
21
+ "--quiet",
22
+ ]
23
+
24
+ # While the dummy app is generated the current directory
25
+ # within ruby is changed to that of the dummy app.
26
+ sh({
27
+ 'FRONTEND' => ENV['FRONTEND'] || 'classic',
28
+ }, [
29
+ 'bin/rails',
30
+ 'generate',
31
+ 'solidus:install',
32
+ Dir.pwd, # use the current dir as Rails.root
33
+ "--auto-accept",
34
+ "--authentication=none",
35
+ "--payment-method=none",
36
+ "--migrate=false",
37
+ "--seed=false",
38
+ "--sample=false",
39
+ "--user-class=#{args[:user_class]}",
40
+ "--quiet",
41
+ ].shelljoin)
22
42
 
23
43
  puts "Setting up dummy database..."
24
44
 
@@ -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
@@ -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,7 +138,6 @@ 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
141
  config.use_legacy_events = ENV['USE_LEGACY_EVENTS'].present?
142
142
 
143
143
  if ENV['DISABLE_ACTIVE_STORAGE']
@@ -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|