solidus_core 3.1.8 → 3.2.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/spree/products_helper.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +23 -10
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/user_address_book.rb +11 -1
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/option_value.rb +9 -0
- data/app/models/spree/order.rb +68 -29
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +4 -3
- data/app/models/spree/payment_method.rb +11 -0
- data/app/models/spree/price.rb +1 -1
- data/app/models/spree/product/scopes.rb +21 -3
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -0
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +4 -0
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +34 -23
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code.rb +8 -4
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/reimbursement.rb +2 -2
- data/app/models/spree/return_item.rb +1 -2
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +2 -1
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_rate.rb +2 -0
- data/app/models/spree/variant.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/locales/en.yml +7 -249
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/lib/generators/solidus/install/install_generator/bundler_context.rb +97 -0
- data/lib/generators/solidus/install/install_generator/install_frontend.rb +50 -0
- data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +48 -0
- data/lib/generators/solidus/install/install_generator.rb +56 -49
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +6 -16
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/spree/app_configuration.rb +29 -3
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/controller_helpers/auth.rb +9 -1
- data/lib/spree/core/controller_helpers/current_host.rb +1 -3
- data/lib/spree/core/controller_helpers/order.rb +10 -10
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/engine.rb +33 -8
- data/lib/spree/core/state_machines/order.rb +1 -1
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +3 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +20 -0
- data/lib/spree/event/subscriber_registry.rb +4 -6
- data/lib/spree/event.rb +1 -1
- data/lib/spree/migrations.rb +1 -1
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +4 -4
- data/lib/spree/preferences/configuration.rb +34 -12
- data/lib/spree/preferences/preferable_class_methods.rb +1 -1
- data/lib/spree/preferences/preference_differentiator.rb +2 -1
- data/lib/spree/preferences/static_model_preferences.rb +0 -2
- data/lib/spree/rails_compatibility.rb +99 -0
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/common_rake.rb +47 -19
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app.rb +6 -2
- data/lib/spree/testing_support/factories/address_factory.rb +7 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -4
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factory_bot.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +5 -4
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +2 -2
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +6 -2
- metadata +71 -26
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
# Supported Rails versions compatibility
|
|
5
|
+
#
|
|
6
|
+
# This module is meant to wrap some Rails API changes between supported
|
|
7
|
+
# versions. It's also meant to contain compatibility for features that we use
|
|
8
|
+
# internally in the Solidus code base.
|
|
9
|
+
module RailsCompatibility
|
|
10
|
+
# Method `#to_fs`
|
|
11
|
+
#
|
|
12
|
+
# Available since Rails 7.0, substitutes `#to_s(format)`
|
|
13
|
+
#
|
|
14
|
+
# It includes:
|
|
15
|
+
#
|
|
16
|
+
# ActiveSupport::NumericWithFormat
|
|
17
|
+
# ActiveSupport::RangeWithFormat
|
|
18
|
+
# ActiveSupport::TimeWithZone
|
|
19
|
+
# Array
|
|
20
|
+
# Date
|
|
21
|
+
# DateTime
|
|
22
|
+
# Time
|
|
23
|
+
#
|
|
24
|
+
# See https://github.com/rails/rails/pull/43772 &
|
|
25
|
+
# https://github.com/rails/rails/pull/44354
|
|
26
|
+
#
|
|
27
|
+
# TODO: Remove when deprecating Rails 6.1
|
|
28
|
+
def self.to_fs(value, *args, **kwargs, &block)
|
|
29
|
+
if version_gte?('7.0')
|
|
30
|
+
value.to_fs(*args, **kwargs, &block)
|
|
31
|
+
else
|
|
32
|
+
value.to_s(*args, **kwargs, &block)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# `raise_on_missing_translations` config option
|
|
37
|
+
#
|
|
38
|
+
# Changed from ActionView to I18n on Rails 6.1
|
|
39
|
+
#
|
|
40
|
+
# See https://github.com/rails/rails/pull/31571
|
|
41
|
+
#
|
|
42
|
+
# TODO: Remove when deprecating Rails 6.0
|
|
43
|
+
def self.raise_on_missing_translations(value)
|
|
44
|
+
if version_gte?('6.1')
|
|
45
|
+
Rails.application.config.i18n.raise_on_missing_translations = value
|
|
46
|
+
else
|
|
47
|
+
Rails.application.config.action_view.raise_on_missing_translations = value
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Set current host for ActiveStorage in a controller
|
|
52
|
+
#
|
|
53
|
+
# Changed from `#host` to including a module in Rails 6
|
|
54
|
+
#
|
|
55
|
+
# See https://github.com/rails/rails/commit/e33c3cd8ccbecaca6c6af0438956431b02cb3fb2
|
|
56
|
+
#
|
|
57
|
+
# TODO: Remove when deprecating Rails 5.2
|
|
58
|
+
def self.active_storage_set_current(controller)
|
|
59
|
+
if version_gte?('6')
|
|
60
|
+
controller.include ActiveStorage::SetCurrent
|
|
61
|
+
else
|
|
62
|
+
controller.before_action do
|
|
63
|
+
ActiveStorage::Current.host = request.base_url
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Set current host for ActiveStorage
|
|
69
|
+
#
|
|
70
|
+
# Changed from `#host` to `#url_options` on Rails 7
|
|
71
|
+
#
|
|
72
|
+
# See https://github.com/rails/rails/issues/41388
|
|
73
|
+
#
|
|
74
|
+
# TODO: Remove when deprecating Rails 6.1
|
|
75
|
+
def self.active_storage_url_options_host(value)
|
|
76
|
+
if version_gte?('7')
|
|
77
|
+
ActiveStorage::Current.url_options = { host: value }
|
|
78
|
+
else
|
|
79
|
+
ActiveStorage::Current.host = value
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Default ActiveStorage variant processor
|
|
84
|
+
#
|
|
85
|
+
# Changed from `:mini_magick` to `vips` on Rails 7
|
|
86
|
+
#
|
|
87
|
+
# See https://github.com/rails/rails/issues/42744
|
|
88
|
+
#
|
|
89
|
+
# TODO: Remove when deprecating Rails 6.1
|
|
90
|
+
def self.variant_processor
|
|
91
|
+
version_gte?('7') ? :vips : :mini_magick
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.version_gte?(version)
|
|
95
|
+
::Rails.gem_version >= Gem::Version.new(version)
|
|
96
|
+
end
|
|
97
|
+
private_class_method :version_gte?
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spree/bus'
|
|
4
|
+
|
|
5
|
+
module Spree
|
|
6
|
+
module TestingSupport
|
|
7
|
+
# RSpec test helpers for the event bus
|
|
8
|
+
#
|
|
9
|
+
# If you want to use the methods defined in this module, include it in your
|
|
10
|
+
# specs:
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# require 'rails_helper'
|
|
14
|
+
# require 'spree/testing_support/bus_helpers'
|
|
15
|
+
#
|
|
16
|
+
# RSpec.describe MyClass do
|
|
17
|
+
# include Spree::TestingSupport::BusHelpers
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# or, globally, in your `spec_helper.rb`:
|
|
21
|
+
#
|
|
22
|
+
# @example
|
|
23
|
+
# require 'spree/testing_support/bus_helpers'
|
|
24
|
+
#
|
|
25
|
+
# RSpec.configure do |config|
|
|
26
|
+
# config.include Spree::TestingSupport::BusHelpers
|
|
27
|
+
# end
|
|
28
|
+
module BusHelpers
|
|
29
|
+
extend RSpec::Matchers::DSL
|
|
30
|
+
|
|
31
|
+
# Stubs {Spree::Bus}
|
|
32
|
+
#
|
|
33
|
+
# After you have called this method in an example, {Spree::Bus} will no
|
|
34
|
+
# longer publish any event for the duration of that example. All the
|
|
35
|
+
# method invocations on it will be stubbed.
|
|
36
|
+
#
|
|
37
|
+
# Internally, it stubs {Spree::Bus#publish}.
|
|
38
|
+
#
|
|
39
|
+
# After you call this method, probably you'll want to call some of the
|
|
40
|
+
# matchers defined in this module.
|
|
41
|
+
def stub_spree_bus
|
|
42
|
+
allow(Spree::Bus).to receive(:publish)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @!method have_been_published(event_name)
|
|
46
|
+
# Matcher to test that an event has been published via {Spree::Bus#publish}
|
|
47
|
+
#
|
|
48
|
+
# Before using this matcher, you need to call {#stub_spree_bus}.
|
|
49
|
+
#
|
|
50
|
+
# Remember that the event listeners won't be performed.
|
|
51
|
+
#
|
|
52
|
+
# @example
|
|
53
|
+
# it 'publishes foo event' do
|
|
54
|
+
# stub_spree_bus
|
|
55
|
+
#
|
|
56
|
+
# Spree::Bus.publish 'foo'
|
|
57
|
+
#
|
|
58
|
+
# expect('foo').to have_been_published
|
|
59
|
+
# end
|
|
60
|
+
#
|
|
61
|
+
# It can be chain through `with` to match with the published payload:
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# it 'publishes foo event with the expected payload' do
|
|
65
|
+
# stub_spree_bus
|
|
66
|
+
#
|
|
67
|
+
# Spree::Bus.publish 'foo', bar: :baz, qux: :quux
|
|
68
|
+
#
|
|
69
|
+
# expect('foo').to have_been_published.with(a_hash_including(bar: :baz))
|
|
70
|
+
# end
|
|
71
|
+
#
|
|
72
|
+
# @param [Symbol] event_name
|
|
73
|
+
matcher :have_been_published do
|
|
74
|
+
chain :with, :payload
|
|
75
|
+
|
|
76
|
+
match do |expected_event|
|
|
77
|
+
expected_event = normalize_name(expected_event)
|
|
78
|
+
arguments = payload ? [expected_event, payload] : [expected_event, any_args]
|
|
79
|
+
expect(Spree::Bus).to have_received(:publish).with(*arguments)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
failure_message do |expected_event|
|
|
83
|
+
<<~MSG
|
|
84
|
+
expected #{expected_event.inspect} to have been published.
|
|
85
|
+
Make sure that provided payload, if any, also matches.
|
|
86
|
+
MSG
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def normalize_name(event_name)
|
|
90
|
+
if event_name.is_a?(Symbol)
|
|
91
|
+
eq(event_name)
|
|
92
|
+
else
|
|
93
|
+
raise ArgumentError, <<~MSG
|
|
94
|
+
"#{event_name.inspect} is not a valid event name. It must be a Symbol."
|
|
95
|
+
MSG
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -6,33 +6,61 @@ end
|
|
|
6
6
|
|
|
7
7
|
require 'generators/spree/dummy/dummy_generator'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
args.with_defaults(user_class: "Spree::LegacyUser")
|
|
12
|
-
require ENV['LIB_NAME']
|
|
9
|
+
class CommonRakeTasks
|
|
10
|
+
include Rake::DSL
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
def initialize
|
|
13
|
+
namespace :common do
|
|
14
|
+
task :test_app, :user_class do |_t, args|
|
|
15
|
+
args.with_defaults(user_class: "Spree::LegacyUser")
|
|
16
|
+
require ENV['LIB_NAME']
|
|
17
|
+
|
|
18
|
+
force_rails_environment_to_test
|
|
19
|
+
|
|
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]}"]
|
|
22
|
+
|
|
23
|
+
puts "Setting up dummy database..."
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
sh "bin/rails db:environment:set RAILS_ENV=test"
|
|
26
|
+
sh "bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test"
|
|
18
27
|
|
|
19
|
-
|
|
28
|
+
if extension_installation_generator_exists?
|
|
29
|
+
puts 'Running extension installation generator...'
|
|
30
|
+
sh "bin/rails generate #{rake_generator_namespace}:install --auto-run-migrations"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
task :seed do |_t, _args|
|
|
35
|
+
puts "Seeding ..."
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
puts 'Running extension installation generator...'
|
|
27
|
-
"#{ENV['LIB_NAMESPACE'] || ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
|
|
28
|
-
rescue LoadError
|
|
29
|
-
# No extension generator to run
|
|
37
|
+
sh "bundle exec rake db:seed RAILS_ENV=test"
|
|
38
|
+
end
|
|
30
39
|
end
|
|
31
40
|
end
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
puts "Seeding ..."
|
|
42
|
+
private
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
def force_rails_environment_to_test
|
|
45
|
+
ENV["RAILS_ENV"] = 'test'
|
|
46
|
+
Rails.env = 'test'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def extension_installation_generator_exists?
|
|
50
|
+
require "generators/#{generator_namespace}/install/install_generator"
|
|
51
|
+
|
|
52
|
+
true
|
|
53
|
+
rescue LoadError
|
|
54
|
+
false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def generator_namespace
|
|
58
|
+
"#{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def rake_generator_namespace
|
|
62
|
+
generator_namespace.gsub("/", ":")
|
|
37
63
|
end
|
|
38
64
|
end
|
|
65
|
+
|
|
66
|
+
CommonRakeTasks.new
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
-
// Add new JavaScript
|
|
2
|
+
// Add new JavaScript code in separate files in this directory and they'll automatically
|
|
3
3
|
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
4
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
5
|
// the compiled file.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
-
// Add new JavaScript
|
|
2
|
+
// Add new JavaScript code in separate files in this directory and they'll automatically
|
|
3
3
|
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
4
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
5
|
// the compiled file.
|
|
@@ -48,7 +48,6 @@ module DummyApp
|
|
|
48
48
|
class Application < ::Rails::Application
|
|
49
49
|
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
|
|
50
50
|
# Make the test environment more production-like:
|
|
51
|
-
config.cache_classes = true
|
|
52
51
|
config.action_controller.allow_forgery_protection = false
|
|
53
52
|
config.action_controller.default_protect_from_forgery = false
|
|
54
53
|
config.action_mailer.perform_caching = false
|
|
@@ -60,6 +59,10 @@ module DummyApp
|
|
|
60
59
|
# https://github.com/solidusio/solidus/issues/4110
|
|
61
60
|
config.action_controller.perform_caching = false
|
|
62
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
|
+
|
|
63
66
|
# Make debugging easier:
|
|
64
67
|
config.consider_all_requests_local = true
|
|
65
68
|
config.action_dispatch.show_exceptions = false
|
|
@@ -96,7 +99,7 @@ module DummyApp
|
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
config.active_storage.service = :test
|
|
99
|
-
config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR',
|
|
102
|
+
config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', Spree::RailsCompatibility.variant_processor).to_sym
|
|
100
103
|
end
|
|
101
104
|
end
|
|
102
105
|
|
|
@@ -135,6 +138,7 @@ Spree.user_class = 'Spree::LegacyUser'
|
|
|
135
138
|
Spree.load_defaults(Spree.solidus_version)
|
|
136
139
|
Spree.config do |config|
|
|
137
140
|
config.mails_from = "store@example.com"
|
|
141
|
+
config.use_legacy_events = ENV['USE_LEGACY_EVENTS'].present?
|
|
138
142
|
|
|
139
143
|
if ENV['DISABLE_ACTIVE_STORAGE']
|
|
140
144
|
config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
|
|
@@ -26,14 +26,19 @@ FactoryBot.define do
|
|
|
26
26
|
|
|
27
27
|
state do |address|
|
|
28
28
|
Spree::State.joins(:country).where('spree_countries.iso = (?)', country_iso_code).find_by(abbr: state_code) ||
|
|
29
|
-
address.association(
|
|
29
|
+
address.association(
|
|
30
|
+
:state,
|
|
31
|
+
strategy: :create,
|
|
32
|
+
country_iso: country_iso_code,
|
|
33
|
+
state_code: state_code
|
|
34
|
+
)
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
country do |address|
|
|
33
38
|
if address.state
|
|
34
39
|
address.state.country
|
|
35
40
|
else
|
|
36
|
-
address.association(:country, iso: country_iso_code)
|
|
41
|
+
address.association(:country, strategy: :create, iso: country_iso_code)
|
|
37
42
|
end
|
|
38
43
|
end
|
|
39
44
|
end
|
|
@@ -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) }
|
|
@@ -68,6 +68,7 @@ FactoryBot.define do
|
|
|
68
68
|
|
|
69
69
|
factory :completed_order_with_promotion do
|
|
70
70
|
transient do
|
|
71
|
+
completed_at { Time.current }
|
|
71
72
|
promotion { nil }
|
|
72
73
|
end
|
|
73
74
|
|
|
@@ -79,7 +80,7 @@ FactoryBot.define do
|
|
|
79
80
|
order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
|
|
80
81
|
|
|
81
82
|
# Complete the order after the promotion has been activated
|
|
82
|
-
order.update_column(:completed_at,
|
|
83
|
+
order.update_column(:completed_at, evaluator.completed_at)
|
|
83
84
|
order.update_column(:state, "complete")
|
|
84
85
|
end
|
|
85
86
|
end
|
|
@@ -104,13 +105,16 @@ FactoryBot.define do
|
|
|
104
105
|
end
|
|
105
106
|
|
|
106
107
|
factory :completed_order_with_totals do
|
|
108
|
+
transient do
|
|
109
|
+
completed_at { Time.current }
|
|
110
|
+
end
|
|
107
111
|
state { 'complete' }
|
|
108
112
|
|
|
109
|
-
after(:create) do |order|
|
|
113
|
+
after(:create) do |order, evaluator|
|
|
110
114
|
order.shipments.each do |shipment|
|
|
111
115
|
shipment.inventory_units.update_all state: 'on_hand', pending: false
|
|
112
116
|
end
|
|
113
|
-
order.update_column(:completed_at,
|
|
117
|
+
order.update_column(:completed_at, evaluator.completed_at)
|
|
114
118
|
end
|
|
115
119
|
|
|
116
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
|
|
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 }
|
|
@@ -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
|
|
@@ -44,7 +44,7 @@ module Spree
|
|
|
44
44
|
def self.check_version
|
|
45
45
|
require "factory_bot/version"
|
|
46
46
|
|
|
47
|
-
requirement = Gem::Requirement.new("
|
|
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
|
)
|
|
@@ -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'
|
|
@@ -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
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
namespace :solidus do
|
|
4
|
-
desc "Delete Spree::Price records which amount field is NULL"
|
|
4
|
+
desc "Delete Spree::Price records (including discarded) which amount field is NULL"
|
|
5
5
|
task delete_prices_with_nil_amount: :environment do
|
|
6
|
-
Spree::Price.where(amount: nil).delete_all
|
|
6
|
+
Spree::Price.with_discarded.where(amount: nil).delete_all
|
|
7
7
|
end
|
|
8
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
|
data/solidus_core.gemspec
CHANGED
|
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.homepage = 'http://solidus.io'
|
|
15
15
|
s.license = 'BSD-3-Clause'
|
|
16
16
|
|
|
17
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
18
|
+
|
|
17
19
|
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
20
|
f.match(%r{^(spec|script)/})
|
|
19
21
|
end
|
|
@@ -25,7 +27,7 @@ Gem::Specification.new do |s|
|
|
|
25
27
|
actionmailer actionpack actionview activejob activemodel activerecord
|
|
26
28
|
activesupport railties
|
|
27
29
|
].each do |rails_dep|
|
|
28
|
-
s.add_dependency rails_dep, ['>= 5.2', '<
|
|
30
|
+
s.add_dependency rails_dep, ['>= 5.2', '< 7.1.x']
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
s.add_dependency 'activemerchant', '~> 1.66'
|
|
@@ -39,10 +41,12 @@ Gem::Specification.new do |s|
|
|
|
39
41
|
s.add_dependency 'kaminari-activerecord', '~> 1.1'
|
|
40
42
|
s.add_dependency 'mini_magick', '~> 4.10'
|
|
41
43
|
s.add_dependency 'monetize', '~> 1.8'
|
|
42
|
-
s.add_dependency 'kt-paperclip', '
|
|
44
|
+
s.add_dependency 'kt-paperclip', ['>= 6.3', '< 8']
|
|
43
45
|
s.add_dependency 'psych', ['>= 3.1.0', '< 5.0']
|
|
44
46
|
s.add_dependency 'ransack', '~> 2.0'
|
|
47
|
+
s.add_dependency 'sprockets-rails'
|
|
45
48
|
s.add_dependency 'state_machines-activerecord', '~> 0.6'
|
|
49
|
+
s.add_dependency 'omnes', '~> 0.2.2'
|
|
46
50
|
|
|
47
51
|
s.post_install_message = <<-MSG
|
|
48
52
|
-------------------------------------------------------------
|