solidus_core 2.11.10 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -2
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +2 -2
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/default_price.rb +39 -10
- data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +10 -37
- data/app/models/concerns/spree/user_methods.rb +38 -13
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +7 -33
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flat_fee.rb +21 -0
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/country.rb +2 -7
- data/app/models/spree/credit_card.rb +1 -28
- data/app/models/spree/customer_return.rb +5 -7
- data/app/models/spree/image/active_storage_attachment.rb +2 -7
- data/app/models/spree/image/paperclip_attachment.rb +2 -2
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +6 -49
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +10 -1
- data/app/models/spree/order/number_generator.rb +7 -1
- data/app/models/spree/order.rb +82 -170
- data/app/models/spree/order_cancellations.rb +4 -24
- 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_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +17 -16
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment/processing.rb +58 -55
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
- data/app/models/spree/payment_method.rb +26 -110
- data/app/models/spree/price.rb +3 -3
- data/app/models/spree/product/scopes.rb +24 -33
- data/app/models/spree/product.rb +15 -42
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
- data/app/models/spree/promotion/rules/item_total.rb +50 -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 +6 -15
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +39 -32
- data/app/models/spree/promotion_action.rb +6 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +11 -7
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/property.rb +1 -1
- data/app/models/spree/refund.rb +8 -52
- data/app/models/spree/reimbursement.rb +5 -43
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +2 -5
- data/app/models/spree/return_item.rb +4 -24
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +1 -5
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +8 -26
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +2 -8
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit.rb +14 -1
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/store_credit_prioritizer.rb +17 -0
- 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_helpers.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_calculator/default.rb +31 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
- data/app/models/spree/tax_rate.rb +9 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +34 -4
- data/app/models/spree/variant.rb +52 -66
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/i18n-tasks.yml +134 -0
- data/config/locales/en.yml +406 -263
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
- data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
- data/db/seeds.rb +4 -1
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
- data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
- data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
- data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
- data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
- data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
- data/lib/generators/solidus/install/install_generator.rb +247 -149
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
- data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/spree/app_configuration.rb +134 -64
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +10 -15
- data/lib/spree/core/controller_helpers/current_host.rb +5 -3
- data/lib/spree/core/controller_helpers/order.rb +12 -32
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +54 -50
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +1 -41
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +18 -35
- data/lib/spree/core/state_machines/order.rb +2 -2
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +5 -3
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +40 -11
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +7 -7
- data/lib/spree/event.rb +1 -32
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/migrations.rb +13 -11
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +17 -59
- data/lib/spree/preferences/configuration.rb +84 -0
- data/lib/spree/preferences/preferable.rb +13 -0
- data/lib/spree/preferences/preferable_class_methods.rb +37 -4
- data/lib/spree/preferences/preference_differentiator.rb +29 -0
- data/lib/spree/preferences/static_model_preferences.rb +25 -10
- data/lib/spree/rails_compatibility.rb +106 -0
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/common_rake.rb +71 -23
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- 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/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +47 -34
- data/lib/spree/testing_support/factories/address_factory.rb +9 -6
- data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
- data/lib/spree/testing_support/factories/country_factory.rb +1 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -5
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/factories/state_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/user_factory.rb +6 -0
- data/lib/spree/testing_support/factory_bot.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -8
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/colorado_delivery_fee.rake +28 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +14 -7
- metadata +127 -78
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -22
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/app/models/spree/calculator/price_sack.rb +0 -28
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -244
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- 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/generators/spree/install/install_generator.rb +0 -15
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -41
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -12
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
- data/lib/tasks/upgrade.rake +0 -13
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/gem_version'
|
4
|
+
|
5
|
+
module Spree
|
6
|
+
# Supported Rails versions compatibility
|
7
|
+
#
|
8
|
+
# This module is meant to wrap some Rails API changes between supported
|
9
|
+
# versions. It's also meant to contain compatibility for features that we use
|
10
|
+
# internally in the Solidus code base.
|
11
|
+
module RailsCompatibility
|
12
|
+
# Method `#to_fs`
|
13
|
+
#
|
14
|
+
# Available since Rails 7.0, substitutes `#to_s(format)`
|
15
|
+
#
|
16
|
+
# It includes:
|
17
|
+
#
|
18
|
+
# ActiveSupport::NumericWithFormat
|
19
|
+
# ActiveSupport::RangeWithFormat
|
20
|
+
# ActiveSupport::TimeWithZone
|
21
|
+
# Array
|
22
|
+
# Date
|
23
|
+
# DateTime
|
24
|
+
# Time
|
25
|
+
#
|
26
|
+
# See https://github.com/rails/rails/pull/43772 &
|
27
|
+
# https://github.com/rails/rails/pull/44354
|
28
|
+
#
|
29
|
+
# TODO: Remove when deprecating Rails 6.1
|
30
|
+
def self.to_fs(value, *args, **kwargs, &block)
|
31
|
+
if version_gte?('7.0')
|
32
|
+
value.to_fs(*args, **kwargs, &block)
|
33
|
+
else
|
34
|
+
value.to_s(*args, **kwargs, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# `raise_on_missing_translations` config option
|
39
|
+
#
|
40
|
+
# Changed from ActionView to I18n on Rails 6.1
|
41
|
+
#
|
42
|
+
# See https://github.com/rails/rails/pull/31571
|
43
|
+
#
|
44
|
+
# TODO: Remove when deprecating Rails 6.0
|
45
|
+
def self.raise_on_missing_translations(value)
|
46
|
+
if version_gte?('6.1')
|
47
|
+
Rails.application.config.i18n.raise_on_missing_translations = value
|
48
|
+
else
|
49
|
+
Rails.application.config.action_view.raise_on_missing_translations = value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Set default image attachment adapter
|
54
|
+
#
|
55
|
+
# TODO: Remove when deprecating Rails 6.0
|
56
|
+
def self.default_image_attachment_module
|
57
|
+
if version_gte?("6.1")
|
58
|
+
"Spree::Image::ActiveStorageAttachment"
|
59
|
+
else
|
60
|
+
"Spree::Image::PaperclipAttachment"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Set default taxon attachment adapter
|
65
|
+
#
|
66
|
+
# TODO: Remove when deprecating Rails 6.0
|
67
|
+
def self.default_taxon_attachment_module
|
68
|
+
if version_gte?("6.1")
|
69
|
+
"Spree::Taxon::ActiveStorageAttachment"
|
70
|
+
else
|
71
|
+
"Spree::Taxon::PaperclipAttachment"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Set current host for ActiveStorage
|
76
|
+
#
|
77
|
+
# Changed from `#host` to `#url_options` on Rails 7
|
78
|
+
#
|
79
|
+
# See https://github.com/rails/rails/issues/41388
|
80
|
+
#
|
81
|
+
# TODO: Remove when deprecating Rails 6.1
|
82
|
+
def self.active_storage_url_options_host(value)
|
83
|
+
if version_gte?('7')
|
84
|
+
ActiveStorage::Current.url_options = { host: value }
|
85
|
+
else
|
86
|
+
ActiveStorage::Current.host = value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Default ActiveStorage variant processor
|
91
|
+
#
|
92
|
+
# Changed from `:mini_magick` to `vips` on Rails 7
|
93
|
+
#
|
94
|
+
# See https://github.com/rails/rails/issues/42744
|
95
|
+
#
|
96
|
+
# TODO: Remove when deprecating Rails 6.1
|
97
|
+
def self.variant_processor
|
98
|
+
version_gte?('7') ? :vips : :mini_magick
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.version_gte?(version)
|
102
|
+
::Rails.gem_version >= Gem::Version.new(version)
|
103
|
+
end
|
104
|
+
private_class_method :version_gte?
|
105
|
+
end
|
106
|
+
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
|
@@ -35,18 +35,6 @@ module Spree
|
|
35
35
|
find("td:nth-of-type(#{num})").text
|
36
36
|
end
|
37
37
|
|
38
|
-
def fill_in_quantity(table_column, selector, quantity)
|
39
|
-
Spree::Deprecation.warn <<-WARN.strip_heredoc
|
40
|
-
fill_in_quantity is deprecated. Instead use:
|
41
|
-
within(#{table_column.inspect}) do
|
42
|
-
fill_in #{selector.inspect}, with: #{quantity.inspect}
|
43
|
-
end
|
44
|
-
WARN
|
45
|
-
within(table_column) do
|
46
|
-
fill_in selector, with: quantity
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
38
|
def select2_search(value, options)
|
51
39
|
options = {
|
52
40
|
search: value, # by default search for the value
|
@@ -122,21 +110,6 @@ module Spree
|
|
122
110
|
# find the original.
|
123
111
|
find('label:not(.select2-offscreen)', text: /#{Regexp.escape(text)}/i, match: :one)
|
124
112
|
end
|
125
|
-
|
126
|
-
def wait_for_ajax
|
127
|
-
Spree::Deprecation.warn <<-WARN.squish, caller
|
128
|
-
wait_for_ajax has been deprecated.
|
129
|
-
Please refer to the capybara documentation on how to properly wait for asyncronous behavior:
|
130
|
-
https://github.com/teamcapybara/capybara#asynchronous-javascript-ajax-and-friends
|
131
|
-
WARN
|
132
|
-
|
133
|
-
counter = 0
|
134
|
-
while page.evaluate_script("typeof($) === 'undefined' || $.active > 0")
|
135
|
-
counter += 1
|
136
|
-
sleep(0.1)
|
137
|
-
raise "AJAX request took longer than 5 seconds." if counter >= 50
|
138
|
-
end
|
139
|
-
end
|
140
113
|
end
|
141
114
|
end
|
142
115
|
end
|
@@ -156,9 +129,6 @@ RSpec::Matchers.define :have_meta do |name, expected|
|
|
156
129
|
end
|
157
130
|
end
|
158
131
|
|
159
|
-
# @private
|
160
|
-
CapybaraExt = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('CapybaraExt', 'Spree::TestingSupport::CapybaraExt')
|
161
|
-
|
162
132
|
RSpec.configure do |c|
|
163
133
|
c.include Spree::TestingSupport::CapybaraExt
|
164
134
|
end
|
@@ -1,38 +1,86 @@
|
|
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
|
-
|
10
|
-
|
11
|
-
args.with_defaults(user_class: "Spree::LegacyUser")
|
12
|
-
require ENV['LIB_NAME']
|
5
|
+
class CommonRakeTasks
|
6
|
+
include Rake::DSL
|
13
7
|
|
14
|
-
|
8
|
+
def initialize
|
9
|
+
namespace :common do
|
10
|
+
task :test_app, :user_class do |_t, args|
|
11
|
+
args.with_defaults(user_class: "Spree::LegacyUser")
|
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
|
16
|
+
|
17
|
+
force_rails_environment_to_test
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
Spree::DummyGenerator.start [
|
20
|
+
"--lib-name=#{lib_name}",
|
21
|
+
"--quiet",
|
22
|
+
]
|
18
23
|
|
19
|
-
|
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)
|
20
42
|
|
21
|
-
|
22
|
-
sh "bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test"
|
43
|
+
puts "Setting up dummy database..."
|
23
44
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
45
|
+
sh "bin/rails db:environment:set RAILS_ENV=test"
|
46
|
+
sh "bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test"
|
47
|
+
|
48
|
+
if extension_installation_generator_exists?
|
49
|
+
puts 'Running extension installation generator...'
|
50
|
+
sh "bin/rails generate #{rake_generator_namespace}:install --auto-run-migrations"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
task :seed do |_t, _args|
|
55
|
+
puts "Seeding ..."
|
56
|
+
|
57
|
+
sh "bundle exec rake db:seed RAILS_ENV=test"
|
58
|
+
end
|
30
59
|
end
|
31
60
|
end
|
32
61
|
|
33
|
-
|
34
|
-
puts "Seeding ..."
|
62
|
+
private
|
35
63
|
|
36
|
-
|
64
|
+
def force_rails_environment_to_test
|
65
|
+
ENV["RAILS_ENV"] = 'test'
|
66
|
+
Rails.env = 'test'
|
67
|
+
end
|
68
|
+
|
69
|
+
def extension_installation_generator_exists?
|
70
|
+
require "generators/#{generator_namespace}/install/install_generator"
|
71
|
+
|
72
|
+
true
|
73
|
+
rescue LoadError
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def generator_namespace
|
78
|
+
"#{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def rake_generator_namespace
|
82
|
+
generator_namespace.gsub("/", ":")
|
37
83
|
end
|
38
84
|
end
|
85
|
+
|
86
|
+
CommonRakeTasks.new
|
@@ -2,23 +2,12 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
module TestingSupport
|
5
|
-
# A module providing convenience methods to test Solidus controllers
|
6
|
-
# in Rails controller/functional tests. Possibly from inside an
|
7
|
-
# application with a mounted Solidus engine.
|
8
|
-
#
|
9
5
|
# *There is generaly no need* to use this module. Instead, in
|
10
6
|
# a functional/controller test against a Spree controller, just
|
11
7
|
# use standard Rails functionality by including:
|
12
8
|
#
|
13
9
|
# routes { Spree::Core::Engine.routes }
|
14
10
|
#
|
15
|
-
# And then use standard Rails test `get`, `post` etc methods.
|
16
|
-
#
|
17
|
-
# But some legacy code uses this ControllerRequests helper. It must
|
18
|
-
# be included only in tests against Spree controllers, it will interfere
|
19
|
-
# with tests against local app or other engine controllers, resulting
|
20
|
-
# in ActionController::UrlGenerationError.
|
21
|
-
#
|
22
11
|
# To use this module, inside your spec_helper.rb, include this module inside
|
23
12
|
# the RSpec.configure block by:
|
24
13
|
#
|
@@ -26,83 +15,12 @@ module Spree
|
|
26
15
|
# RSpec.configure do |c|
|
27
16
|
# c.include Spree::TestingSupport::ControllerRequests, spree_controller: true
|
28
17
|
# end
|
29
|
-
#
|
30
|
-
# Then, in your controller tests against spree controllers, you can access
|
31
|
-
# tag to use this module, and access spree routes like this:
|
32
|
-
#
|
33
|
-
# require 'spec_helper'
|
34
|
-
#
|
35
|
-
# describe Spree::ProductsController, :spree_controller do
|
36
|
-
# it "can see all the products" do
|
37
|
-
# spree_get :index
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# Use spree_get, spree_post, spree_put or spree_delete to make requests to
|
42
|
-
# the Spree engine, and use regular get, post, put or delete to make
|
43
|
-
# requests to your application.
|
44
18
|
module ControllerRequests
|
45
19
|
extend ActiveSupport::Concern
|
46
20
|
|
47
21
|
included do
|
48
22
|
routes { Spree::Core::Engine.routes }
|
49
23
|
end
|
50
|
-
|
51
|
-
def spree_get(action, parameters = nil, session = nil, flash = nil)
|
52
|
-
process_spree_action(action, parameters, session, flash, "GET")
|
53
|
-
end
|
54
|
-
deprecate spree_get: :get, deprecator: Spree::Deprecation
|
55
|
-
|
56
|
-
# Executes a request simulating POST HTTP method and set/volley the response
|
57
|
-
def spree_post(action, parameters = nil, session = nil, flash = nil)
|
58
|
-
process_spree_action(action, parameters, session, flash, "POST")
|
59
|
-
end
|
60
|
-
deprecate spree_post: :post, deprecator: Spree::Deprecation
|
61
|
-
|
62
|
-
# Executes a request simulating PUT HTTP method and set/volley the response
|
63
|
-
def spree_put(action, parameters = nil, session = nil, flash = nil)
|
64
|
-
process_spree_action(action, parameters, session, flash, "PUT")
|
65
|
-
end
|
66
|
-
deprecate spree_put: :put, deprecator: Spree::Deprecation
|
67
|
-
|
68
|
-
# Executes a request simulating DELETE HTTP method and set/volley the response
|
69
|
-
def spree_delete(action, parameters = nil, session = nil, flash = nil)
|
70
|
-
process_spree_action(action, parameters, session, flash, "DELETE")
|
71
|
-
end
|
72
|
-
deprecate spree_delete: :delete, deprecator: Spree::Deprecation
|
73
|
-
|
74
|
-
def spree_xhr_get(action, parameters = nil, session = nil, flash = nil)
|
75
|
-
process_spree_xhr_action(action, parameters, session, flash, :get)
|
76
|
-
end
|
77
|
-
deprecate spree_xhr_get: :get, deprecator: Spree::Deprecation
|
78
|
-
|
79
|
-
def spree_xhr_post(action, parameters = nil, session = nil, flash = nil)
|
80
|
-
process_spree_xhr_action(action, parameters, session, flash, :post)
|
81
|
-
end
|
82
|
-
deprecate spree_xhr_post: :post, deprecator: Spree::Deprecation
|
83
|
-
|
84
|
-
def spree_xhr_put(action, parameters = nil, session = nil, flash = nil)
|
85
|
-
process_spree_xhr_action(action, parameters, session, flash, :put)
|
86
|
-
end
|
87
|
-
deprecate spree_xhr_put: :put, deprecator: Spree::Deprecation
|
88
|
-
|
89
|
-
def spree_xhr_delete(action, parameters = nil, session = nil, flash = nil)
|
90
|
-
process_spree_xhr_action(action, parameters, session, flash, :delete)
|
91
|
-
end
|
92
|
-
deprecate spree_xhr_delete: :delete, deprecator: Spree::Deprecation
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
def process_spree_action(action, parameters = nil, session = nil, flash = nil, method = "GET")
|
97
|
-
parameters ||= {}
|
98
|
-
process(action, method, parameters, session, flash)
|
99
|
-
end
|
100
|
-
|
101
|
-
def process_spree_xhr_action(action, parameters = nil, session = nil, flash = nil, method = :get)
|
102
|
-
parameters ||= {}
|
103
|
-
parameters.reverse_merge!(format: :json)
|
104
|
-
xml_http_request(method, action, parameters, session, flash)
|
105
|
-
end
|
106
24
|
end
|
107
25
|
end
|
108
26
|
end
|
@@ -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.
|
@@ -1,34 +1,54 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<% db = case ENV['DB']
|
2
|
+
when 'mysql'
|
3
|
+
'mysql'
|
4
|
+
when 'postgres', 'postgresql'
|
5
|
+
'postgres'
|
6
|
+
when 'sqlite', '', nil
|
7
|
+
'sqlite'
|
8
|
+
else
|
9
|
+
raise "Invalid DB specified: #{ENV['DB']}"
|
10
|
+
end %>
|
11
|
+
<% db_host = case db
|
12
|
+
when 'mysql'
|
13
|
+
ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
|
14
|
+
when 'postgres'
|
15
|
+
ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
|
16
|
+
else
|
17
|
+
ENV['DB_HOST']
|
18
|
+
end %>
|
19
|
+
<% db_prefix = ENV['LIB_NAME'].presence || "solidus" %>
|
20
|
+
<% db_username = ENV['DB_USERNAME'] %>
|
21
|
+
<% db_password = ENV['DB_PASSWORD'] %>
|
22
|
+
<% case db
|
5
23
|
when 'mysql' %>
|
6
24
|
test:
|
7
25
|
adapter: mysql2
|
8
|
-
|
9
|
-
|
10
|
-
|
26
|
+
database: <%= db_prefix %>_test
|
27
|
+
<% unless db_username.blank? %>
|
28
|
+
username: <%= db_username %>
|
11
29
|
<% end %>
|
12
|
-
|
13
|
-
|
14
|
-
<%
|
15
|
-
|
30
|
+
<% unless db_password.blank? %>
|
31
|
+
password: <%= db_password %>
|
32
|
+
<% end %>
|
33
|
+
<% unless db_host.blank? %>
|
34
|
+
host: <%= db_host %>
|
16
35
|
<% end %>
|
17
|
-
|
18
|
-
<%
|
36
|
+
encoding: utf8
|
37
|
+
<% when 'postgres' %>
|
19
38
|
test:
|
20
39
|
adapter: postgresql
|
21
|
-
database: <%=
|
22
|
-
username: postgres
|
23
|
-
|
24
|
-
|
40
|
+
database: <%= db_prefix %>_test
|
41
|
+
username: <%= db_username.presence || "postgres" %>
|
42
|
+
<% unless db_password.blank? %>
|
43
|
+
password: <%= db_password %>
|
44
|
+
<% end %>
|
45
|
+
<% unless db_host.blank? %>
|
25
46
|
host: <%= db_host %>
|
26
|
-
<% end %>
|
27
|
-
|
47
|
+
<% end %>
|
48
|
+
min_messages: warning
|
49
|
+
<% when 'sqlite' %>
|
28
50
|
test:
|
29
51
|
adapter: sqlite3
|
30
|
-
database: db/<%=
|
52
|
+
database: db/<%= db_prefix %>_test.sqlite3
|
31
53
|
timeout: 10000
|
32
|
-
<% else %>
|
33
|
-
<% raise "Invalid DB specified: #{ENV['DB']}" %>
|
34
54
|
<% end %>
|
@@ -27,9 +27,6 @@ module DummyApp
|
|
27
27
|
ActiveRecord::Base.remove_connection
|
28
28
|
|
29
29
|
sh 'rake db:reset VERBOSE=false'
|
30
|
-
if ENV['ENABLE_ACTIVE_STORAGE']
|
31
|
-
sh 'rake active_storage:install db:migrate VERBOSE=false'
|
32
|
-
end
|
33
30
|
|
34
31
|
# We have a brand new database, so we must re-establish our connection
|
35
32
|
ActiveRecord::Base.establish_connection
|