solidus_core 2.8.6 → 2.9.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/images/logo/solidus.svg +1 -18
- data/app/assets/images/logo/solidus_logo.png +0 -0
- data/app/mailers/spree/test_mailer.rb +2 -0
- data/app/models/concerns/spree/default_price.rb +1 -1
- data/app/models/concerns/spree/ransackable_attributes.rb +1 -1
- data/app/models/concerns/spree/user_reporting.rb +1 -1
- data/app/models/spree/billing_integration.rb +7 -2
- data/app/models/spree/country.rb +2 -0
- data/app/models/spree/customer_return.rb +1 -1
- data/app/models/spree/image.rb +2 -44
- data/app/models/spree/image/paperclip_attachment.rb +55 -0
- data/app/models/spree/inventory_unit.rb +0 -1
- data/app/models/spree/option_type.rb +2 -0
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order.rb +8 -13
- data/app/models/spree/payment.rb +1 -1
- data/app/models/spree/payment_method.rb +8 -4
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/promotion.rb +18 -11
- data/app/models/spree/promotion/rules/first_order.rb +1 -3
- data/app/models/spree/promotion/rules/item_total.rb +9 -1
- data/app/models/spree/promotion/rules/one_use_per_user.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion/rules/taxon.rb +5 -8
- data/app/models/spree/promotion/rules/user_logged_in.rb +1 -1
- data/app/models/spree/promotion_handler/coupon.rb +19 -3
- data/app/models/spree/property.rb +2 -0
- data/app/models/spree/reimbursement.rb +5 -5
- data/app/models/spree/return_item.rb +6 -2
- data/app/models/spree/state.rb +6 -0
- data/app/models/spree/stock/location_filter/active.rb +14 -0
- data/app/models/spree/stock/location_filter/base.rb +43 -0
- data/app/models/spree/stock/simple_coordinator.rb +4 -1
- data/app/models/spree/stock_location.rb +2 -0
- data/app/models/spree/tax_category.rb +11 -0
- data/app/models/spree/taxon.rb +4 -11
- data/app/models/spree/taxon/paperclip_attachment.rb +21 -0
- data/app/models/spree/taxonomy.rb +2 -0
- data/app/models/spree/unit_cancel.rb +12 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/models/spree/variant/pricing_options.rb +10 -0
- data/app/models/spree/wallet_payment_source.rb +26 -10
- data/app/models/spree/zone.rb +1 -1
- data/app/views/spree/order_mailer/inventory_cancellation_email.text.erb +3 -3
- data/config/locales/en.yml +26 -53
- data/db/default/spree/store_credit.rb +1 -0
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +1 -1
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +9 -8
- data/db/migrate/20190220093635_drop_spree_store_credit_update_reasons.rb +19 -0
- data/lib/generators/spree/install/install_generator.rb +0 -3
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +3 -0
- data/lib/solidus/migrations/rename_gateways.rb +2 -0
- data/lib/spree/app_configuration.rb +24 -0
- data/lib/spree/core.rb +1 -0
- data/lib/spree/core/controller_helpers/pricing.rb +1 -4
- data/lib/spree/core/controller_helpers/strong_parameters.rb +7 -21
- data/lib/spree/core/engine.rb +5 -0
- data/lib/spree/core/importer/order.rb +1 -3
- data/lib/spree/core/stock_configuration.rb +5 -0
- data/lib/spree/core/version.rb +3 -1
- data/lib/spree/deprecation.rb +50 -0
- data/lib/spree/event.rb +111 -0
- data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
- data/lib/spree/event/configuration.rb +17 -0
- data/lib/spree/event/processors/mailer_processor.rb +27 -0
- data/lib/spree/event/subscriber.rb +84 -0
- data/lib/spree/permitted_attributes.rb +7 -76
- data/lib/spree/testing_support/capybara_ext.rb +15 -0
- data/lib/spree/testing_support/common_rake.rb +1 -1
- data/lib/spree/testing_support/dummy_app.rb +3 -10
- data/lib/spree/testing_support/factories/promotion_factory.rb +10 -0
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
- data/lib/spree/testing_support/preferences.rb +62 -0
- data/lib/tasks/email.rake +2 -0
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +4 -0
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +2 -0
- data/lib/tasks/migrations/migrate_user_addresses.rake +3 -0
- data/lib/tasks/migrations/rename_gateways.rake +2 -0
- data/lib/tasks/order_capturing.rake +2 -0
- data/spec/helpers/base_helper_spec.rb +3 -3
- data/spec/helpers/products_helper_spec.rb +2 -2
- data/spec/{models → lib}/spree/app_configuration_spec.rb +11 -1
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +13 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +1 -8
- data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +1 -1
- data/spec/lib/spree/core/testing_support/preferences_spec.rb +33 -0
- data/spec/lib/spree/event/subscriber_spec.rb +85 -0
- data/spec/lib/spree/event_spec.rb +92 -0
- data/spec/lib/spree/money_spec.rb +3 -9
- data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +5 -3
- data/spec/mailers/order_mailer_spec.rb +1 -1
- data/spec/mailers/test_mailer_spec.rb +3 -1
- data/spec/models/spree/address_spec.rb +5 -4
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/country_spec.rb +5 -5
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +3 -7
- data/spec/models/spree/order/finalizing_spec.rb +1 -1
- data/spec/models/spree/order/payment_spec.rb +3 -3
- data/spec/models/spree/order_inventory_spec.rb +1 -1
- data/spec/models/spree/order_spec.rb +67 -2
- data/spec/models/spree/order_updater_spec.rb +2 -2
- data/spec/models/spree/payment_spec.rb +12 -0
- data/spec/models/spree/product_spec.rb +3 -3
- data/spec/models/spree/promotion/rules/first_order_spec.rb +13 -3
- data/spec/models/spree/promotion/rules/item_total_spec.rb +15 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +10 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +15 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +59 -8
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +5 -0
- data/spec/models/spree/promotion_handler/shipping_spec.rb +1 -1
- data/spec/models/spree/promotion_spec.rb +80 -0
- data/spec/models/spree/reimbursement_spec.rb +3 -2
- data/spec/models/spree/return_item_spec.rb +9 -0
- data/spec/models/spree/shipment_spec.rb +3 -3
- data/spec/models/spree/stock/availability_spec.rb +1 -1
- data/spec/models/spree/stock/estimator_spec.rb +5 -7
- data/spec/models/spree/stock/location_filter/active_spec.rb +22 -0
- data/spec/models/spree/stock/location_sorter/default_first_spec.rb +4 -2
- data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +3 -1
- data/spec/models/spree/stock/quantifier_spec.rb +1 -1
- data/spec/models/spree/stock/simple_coordinator_spec.rb +5 -0
- data/spec/models/spree/stock_item_spec.rb +3 -2
- data/spec/models/spree/stock_movement_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +1 -1
- data/spec/models/spree/tax/order_adjuster_spec.rb +1 -1
- data/spec/models/spree/tax/taxation_integration_spec.rb +1 -1
- data/spec/models/spree/tax_category_spec.rb +21 -0
- data/spec/models/spree/taxon_spec.rb +28 -0
- data/spec/models/spree/unit_cancel_spec.rb +41 -0
- data/spec/models/spree/user_spec.rb +3 -3
- data/spec/models/spree/variant/pricing_options_spec.rb +23 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +1 -1
- data/spec/models/spree/variant_spec.rb +11 -8
- data/spec/models/spree/wallet_payment_source_spec.rb +35 -6
- data/spec/models/spree/wallet_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -4
- data/spec/support/concerns/default_price.rb +8 -0
- metadata +18 -5
- data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
@@ -12,6 +12,21 @@ module Spree
|
|
12
12
|
fill_in field, options
|
13
13
|
end
|
14
14
|
|
15
|
+
def fill_in_with_force(locator, with:)
|
16
|
+
if Capybara.current_driver == Capybara.javascript_driver
|
17
|
+
field_id = find_field(locator)[:id]
|
18
|
+
page.execute_script <<-JS
|
19
|
+
var field = document.getElementById('#{field_id}');
|
20
|
+
field.value = '#{with}';
|
21
|
+
|
22
|
+
var event = new Event('change', { bubbles: true });
|
23
|
+
field.dispatchEvent(event);
|
24
|
+
JS
|
25
|
+
else
|
26
|
+
fill_in locator, with: with
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
15
30
|
def within_row(num, &block)
|
16
31
|
within("table.index tbody tr:nth-of-type(#{num})", &block)
|
17
32
|
end
|
@@ -24,7 +24,7 @@ namespace :common do
|
|
24
24
|
begin
|
25
25
|
require "generators/#{ENV['LIB_NAME']}/install/install_generator"
|
26
26
|
puts 'Running extension installation generator...'
|
27
|
-
"#{ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
|
27
|
+
"#{ENV['LIB_NAMESPACE'] || ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
|
28
28
|
rescue LoadError
|
29
29
|
# No extension generator to run
|
30
30
|
end
|
@@ -12,14 +12,11 @@ Rails.env = 'test'
|
|
12
12
|
|
13
13
|
require 'solidus_core'
|
14
14
|
|
15
|
-
|
16
|
-
def forgery_protected_by_default?
|
17
|
-
Gem::Version.new(Rails.version) >= Gem::Version.new('5.2')
|
18
|
-
end
|
15
|
+
RAILS_52_OR_ABOVE = Gem::Version.new(Rails.version) >= Gem::Version.new('5.2')
|
19
16
|
|
20
17
|
# @private
|
21
18
|
class ApplicationController < ActionController::Base
|
22
|
-
|
19
|
+
unless RAILS_52_OR_ABOVE
|
23
20
|
protect_from_forgery with: :exception
|
24
21
|
end
|
25
22
|
end
|
@@ -65,12 +62,8 @@ module DummyApp
|
|
65
62
|
config.active_support.deprecation = :stderr
|
66
63
|
config.secret_key_base = 'SECRET_TOKEN'
|
67
64
|
|
68
|
-
if
|
65
|
+
if RAILS_52_OR_ABOVE
|
69
66
|
config.action_controller.default_protect_from_forgery = true
|
70
|
-
end
|
71
|
-
|
72
|
-
if config.active_record.sqlite3
|
73
|
-
# Rails >= 5.2
|
74
67
|
config.active_record.sqlite3.represent_boolean_as_integer = true
|
75
68
|
end
|
76
69
|
|
@@ -60,5 +60,15 @@ FactoryBot.define do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
factory :promotion_with_item_total_rule, traits: [:with_item_total_rule]
|
63
|
+
trait :with_first_order_rule do
|
64
|
+
after(:create) do |promotion, _evaluator|
|
65
|
+
rule = Spree::Promotion::Rules::FirstOrder.create!(
|
66
|
+
promotion: promotion,
|
67
|
+
)
|
68
|
+
promotion.rules << rule
|
69
|
+
promotion.save!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
factory :promotion_with_first_order_rule, traits: [:with_first_order_rule]
|
63
73
|
end
|
64
74
|
end
|
@@ -6,6 +6,7 @@ require 'spree/testing_support/factories/return_authorization_factory'
|
|
6
6
|
|
7
7
|
FactoryBot.define do
|
8
8
|
factory :return_item, class: 'Spree::ReturnItem' do
|
9
|
+
skip_customer_return_processing { true }
|
9
10
|
association(:inventory_unit, factory: :inventory_unit, state: :shipped)
|
10
11
|
association(:return_reason, factory: :return_reason)
|
11
12
|
return_authorization do |_return_item|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'spree/deprecation'
|
4
|
+
|
3
5
|
module Spree
|
4
6
|
module TestingSupport
|
5
7
|
module Preferences
|
@@ -10,6 +12,7 @@ module Spree
|
|
10
12
|
# config.track_inventory_levels = false
|
11
13
|
# end
|
12
14
|
#
|
15
|
+
# @deprecated
|
13
16
|
def reset_spree_preferences(&config_block)
|
14
17
|
Spree::Config.instance_variables.each { |iv| Spree::Config.remove_instance_variable(iv) }
|
15
18
|
Spree::Config.preference_store = Spree::Config.default_preferences
|
@@ -21,6 +24,8 @@ module Spree
|
|
21
24
|
configure_spree_preferences(&config_block) if block_given?
|
22
25
|
end
|
23
26
|
|
27
|
+
deprecate :reset_spree_preferences, deprecator: Spree::Deprecation
|
28
|
+
|
24
29
|
def configure_spree_preferences
|
25
30
|
yield(Spree::Config) if block_given?
|
26
31
|
end
|
@@ -29,6 +34,63 @@ module Spree
|
|
29
34
|
find("#preferences_#{preference}")['checked'].should be false
|
30
35
|
Spree::Config[preference].should be false
|
31
36
|
end
|
37
|
+
|
38
|
+
# This is the preferred way for changing temporarily Spree preferences during
|
39
|
+
# tests via stubs, without changing the actual values stored in Spree::Config.
|
40
|
+
#
|
41
|
+
# By using stubs no global preference change will leak outside the lifecycle
|
42
|
+
# of each spec example, avoiding possible unpredictable side effects.
|
43
|
+
#
|
44
|
+
# This method may be used for stubbing one or more different preferences
|
45
|
+
# at the same time.
|
46
|
+
#
|
47
|
+
# @param [Hash] preferences names and values to be stubbed
|
48
|
+
#
|
49
|
+
# @example Stubs `currency` and `track_inventory_levels` preferences
|
50
|
+
# stub_spree_preferences(currency: 'EUR', track_inventory_levels: false)
|
51
|
+
# expect(Spree::Config.currency).to eql 'EUR'
|
52
|
+
#
|
53
|
+
# @see https://github.com/solidusio/solidus/issues/3219
|
54
|
+
# Solidus #3219 for more details and motivations.
|
55
|
+
def stub_spree_preferences(preferences)
|
56
|
+
preferences.each do |name, value|
|
57
|
+
if Spree::Config.method(:[]).owner >= Spree::Config.class
|
58
|
+
allow(Spree::Config).to receive(:[]).and_call_original
|
59
|
+
end
|
60
|
+
allow(Spree::Config).to receive(:[]).with(name) { value }
|
61
|
+
allow(Spree::Config).to receive(name) { value }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# This method allows to temporarily switch to an unfrozen Spree::Config preference
|
66
|
+
# store with all proper preferences values set.
|
67
|
+
#
|
68
|
+
# It should be used sparingly, only when `stub_spree_preferences` would not work.
|
69
|
+
#
|
70
|
+
# @example Temporarily switch to an unfrozen store and change some preferences:
|
71
|
+
# with_unfrozen_spree_preference_store do
|
72
|
+
# Spree::Config.currency = 'EUR'
|
73
|
+
# Spree::Config.track_inventory_levels = false
|
74
|
+
#
|
75
|
+
# expect(Spree::Config.currency).to eql 'EUR'
|
76
|
+
# end
|
77
|
+
# @see Spree::TestingSupport::Preferences#stub_spree_preferences
|
78
|
+
def with_unfrozen_spree_preference_store
|
79
|
+
frozen_store = Spree::Config.preference_store
|
80
|
+
Spree::Config.preference_store = Spree::Config[:unfrozen_preference_store].dup
|
81
|
+
yield
|
82
|
+
ensure
|
83
|
+
Spree::Config.preference_store = frozen_store
|
84
|
+
end
|
32
85
|
end
|
33
86
|
end
|
34
87
|
end
|
88
|
+
|
89
|
+
RSpec.configure do |config|
|
90
|
+
config.before :suite do
|
91
|
+
# keep a copy of the original unfrozen preference_store for later use:
|
92
|
+
Spree::AppConfiguration.preference :unfrozen_preference_store, :hash
|
93
|
+
Spree::Config.unfrozen_preference_store = Spree::Config.preference_store.dup
|
94
|
+
Spree::Config.preference_store.freeze
|
95
|
+
end
|
96
|
+
end
|
data/lib/tasks/email.rake
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
namespace :email do
|
4
4
|
desc 'Sends test email to specified address - Example: EMAIL=spree@example.com bundle exec rake email:test'
|
5
5
|
task test: :environment do
|
6
|
+
Spree::Deprecation.warn("rake email:test has been deprecated and will be removed with Solidus 3.0")
|
7
|
+
|
6
8
|
raise ArgumentError, "Must pass EMAIL environment variable. Example: EMAIL=spree@example.com bundle exec rake email:test" unless ENV['EMAIL'].present?
|
7
9
|
Spree::TestMailer.test_email(ENV['EMAIL']).deliver!
|
8
10
|
end
|
@@ -13,6 +13,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
|
13
13
|
# This task should be safe to run multiple times.
|
14
14
|
|
15
15
|
task up: :environment do
|
16
|
+
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:up has been deprecated and will be removed with Solidus 3.0.")
|
17
|
+
|
16
18
|
if Spree::CreditCard.connection.adapter_name =~ /postgres/i
|
17
19
|
postgres_copy
|
18
20
|
else
|
@@ -21,6 +23,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
task down: :environment do
|
26
|
+
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:down has been deprecated and will be removed with Solidus 3.0.")
|
27
|
+
|
24
28
|
Spree::CreditCard.update_all(address_id: nil)
|
25
29
|
end
|
26
30
|
|
@@ -4,6 +4,8 @@ namespace :solidus do
|
|
4
4
|
namespace :migrations do
|
5
5
|
namespace :migrate_shipping_rate_taxes do
|
6
6
|
task up: :environment do
|
7
|
+
Spree::Deprecation.warn("rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated and will be removed with Solidus 3.0.")
|
8
|
+
|
7
9
|
print "Adding persisted tax notes to historic shipping rates ... "
|
8
10
|
Spree::ShippingRate.where.not(tax_rate_id: nil).find_each do |shipping_rate|
|
9
11
|
tax_rate = Spree::TaxRate.unscoped.find(shipping_rate.tax_rate_id)
|
@@ -10,6 +10,8 @@ namespace 'spree:migrations:migrate_user_addresses' do
|
|
10
10
|
# to the user's address book. This will catch up all the historical data.
|
11
11
|
|
12
12
|
task up: :environment do
|
13
|
+
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:up has been deprecated and will be removed with Solidus 3.0.")
|
14
|
+
|
13
15
|
Spree.user_class.find_each(batch_size: 500) do |user|
|
14
16
|
ship_address = Spree::Address.find_by(id: user.ship_address_id)
|
15
17
|
bill_address = Spree::Address.find_by(id: user.bill_address_id)
|
@@ -26,6 +28,7 @@ namespace 'spree:migrations:migrate_user_addresses' do
|
|
26
28
|
end
|
27
29
|
|
28
30
|
task down: :environment do
|
31
|
+
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:down has been deprecated and will be removed with Solidus 3.0.")
|
29
32
|
Spree::UserAddress.delete_all
|
30
33
|
end
|
31
34
|
end
|
@@ -4,6 +4,7 @@ require 'solidus/migrations/rename_gateways'
|
|
4
4
|
|
5
5
|
namespace 'solidus:migrations:rename_gateways' do
|
6
6
|
task up: :environment do
|
7
|
+
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:up has been deprecated and will be removed with Solidus 3.0.")
|
7
8
|
count = Solidus::Migrations::RenameGateways.new.up
|
8
9
|
|
9
10
|
unless ENV['VERBOSE'] == 'false' || !verbose
|
@@ -12,6 +13,7 @@ namespace 'solidus:migrations:rename_gateways' do
|
|
12
13
|
end
|
13
14
|
|
14
15
|
task down: :environment do
|
16
|
+
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:down has been deprecated and will be removed with Solidus 3.0.")
|
15
17
|
count = Solidus::Migrations::RenameGateways.new.down
|
16
18
|
|
17
19
|
unless ENV['VERBOSE'] == 'false' || !verbose
|
@@ -3,6 +3,8 @@
|
|
3
3
|
namespace :order_capturing do
|
4
4
|
desc "Looks for orders with inventory that is fully shipped/short-shipped, and captures money for it"
|
5
5
|
task capture_payments: :environment do
|
6
|
+
Spree::Deprecation.warn("rake order_capturing:capture_payments has been deprecated and will be removed with Solidus 3.0.")
|
7
|
+
|
6
8
|
failures = []
|
7
9
|
orders = Spree::Order.complete.where(payment_state: 'balance_due').where('completed_at > ?', Spree::Config[:order_capturing_time_window].days.ago)
|
8
10
|
|
@@ -16,7 +16,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
|
|
16
16
|
|
17
17
|
context "with no checkout zone defined" do
|
18
18
|
before do
|
19
|
-
|
19
|
+
stub_spree_preferences(checkout_zone: nil)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "return complete list of countries" do
|
@@ -33,7 +33,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
|
|
33
33
|
before do
|
34
34
|
@country_zone = create(:zone, name: "CountryZone")
|
35
35
|
@country_zone.members.create(zoneable: country)
|
36
|
-
|
36
|
+
stub_spree_preferences(checkout_zone: @country_zone.name)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "return only the countries defined by the checkout zone" do
|
@@ -50,7 +50,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
|
|
50
50
|
state_zone = create(:zone, name: "StateZone")
|
51
51
|
state = create(:state, country: country)
|
52
52
|
state_zone.members.create(zoneable: state)
|
53
|
-
|
53
|
+
stub_spree_preferences(checkout_zone: state_zone.name)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "return complete list of countries" do
|
@@ -75,7 +75,7 @@ module Spree
|
|
75
75
|
let(:variant_price) { 15 }
|
76
76
|
|
77
77
|
before do
|
78
|
-
|
78
|
+
stub_spree_preferences(show_variant_full_price: true)
|
79
79
|
variant
|
80
80
|
end
|
81
81
|
|
@@ -148,7 +148,7 @@ THIS IS THE BEST PRODUCT EVER!
|
|
148
148
|
|
149
149
|
product.description = description
|
150
150
|
|
151
|
-
|
151
|
+
stub_spree_preferences(show_raw_product_description: true)
|
152
152
|
description = product_description(product)
|
153
153
|
expect(description).to eq(description)
|
154
154
|
end
|
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
|
-
RSpec.describe Spree::AppConfiguration
|
5
|
+
RSpec.describe Spree::AppConfiguration do
|
6
6
|
let(:prefs) { Spree::Config }
|
7
7
|
|
8
|
+
around do |example|
|
9
|
+
with_unfrozen_spree_preference_store do
|
10
|
+
example.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
it "should be available from the environment" do
|
9
15
|
prefs.layout = "my/layout"
|
10
16
|
expect(prefs.layout).to eq "my/layout"
|
@@ -52,4 +58,8 @@ RSpec.describe Spree::AppConfiguration, type: :model do
|
|
52
58
|
expect(prefs.admin_vat_location.state_id).to eq(nil)
|
53
59
|
expect(prefs.admin_vat_location.country_id).to eq(nil)
|
54
60
|
end
|
61
|
+
|
62
|
+
it 'has default Event adapter' do
|
63
|
+
expect(prefs.events.adapter).to eq Spree::Event::Adapters::ActiveSupportNotifications
|
64
|
+
end
|
55
65
|
end
|
@@ -77,5 +77,18 @@ RSpec.describe Spree::Core::ControllerHelpers::Pricing, type: :controller do
|
|
77
77
|
it { is_expected.to be_nil }
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
context "from context" do
|
82
|
+
subject { controller.current_pricing_options }
|
83
|
+
|
84
|
+
let(:store) { FactoryBot.create :store, default_currency: 'USD' }
|
85
|
+
|
86
|
+
context "when the whole context is passed" do
|
87
|
+
it "receives the right object " do
|
88
|
+
expect(Spree::Config.pricing_options_class).to receive(:from_context).with(controller)
|
89
|
+
is_expected.to be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
80
93
|
end
|
81
94
|
end
|
@@ -23,14 +23,7 @@ RSpec.describe Spree::Core::ControllerHelpers::StrongParameters, type: :controll
|
|
23
23
|
|
24
24
|
describe '#permitted_checkout_attributes' do
|
25
25
|
it 'returns Array class' do
|
26
|
-
|
27
|
-
expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'is deprecated' do
|
32
|
-
expect(Spree::Deprecation).to receive(:warn)
|
33
|
-
controller.permitted_checkout_attributes
|
26
|
+
expect(controller.permitted_checkout_attributes.class).to eq Array
|
34
27
|
end
|
35
28
|
end
|
36
29
|
|
@@ -17,7 +17,7 @@ RSpec.describe 'shipping method factory' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'store using alternate currency' do
|
20
|
-
before {
|
20
|
+
before { stub_spree_preferences(currency: 'CAD') }
|
21
21
|
|
22
22
|
it "should configure the calculator correctly" do
|
23
23
|
shipping_method = create(factory)
|
@@ -4,7 +4,16 @@ require 'rails_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Spree::TestingSupport::Preferences do
|
6
6
|
describe 'resetting the app configuration' do
|
7
|
+
around do |example|
|
8
|
+
with_unfrozen_spree_preference_store do
|
9
|
+
Spree::Deprecation.silence do
|
10
|
+
example.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
before do
|
16
|
+
reset_spree_preferences
|
8
17
|
@original_spree_mails_from = Spree::Config.mails_from
|
9
18
|
@original_spree_searcher_class = Spree::Config.searcher_class
|
10
19
|
class MySearcherClass; end
|
@@ -25,4 +34,28 @@ RSpec.describe Spree::TestingSupport::Preferences do
|
|
25
34
|
expect(Spree::Config.searcher_class).to eq(@original_spree_searcher_class)
|
26
35
|
end
|
27
36
|
end
|
37
|
+
|
38
|
+
describe '#stub_spree_preferences' do
|
39
|
+
it 'stubs method calls but does not affect actual stored Spree::Config settings' do
|
40
|
+
stub_spree_preferences(currency: 'FOO')
|
41
|
+
expect(Spree::Config.currency).to eq 'FOO'
|
42
|
+
expect(Spree::Config.preference_store[:currency]).to eq 'USD'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#with_unfrozen_spree_preference_store' do
|
47
|
+
it 'changes the original settings, but returns them to original values at exit' do
|
48
|
+
with_unfrozen_spree_preference_store do
|
49
|
+
Spree::Config.mails_from = 'override@example.com'
|
50
|
+
expect(Spree::Config.mails_from).to eq 'override@example.com'
|
51
|
+
expect(Spree::Config.preference_store[:mails_from]).to eq 'override@example.com'
|
52
|
+
end
|
53
|
+
|
54
|
+
# both the original frozen store and the unfrozen store are unaffected by changes above:
|
55
|
+
expect(Spree::Config.mails_from).to eq 'store@example.com'
|
56
|
+
with_unfrozen_spree_preference_store do
|
57
|
+
expect(Spree::Config.mails_from).to eq 'store@example.com'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
28
61
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'spree/event'
|
5
|
+
|
6
|
+
RSpec.describe Spree::Event do
|
7
|
+
module M
|
8
|
+
include Spree::Event::Subscriber
|
9
|
+
|
10
|
+
event_action :event_name
|
11
|
+
|
12
|
+
def event_name(event)
|
13
|
+
# code that handles the event
|
14
|
+
end
|
15
|
+
|
16
|
+
def other_event(event)
|
17
|
+
# ...
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '::subscribe!' do
|
22
|
+
before { M.unsubscribe! }
|
23
|
+
|
24
|
+
it 'adds new listeners to Spree::Event' do
|
25
|
+
expect { M.subscribe! }.to change { Spree::Event.listeners }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when subscriptions are not registered' do
|
29
|
+
it 'does not trigger the event callback' do
|
30
|
+
expect(M).not_to receive(:event_name)
|
31
|
+
Spree::Event.fire 'event_name'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'subscribes event actions' do
|
36
|
+
M.subscribe!
|
37
|
+
expect(M).to receive(:event_name)
|
38
|
+
Spree::Event.fire 'event_name'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not subscribe event actions more than once' do
|
42
|
+
2.times { M.subscribe! }
|
43
|
+
expect(M).to receive(:event_name).once
|
44
|
+
Spree::Event.fire 'event_name'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '::unsubscribe' do
|
49
|
+
before { M.subscribe! }
|
50
|
+
|
51
|
+
it 'removes the subscription' do
|
52
|
+
expect(M).not_to receive(:event_name)
|
53
|
+
M.unsubscribe!
|
54
|
+
Spree::Event.fire 'event_name'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '::event_action' do
|
59
|
+
context 'when the action has not been declared' do
|
60
|
+
before { M.subscribe! }
|
61
|
+
|
62
|
+
it 'does not subscribe the action' do
|
63
|
+
expect(M).not_to receive(:other_event)
|
64
|
+
Spree::Event.fire 'other_event'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when the action is declared' do
|
69
|
+
before do
|
70
|
+
M.event_action :other_event
|
71
|
+
M.subscribe!
|
72
|
+
end
|
73
|
+
|
74
|
+
after do
|
75
|
+
M.unsubscribe!
|
76
|
+
M.event_actions.delete(:other_event)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'subscribe the action' do
|
80
|
+
expect(M).to receive(:other_event)
|
81
|
+
Spree::Event.fire 'other_event'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|