solidus_core 2.8.6 → 2.9.0
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/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/paperclip_attachment.rb +55 -0
- data/app/models/spree/image.rb +2 -44
- 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/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.rb +18 -11
- 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/paperclip_attachment.rb +21 -0
- data/app/models/spree/taxon.rb +4 -11
- data/app/models/spree/taxonomy.rb +2 -0
- data/app/models/spree/unit_cancel.rb +12 -1
- data/app/models/spree/variant/pricing_options.rb +10 -0
- data/app/models/spree/variant.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +26 -10
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +25 -0
- 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 +21 -19
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +29 -1
- data/lib/solidus/migrations/rename_gateways.rb +2 -0
- data/lib/spree/app_configuration.rb +69 -47
- data/lib/spree/core/class_constantizer.rb +6 -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 +11 -0
- data/lib/spree/core/environment/promotions.rb +15 -0
- data/lib/spree/core/environment.rb +1 -1
- data/lib/spree/core/environment_extension.rb +0 -4
- 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/core.rb +2 -0
- data/lib/spree/deprecation.rb +50 -0
- data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
- data/lib/spree/event/configuration.rb +25 -0
- data/lib/spree/event/subscriber.rb +84 -0
- data/lib/spree/event.rb +117 -0
- data/lib/spree/permitted_attributes.rb +7 -76
- data/lib/spree/promo/environment.rb +6 -7
- 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/lib/spree/app_configuration_spec.rb +140 -0
- data/spec/lib/spree/core/class_constantizer_spec.rb +20 -0
- 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/environment_extension_spec.rb +22 -23
- 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 +118 -0
- data/spec/lib/spree/money_spec.rb +3 -9
- data/spec/lib/spree/promo/environment_spec.rb +53 -0
- 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/rails_helper.rb +1 -0
- data/spec/spec_helper.rb +0 -4
- data/spec/support/concerns/default_price.rb +8 -0
- metadata +21 -6
- data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
- data/spec/models/spree/app_configuration_spec.rb +0 -55
- /data/{spec/support/shared_contexts → lib/spree/testing_support}/rake.rb +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Spree::AppConfiguration do
|
|
6
|
+
let(:prefs) { Spree::Config }
|
|
7
|
+
|
|
8
|
+
around do |example|
|
|
9
|
+
with_unfrozen_spree_preference_store do
|
|
10
|
+
example.run
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should be available from the environment" do
|
|
15
|
+
prefs.layout = "my/layout"
|
|
16
|
+
expect(prefs.layout).to eq "my/layout"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should be available as Spree::Config for legacy access" do
|
|
20
|
+
expect(Spree::Config).to be_a Spree::AppConfiguration
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "uses base searcher class by default" do
|
|
24
|
+
expect(prefs.searcher_class).to eq Spree::Core::Search::Base
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "uses variant search class by default" do
|
|
28
|
+
expect(prefs.variant_search_class).to eq Spree::Core::Search::Variant
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "uses variant price selector class by default" do
|
|
32
|
+
expect(prefs.variant_price_selector_class).to eq Spree::Variant::PriceSelector
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "has a getter for the pricing options class provided by the variant price selector class" do
|
|
36
|
+
expect(prefs.pricing_options_class).to eq Spree::Variant::PriceSelector.pricing_options_class
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#stock' do
|
|
40
|
+
subject { prefs.stock }
|
|
41
|
+
it { is_expected.to be_a Spree::Core::StockConfiguration }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '@default_country_iso_code' do
|
|
45
|
+
it 'is the USA by default' do
|
|
46
|
+
expect(prefs[:default_country_iso]).to eq("US")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '@admin_vat_country_iso' do
|
|
51
|
+
it 'is `nil` by default' do
|
|
52
|
+
expect(prefs[:admin_vat_country_iso]).to eq(nil)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#environment' do
|
|
57
|
+
class DummyClass; end;
|
|
58
|
+
|
|
59
|
+
subject(:environment) { prefs.environment }
|
|
60
|
+
it { is_expected.to be_a Spree::Core::Environment }
|
|
61
|
+
|
|
62
|
+
shared_examples "working preferences set" do
|
|
63
|
+
it "allows adding new items" do
|
|
64
|
+
preferences_set << DummyClass
|
|
65
|
+
expect(preferences_set).to include DummyClass
|
|
66
|
+
preferences_set.delete DummyClass
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context '.payment_methods' do
|
|
71
|
+
subject(:preferences_set) { environment.payment_methods }
|
|
72
|
+
it_should_behave_like "working preferences set"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context '.stock_splitters' do
|
|
76
|
+
subject(:preferences_set) { environment.stock_splitters }
|
|
77
|
+
it_should_behave_like "working preferences set"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context '.calculators' do
|
|
81
|
+
subject(:calculators) { environment.calculators }
|
|
82
|
+
it { is_expected.to be_a Spree::Core::Environment::Calculators }
|
|
83
|
+
|
|
84
|
+
context '.calculators.shipping_methods' do
|
|
85
|
+
subject(:preferences_set) { calculators.shipping_methods }
|
|
86
|
+
it_should_behave_like "working preferences set"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context '.calculators.tax_rates' do
|
|
90
|
+
subject(:preferences_set) { calculators.tax_rates }
|
|
91
|
+
it_should_behave_like "working preferences set"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context '.calculators.promotion_actions_create_adjustments' do
|
|
95
|
+
subject(:preferences_set) { calculators.promotion_actions_create_adjustments }
|
|
96
|
+
it_should_behave_like "working preferences set"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
context '.calculators.promotion_actions_create_item_adjustments' do
|
|
100
|
+
subject(:preferences_set) { calculators.promotion_actions_create_item_adjustments }
|
|
101
|
+
it_should_behave_like "working preferences set"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context '.calculators.promotion_actions_create_quantity_adjustments' do
|
|
105
|
+
subject(:preferences_set) { calculators.promotion_actions_create_quantity_adjustments }
|
|
106
|
+
it_should_behave_like "working preferences set"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context '.promotions' do
|
|
111
|
+
subject(:promotions) { environment.promotions }
|
|
112
|
+
it { is_expected.to be_a Spree::Core::Environment::Promotions }
|
|
113
|
+
|
|
114
|
+
context '.promotions.rules' do
|
|
115
|
+
subject(:preferences_set) { promotions.rules }
|
|
116
|
+
it_should_behave_like "working preferences set"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context '.promotions.actions' do
|
|
120
|
+
subject(:preferences_set) { promotions.actions }
|
|
121
|
+
it_should_behave_like "working preferences set"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context '.promotions.shipping_actions' do
|
|
125
|
+
subject(:preferences_set) { promotions.shipping_actions }
|
|
126
|
+
it_should_behave_like "working preferences set"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'has a default admin VAT location with nil values by default' do
|
|
132
|
+
expect(prefs.admin_vat_location).to eq(Spree::Tax::TaxLocation.new)
|
|
133
|
+
expect(prefs.admin_vat_location.state_id).to eq(nil)
|
|
134
|
+
expect(prefs.admin_vat_location.country_id).to eq(nil)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'has default Event adapter' do
|
|
138
|
+
expect(prefs.events.adapter).to eq Spree::Event::Adapters::ActiveSupportNotifications
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -29,6 +29,10 @@ RSpec.describe Spree::Core::ClassConstantizer::Set do
|
|
|
29
29
|
expect(set).to include(ClassConstantizerTest::ClassA)
|
|
30
30
|
expect(set).to include(ClassConstantizerTest::ClassB)
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
it "returns itself" do
|
|
34
|
+
expect(set.concat(['String'])).to eql(set)
|
|
35
|
+
end
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
describe "<<" do
|
|
@@ -68,4 +72,20 @@ RSpec.describe Spree::Core::ClassConstantizer::Set do
|
|
|
68
72
|
end
|
|
69
73
|
end
|
|
70
74
|
end
|
|
75
|
+
|
|
76
|
+
describe "#delete" do
|
|
77
|
+
before do
|
|
78
|
+
set << ClassConstantizerTest::ClassA
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "can delete by string" do
|
|
82
|
+
set.delete "ClassConstantizerTest::ClassA"
|
|
83
|
+
expect(set).not_to include(ClassConstantizerTest::ClassA)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "can delete by class" do
|
|
87
|
+
set.delete ClassConstantizerTest::ClassA
|
|
88
|
+
expect(set).not_to include(ClassConstantizerTest::ClassA)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
71
91
|
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
|
|
|
@@ -3,34 +3,33 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require 'spree/core/environment_extension'
|
|
5
5
|
|
|
6
|
-
class DummyClass
|
|
7
|
-
include Spree::Core::EnvironmentExtension
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class C1; end
|
|
11
|
-
class C2; end
|
|
12
|
-
class C3; end
|
|
13
|
-
|
|
14
6
|
RSpec.describe Spree::Core::EnvironmentExtension do
|
|
15
|
-
|
|
7
|
+
let(:base) { Class.new }
|
|
8
|
+
subject! { base.include(described_class).new }
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
describe '.add_class_set' do
|
|
11
|
+
context 'with a class set named "foo"' do
|
|
12
|
+
before { base.add_class_set('foo') }
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
14
|
+
let(:class_one) { String }
|
|
15
|
+
let(:class_two) { Array }
|
|
16
|
+
let(:class_three) { Hash }
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
describe '#foo' do
|
|
19
|
+
it { respond_to?(:foo) }
|
|
20
|
+
it { expect(subject.foo).to be_empty }
|
|
21
|
+
it { expect(subject.foo).to be_kind_of Spree::Core::ClassConstantizer::Set }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#foo=' do
|
|
25
|
+
it { respond_to?(:foo=) }
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
before { subject.random_name = [C1, C2]; @set = subject.random_name.to_a }
|
|
27
|
+
before { subject.foo = [class_one, class_two] }
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
it { expect(subject.foo).to include(class_one) }
|
|
30
|
+
it { expect(subject.foo).to include(class_two) }
|
|
31
|
+
it { expect(subject.foo).not_to include(class_three) }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -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::Subscriber 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
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'spree/event'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Spree::Event do
|
|
7
|
+
let(:subscription_name) { 'foo_bar' }
|
|
8
|
+
let(:item) { spy('object') }
|
|
9
|
+
let(:notifier) { ActiveSupport::Notifications.notifier }
|
|
10
|
+
|
|
11
|
+
subject { described_class }
|
|
12
|
+
|
|
13
|
+
it 'has default adapter' do
|
|
14
|
+
expect(subject.adapter).to eql Spree::Event::Adapters::ActiveSupportNotifications
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'with the default adapter' do
|
|
18
|
+
before do
|
|
19
|
+
# ActiveSupport::Notifications does not provide an interface to clean all
|
|
20
|
+
# subscribers at once, so some low level brittle code is required
|
|
21
|
+
@old_subscribers = notifier.instance_variable_get('@subscribers').dup
|
|
22
|
+
@old_listeners = notifier.instance_variable_get('@listeners_for').dup
|
|
23
|
+
notifier.instance_variable_get('@subscribers').clear
|
|
24
|
+
notifier.instance_variable_get('@listeners_for').clear
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
after do
|
|
28
|
+
notifier.instance_variable_set '@subscribers', @old_subscribers
|
|
29
|
+
notifier.instance_variable_set '@listeners_for', @old_listeners
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#listeners' do
|
|
33
|
+
context 'when there is no subscription' do
|
|
34
|
+
it { expect(subject.listeners).to be_empty }
|
|
35
|
+
|
|
36
|
+
context 'after adding a subscription' do
|
|
37
|
+
before do
|
|
38
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'includes the new subscription with custom suffix' do
|
|
42
|
+
expect(subject.listeners).to be_present
|
|
43
|
+
subscription_listeners = subject.listeners["#{subscription_name}.spree"]
|
|
44
|
+
expect(subscription_listeners).to be_a Array
|
|
45
|
+
expect(subscription_listeners.first).to be_a ActiveSupport::Notifications::Fanout::Subscribers::Timed
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'subscriptions' do
|
|
52
|
+
describe '#subscribe' do
|
|
53
|
+
it 'can subscribe to events' do
|
|
54
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
|
55
|
+
Spree::Event.fire subscription_name
|
|
56
|
+
expect(item).to have_received :do_something
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#unsubscribe' do
|
|
61
|
+
context 'when unsubscribing using a subscription object as reference' do
|
|
62
|
+
let!(:subscription) { Spree::Event.subscribe(subscription_name) { item.do_something } }
|
|
63
|
+
|
|
64
|
+
before do
|
|
65
|
+
Spree::Event.subscribe(subscription_name) { item.do_something_else }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'can unsubscribe from single event by object' do
|
|
69
|
+
subject.unsubscribe subscription
|
|
70
|
+
Spree::Event.fire subscription_name
|
|
71
|
+
expect(item).not_to have_received :do_something
|
|
72
|
+
expect(item).to have_received :do_something_else
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context 'when unsubscribing using a string as reference' do
|
|
77
|
+
before do
|
|
78
|
+
Spree::Event.subscribe(subscription_name) { item.do_something }
|
|
79
|
+
Spree::Event.subscribe(subscription_name) { item.do_something_else }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'can unsubscribe from multiple events with the same name' do
|
|
83
|
+
subject.unsubscribe subscription_name
|
|
84
|
+
Spree::Event.fire subscription_name
|
|
85
|
+
expect(item).not_to have_received :do_something
|
|
86
|
+
expect(item).not_to have_received :do_something_else
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe '.subscribers' do
|
|
94
|
+
let(:subscriber) { instance_double(Module, 'Subscriber') }
|
|
95
|
+
let(:subscriber_name) { instance_double(String, 'Subscriber name') }
|
|
96
|
+
|
|
97
|
+
before do
|
|
98
|
+
described_class.subscribers.clear
|
|
99
|
+
allow(subscriber).to receive(:name).and_return(subscriber_name)
|
|
100
|
+
allow(subscriber_name).to receive(:constantize).and_return(subscriber)
|
|
101
|
+
allow(subscriber_name).to receive(:to_s).and_return(subscriber_name)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'accepts the names of constants' do
|
|
105
|
+
Spree::Config.events.subscribers << subscriber_name
|
|
106
|
+
|
|
107
|
+
expect(described_class.subscribers.to_a).to eq([subscriber])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'discards duplicates' do
|
|
111
|
+
described_class.subscribers << subscriber_name
|
|
112
|
+
described_class.subscribers << subscriber_name
|
|
113
|
+
described_class.subscribers << subscriber_name
|
|
114
|
+
|
|
115
|
+
expect(described_class.subscribers.to_a).to eq([subscriber])
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -4,9 +4,7 @@ require 'rails_helper'
|
|
|
4
4
|
|
|
5
5
|
RSpec.describe Spree::Money do
|
|
6
6
|
before do
|
|
7
|
-
|
|
8
|
-
config.currency = "USD"
|
|
9
|
-
end
|
|
7
|
+
stub_spree_preferences(currency: "USD")
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
describe '#initialize' do
|
|
@@ -155,9 +153,7 @@ RSpec.describe Spree::Money do
|
|
|
155
153
|
|
|
156
154
|
context "JPY" do
|
|
157
155
|
before do
|
|
158
|
-
|
|
159
|
-
config.currency = "JPY"
|
|
160
|
-
end
|
|
156
|
+
stub_spree_preferences(currency: "JPY")
|
|
161
157
|
end
|
|
162
158
|
|
|
163
159
|
it "formats correctly" do
|
|
@@ -168,9 +164,7 @@ RSpec.describe Spree::Money do
|
|
|
168
164
|
|
|
169
165
|
context "EUR" do
|
|
170
166
|
before do
|
|
171
|
-
|
|
172
|
-
config.currency = "EUR"
|
|
173
|
-
end
|
|
167
|
+
stub_spree_preferences(currency: "EUR")
|
|
174
168
|
end
|
|
175
169
|
|
|
176
170
|
# Regression test for https://github.com/spree/spree/issues/2634
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'spree/core/environment/promotions'
|
|
5
|
+
require 'spree/promo/environment'
|
|
6
|
+
|
|
7
|
+
RSpec.describe 'Spree::Promo::Environment' do
|
|
8
|
+
it 'is deprecated' do
|
|
9
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
10
|
+
|
|
11
|
+
Spree::Promo::Environment.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when customized' do
|
|
15
|
+
after do
|
|
16
|
+
# This is needed to cleanup classes after the following specs run.
|
|
17
|
+
# They will add two new methods but we don't want them to be defined
|
|
18
|
+
# on the described class for specs that will run later.
|
|
19
|
+
Spree::Core::Environment::Promotions.remove_method :custom_rules, :custom_rules=
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'with class_eval' do
|
|
23
|
+
it 'raises a deprecation warning but keep changes' do
|
|
24
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
25
|
+
|
|
26
|
+
Spree::Promo::Environment.class_eval do
|
|
27
|
+
add_class_set :custom_rules
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
promo_environment_instance = Spree::Core::Environment::Promotions.new
|
|
31
|
+
expect(promo_environment_instance).to respond_to(:custom_rules)
|
|
32
|
+
expect(promo_environment_instance).to respond_to(:custom_rules=)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'with prepend' do
|
|
37
|
+
it 'raises a deprecation warning but keep changes' do
|
|
38
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
39
|
+
|
|
40
|
+
module CustomRules
|
|
41
|
+
def self.prepended(base)
|
|
42
|
+
base.add_class_set :custom_rules
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
Spree::Promo::Environment.prepend CustomRules
|
|
46
|
+
|
|
47
|
+
promo_environment_instance = Spree::Core::Environment::Promotions.new
|
|
48
|
+
expect(promo_environment_instance).to respond_to(:custom_rules)
|
|
49
|
+
expect(promo_environment_instance).to respond_to(:custom_rules=)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -11,9 +11,11 @@ RSpec.describe 'solidus:migrations:migrate_shipping_rate_taxes' do
|
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
it 'runs' do
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Spree::Deprecation.silence do
|
|
15
|
+
expect { task.invoke }.to output(
|
|
16
|
+
"Adding persisted tax notes to historic shipping rates ... Success.\n"
|
|
17
|
+
).to_stdout
|
|
18
|
+
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -109,7 +109,7 @@ RSpec.describe Spree::OrderMailer, type: :mailer do
|
|
|
109
109
|
|
|
110
110
|
context "with preference :send_core_emails set to false" do
|
|
111
111
|
it "sends no email" do
|
|
112
|
-
|
|
112
|
+
stub_spree_preferences(send_core_emails: false)
|
|
113
113
|
message = Spree::OrderMailer.confirm_email(order)
|
|
114
114
|
expect(message.body).to be_blank
|
|
115
115
|
end
|
|
@@ -6,6 +6,8 @@ RSpec.describe Spree::TestMailer, type: :mailer do
|
|
|
6
6
|
let(:user) { create(:user) }
|
|
7
7
|
|
|
8
8
|
it "confirm_email accepts a user id as an alternative to a User object" do
|
|
9
|
-
Spree::
|
|
9
|
+
Spree::Deprecation.silence do
|
|
10
|
+
Spree::TestMailer.test_email('test@example.com')
|
|
11
|
+
end
|
|
10
12
|
end
|
|
11
13
|
end
|
|
@@ -28,8 +28,9 @@ RSpec.describe Spree::Address, type: :model do
|
|
|
28
28
|
|
|
29
29
|
context 'address does not require state' do
|
|
30
30
|
before do
|
|
31
|
-
|
|
31
|
+
stub_spree_preferences(address_requires_state: false)
|
|
32
32
|
end
|
|
33
|
+
|
|
33
34
|
it "address_requires_state preference is false" do
|
|
34
35
|
address.state = nil
|
|
35
36
|
address.state_name = nil
|
|
@@ -39,7 +40,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
|
39
40
|
|
|
40
41
|
context 'address requires state' do
|
|
41
42
|
before do
|
|
42
|
-
|
|
43
|
+
stub_spree_preferences(address_requires_state: true)
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
it "state_name is not nil and country does not have any states" do
|
|
@@ -145,7 +146,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
|
145
146
|
|
|
146
147
|
context 'has a default country' do
|
|
147
148
|
before do
|
|
148
|
-
|
|
149
|
+
stub_spree_preferences(default_country_iso: default_country.iso)
|
|
149
150
|
end
|
|
150
151
|
|
|
151
152
|
it "sets up a new record with Spree::Config[:default_country_iso]" do
|
|
@@ -155,7 +156,7 @@ RSpec.describe Spree::Address, type: :model do
|
|
|
155
156
|
|
|
156
157
|
# Regression test for https://github.com/spree/spree/issues/1142
|
|
157
158
|
it "raises ActiveRecord::RecordNotFound if :default_country_iso is set to an invalid value" do
|
|
158
|
-
|
|
159
|
+
stub_spree_preferences(default_country_iso: "00")
|
|
159
160
|
expect {
|
|
160
161
|
Spree::Address.build_default.country
|
|
161
162
|
}.to raise_error(ActiveRecord::RecordNotFound)
|