solidus_core 3.1.7 → 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/concerns/spree/user_methods.rb +20 -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/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 +9 -2
- 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 +27 -0
- 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 +68 -23
- 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
data/lib/spree/migrations.rb
CHANGED
|
@@ -7,7 +7,14 @@ module Spree
|
|
|
7
7
|
can :read, Country
|
|
8
8
|
can :read, OptionType
|
|
9
9
|
can :read, OptionValue
|
|
10
|
-
can :create, Order
|
|
10
|
+
can :create, Order do |order, token|
|
|
11
|
+
# same user, or both nil
|
|
12
|
+
order.user == user ||
|
|
13
|
+
# guest checkout order
|
|
14
|
+
order.email.present? ||
|
|
15
|
+
# via API, just like with show and update
|
|
16
|
+
(order.guest_token.present? && token == order.guest_token)
|
|
17
|
+
end
|
|
11
18
|
can [:show, :update], Order, Order.where(user: user) do |order, token|
|
|
12
19
|
order.user == user || (order.guest_token.present? && token == order.guest_token)
|
|
13
20
|
end
|
|
@@ -65,10 +65,10 @@ module Spree
|
|
|
65
65
|
|
|
66
66
|
@@line_item_attributes = [:id, :variant_id, :quantity]
|
|
67
67
|
|
|
68
|
-
@@option_type_attributes = [:name, :presentation, :option_values_attributes]
|
|
69
|
-
|
|
70
68
|
@@option_value_attributes = [:name, :presentation]
|
|
71
69
|
|
|
70
|
+
@@option_type_attributes = [:name, :presentation, option_values_attributes: option_value_attributes]
|
|
71
|
+
|
|
72
72
|
@@payment_attributes = [:amount, :payment_method_id, :payment_method]
|
|
73
73
|
|
|
74
74
|
@@product_properties_attributes = [:property_name, :value, :position]
|
|
@@ -131,8 +131,8 @@ module Spree
|
|
|
131
131
|
@@variant_attributes = [
|
|
132
132
|
:name, :presentation, :cost_price, :lock_version,
|
|
133
133
|
:position, :track_inventory,
|
|
134
|
-
:product_id, :product, :
|
|
135
|
-
:weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
|
|
134
|
+
:product_id, :product, :price,
|
|
135
|
+
:weight, :height, :width, :depth, :sku, :cost_currency, :tax_category_id, option_value_ids: [], options: [:name, :value]
|
|
136
136
|
]
|
|
137
137
|
|
|
138
138
|
@@checkout_address_attributes = [
|
|
@@ -38,6 +38,7 @@ module Spree::Preferences
|
|
|
38
38
|
# defaults. Set via {#load_defaults}
|
|
39
39
|
attr_reader :loaded_defaults
|
|
40
40
|
|
|
41
|
+
# @api private
|
|
41
42
|
attr_reader :load_defaults_called
|
|
42
43
|
|
|
43
44
|
def initialize
|
|
@@ -45,9 +46,9 @@ module Spree::Preferences
|
|
|
45
46
|
@load_defaults_called = false
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
# @param [String] Solidus version from which take defaults when
|
|
49
|
-
# overriden.
|
|
50
|
-
# @see #
|
|
49
|
+
# @param [String] Solidus version from which take defaults when preferences
|
|
50
|
+
# are not overriden by the user.
|
|
51
|
+
# @see #loaded_defaults
|
|
51
52
|
def load_defaults(version)
|
|
52
53
|
@loaded_defaults = version
|
|
53
54
|
@load_defaults_called = true
|
|
@@ -118,21 +119,35 @@ module Spree::Preferences
|
|
|
118
119
|
end
|
|
119
120
|
end
|
|
120
121
|
|
|
121
|
-
|
|
122
|
+
def self.inherited(klass)
|
|
123
|
+
klass.instance_variable_set(:@versioned_preferences, [])
|
|
124
|
+
class << klass
|
|
125
|
+
attr_reader :versioned_preferences
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Adds a preference with different default depending on {#loaded_defaults}
|
|
122
130
|
#
|
|
123
|
-
# This method is
|
|
124
|
-
#
|
|
125
|
-
# until version 3.0.0.alpha, when it
|
|
131
|
+
# This method is a specialized version of {.preference} that generates a
|
|
132
|
+
# different default value for different Solidus versions. For instance, in
|
|
133
|
+
# the example, `foo`'s default was `true` until version 3.0.0.alpha, when it
|
|
134
|
+
# became `false`:
|
|
126
135
|
#
|
|
127
136
|
# @example
|
|
128
|
-
#
|
|
137
|
+
# versioned_preference :foo, :boolean, initial_value: true, boundaries: { "3.0.0.alpha" => false }
|
|
129
138
|
#
|
|
139
|
+
# @see .preference
|
|
130
140
|
# @see #loaded_defaults
|
|
131
141
|
# @see Spree::Core::VersionedValue
|
|
132
|
-
def self.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
def self.versioned_preference(name, type, initial_value:, boundaries:, **options)
|
|
143
|
+
@versioned_preferences << name
|
|
144
|
+
preference(
|
|
145
|
+
name,
|
|
146
|
+
type,
|
|
147
|
+
options.merge(
|
|
148
|
+
default: by_version(initial_value, boundaries)
|
|
149
|
+
)
|
|
150
|
+
)
|
|
136
151
|
end
|
|
137
152
|
|
|
138
153
|
def self.preference(name, type, options = {})
|
|
@@ -160,6 +175,13 @@ module Spree::Preferences
|
|
|
160
175
|
end
|
|
161
176
|
end
|
|
162
177
|
|
|
178
|
+
def self.by_version(*args)
|
|
179
|
+
proc do |loaded_defaults|
|
|
180
|
+
Spree::Core::VersionedValue.new(*args).call(loaded_defaults)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
private_class_method :by_version
|
|
184
|
+
|
|
163
185
|
private
|
|
164
186
|
|
|
165
187
|
def context_for_default
|
|
@@ -49,7 +49,7 @@ module Spree::Preferences
|
|
|
49
49
|
|
|
50
50
|
If you want to branch on the provided Solidus version, you can do like the following:
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
versioned_preference :foo, :string, initial_value: true, boundaries: { "3.2.0" => false }
|
|
53
53
|
|
|
54
54
|
MSG
|
|
55
55
|
->(_default_context) { given.call }
|
|
@@ -12,7 +12,8 @@ module Spree
|
|
|
12
12
|
def call(from:, to:)
|
|
13
13
|
preferences_from = config_class.new.load_defaults(from)
|
|
14
14
|
preferences_to = config_class.new.load_defaults(to)
|
|
15
|
-
|
|
15
|
+
config_class.versioned_preferences.reduce({}) do |changes, pref_key|
|
|
16
|
+
value_from = preferences_from[pref_key]
|
|
16
17
|
value_to = preferences_to[pref_key]
|
|
17
18
|
if value_from == value_to
|
|
18
19
|
changes
|
|
@@ -36,8 +36,6 @@ module Spree
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def add(klass, name, preferences)
|
|
39
|
-
# We use class name instead of class to allow reloading in dev
|
|
40
|
-
raise "Static model preference '#{name}' on #{klass} is already defined" if @store[klass.to_s][name]
|
|
41
39
|
@store[klass.to_s][name] = Definition.new(klass, preferences)
|
|
42
40
|
end
|
|
43
41
|
|
|
@@ -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'
|