solidus_core 2.9.0.rc.1 → 2.9.0
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/subscribers/spree/mailer_subscriber.rb +25 -0
- data/lib/generators/spree/install/install_generator.rb +21 -16
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +26 -1
- data/lib/spree/app_configuration.rb +45 -47
- data/lib/spree/core/class_constantizer.rb +6 -0
- data/lib/spree/core/engine.rb +9 -3
- 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/version.rb +1 -1
- data/lib/spree/core.rb +1 -0
- data/lib/spree/event/configuration.rb +8 -0
- data/lib/spree/event.rb +7 -1
- data/lib/spree/promo/environment.rb +6 -7
- data/{spec/support/shared_contexts → lib/spree/testing_support}/rake.rb +0 -0
- data/spec/lib/spree/app_configuration_spec.rb +75 -0
- data/spec/lib/spree/core/class_constantizer_spec.rb +20 -0
- data/spec/lib/spree/core/environment_extension_spec.rb +22 -23
- data/spec/lib/spree/event/subscriber_spec.rb +1 -1
- data/spec/lib/spree/event_spec.rb +39 -13
- data/spec/lib/spree/promo/environment_spec.rb +53 -0
- data/spec/models/spree/order_spec.rb +5 -5
- data/spec/rails_helper.rb +1 -0
- metadata +6 -4
- data/lib/spree/event/processors/mailer_processor.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0094b02cd702626b2e096ec98561a32fb8493227a6e5fa265f66abae656fdaf3'
|
4
|
+
data.tar.gz: 79dbb067dacfc98477078c1a48e812c6d5ac19596c897f573dcd892e8504b2d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2a0aa8d08f5474ab3e531d5b50b667650183e175daf4ed2f2e4ac2d1b9cbdab012a90bb9ccb488624b1a56eaf460faa07f3a56e566d5075d58bb10c7275317
|
7
|
+
data.tar.gz: 7daf2551e03bf901f010279aa59deb43ea215e0456b27e5cbf80e70d843ae54b41a47a92e1dbcc13f0a7bb720cf2d7805478bf69cffcc5611457f798436b6856
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spree/event/subscriber'
|
4
|
+
|
5
|
+
module Spree
|
6
|
+
module MailerSubscriber
|
7
|
+
include Spree::Event::Subscriber
|
8
|
+
|
9
|
+
event_action :order_finalized
|
10
|
+
event_action :send_reimbursement_email, event_name: :reimbursement_reimbursed
|
11
|
+
|
12
|
+
def order_finalized(event)
|
13
|
+
order = event.payload[:order]
|
14
|
+
unless order.confirmation_delivered?
|
15
|
+
Spree::Config.order_mailer_class.confirm_email(order).deliver_later
|
16
|
+
order.update_column(:confirmation_delivered, true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_reimbursement_email(event)
|
21
|
+
reimbursement = event.payload[:reimbursement]
|
22
|
+
Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -79,35 +79,40 @@ module Spree
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def configure_application
|
82
|
-
application <<-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
application <<-RUBY
|
83
|
+
# Load application's model / class decorators
|
84
|
+
initializer 'spree.decorators' do |app|
|
85
|
+
config.to_prepare do
|
86
|
+
Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
|
87
|
+
require_dependency(path)
|
88
|
+
end
|
88
89
|
end
|
90
|
+
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
# Load application's view overrides
|
93
|
+
initializer 'spree.overrides' do |app|
|
94
|
+
config.to_prepare do
|
95
|
+
Dir.glob(Rails.root.join('app/overrides/*.rb')) do |path|
|
96
|
+
require_dependency(path)
|
97
|
+
end
|
93
98
|
end
|
94
99
|
end
|
95
|
-
|
100
|
+
RUBY
|
96
101
|
|
97
102
|
if !options[:enforce_available_locales].nil?
|
98
|
-
application <<-
|
103
|
+
application <<-RUBY
|
99
104
|
# Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
|
100
105
|
I18n.enforce_available_locales = #{options[:enforce_available_locales]}
|
101
|
-
|
106
|
+
RUBY
|
102
107
|
end
|
103
108
|
end
|
104
109
|
|
105
110
|
def include_seed_data
|
106
|
-
append_file "db/seeds.rb", <<-
|
111
|
+
append_file "db/seeds.rb", <<-RUBY.strip_heredoc
|
107
112
|
|
108
113
|
Spree::Core::Engine.load_seed if defined?(Spree::Core)
|
109
114
|
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
|
110
|
-
|
115
|
+
RUBY
|
111
116
|
end
|
112
117
|
|
113
118
|
def install_migrations
|
@@ -157,7 +162,7 @@ module Spree
|
|
157
162
|
routes_file_path = File.join('config', 'routes.rb')
|
158
163
|
unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
|
159
164
|
insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
|
160
|
-
<<-
|
165
|
+
<<-RUBY
|
161
166
|
# This line mounts Solidus's routes at the root of your application.
|
162
167
|
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
|
163
168
|
# If you would like to change where this engine is mounted, simply change the :at option to something different.
|
@@ -165,7 +170,7 @@ module Spree
|
|
165
170
|
# We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
|
166
171
|
#{CORE_MOUNT_ROUTE}, at: '/'
|
167
172
|
|
168
|
-
|
173
|
+
RUBY
|
169
174
|
end
|
170
175
|
end
|
171
176
|
|
@@ -22,6 +22,14 @@ Spree.config do |config|
|
|
22
22
|
config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
|
23
23
|
config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
|
24
24
|
|
25
|
+
|
26
|
+
# Permission Sets:
|
27
|
+
|
28
|
+
# Uncomment and customize the following line to add custom permission sets
|
29
|
+
# to a custom users role:
|
30
|
+
# config.roles.assign_permissions :role_name, ['Spree::PermissionSets::CustomPermissionSet']
|
31
|
+
|
32
|
+
|
25
33
|
# Frontend:
|
26
34
|
|
27
35
|
# Custom logo for the frontend
|
@@ -39,8 +47,11 @@ Spree.config do |config|
|
|
39
47
|
# Gateway credentials can be configured statically here and referenced from
|
40
48
|
# the admin. They can also be fully configured from the admin.
|
41
49
|
#
|
50
|
+
# Please note that you need to use the solidus_stripe gem to have
|
51
|
+
# Stripe working: https://github.com/solidusio-contrib/solidus_stripe
|
52
|
+
#
|
42
53
|
# config.static_model_preferences.add(
|
43
|
-
# Spree::
|
54
|
+
# Spree::PaymentMethod::StripeCreditCard,
|
44
55
|
# 'stripe_env_credentials',
|
45
56
|
# secret_key: ENV['STRIPE_SECRET_KEY'],
|
46
57
|
# publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'],
|
@@ -58,6 +69,15 @@ end
|
|
58
69
|
<% if defined?(Spree::Backend::Engine) -%>
|
59
70
|
Spree::Backend::Config.configure do |config|
|
60
71
|
config.locale = 'en'
|
72
|
+
|
73
|
+
# Uncomment and change the following configuration if you want to add
|
74
|
+
# a new menu item:
|
75
|
+
#
|
76
|
+
# config.menu_items << config.class::MenuItem.new(
|
77
|
+
# [:section],
|
78
|
+
# 'icon-name',
|
79
|
+
# url: 'https://solidus.io/'
|
80
|
+
# )
|
61
81
|
end
|
62
82
|
<% end -%>
|
63
83
|
|
@@ -68,3 +88,8 @@ end
|
|
68
88
|
<% end -%>
|
69
89
|
|
70
90
|
Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
|
91
|
+
|
92
|
+
# If you want to add a field to the whitelisted ransackable attributes,
|
93
|
+
# just uncomment the following code and change it as you need.
|
94
|
+
#
|
95
|
+
# Spree::Model.whitelisted_ransackable_attributes << 'field'
|
@@ -475,6 +475,27 @@ module Spree
|
|
475
475
|
|
476
476
|
def environment
|
477
477
|
@environment ||= Spree::Core::Environment.new(self).tap do |env|
|
478
|
+
env.calculators.promotion_actions_create_adjustments = %w[
|
479
|
+
Spree::Calculator::FlatPercentItemTotal
|
480
|
+
Spree::Calculator::FlatRate
|
481
|
+
Spree::Calculator::FlexiRate
|
482
|
+
Spree::Calculator::TieredPercent
|
483
|
+
Spree::Calculator::TieredFlatRate
|
484
|
+
]
|
485
|
+
|
486
|
+
env.calculators.promotion_actions_create_item_adjustments = %w[
|
487
|
+
Spree::Calculator::DistributedAmount
|
488
|
+
Spree::Calculator::FlatRate
|
489
|
+
Spree::Calculator::FlexiRate
|
490
|
+
Spree::Calculator::PercentOnLineItem
|
491
|
+
Spree::Calculator::TieredPercent
|
492
|
+
]
|
493
|
+
|
494
|
+
env.calculators.promotion_actions_create_quantity_adjustments = %w[
|
495
|
+
Spree::Calculator::PercentOnLineItem
|
496
|
+
Spree::Calculator::FlatRate
|
497
|
+
]
|
498
|
+
|
478
499
|
env.calculators.shipping_methods = %w[
|
479
500
|
Spree::Calculator::Shipping::FlatPercentItemTotal
|
480
501
|
Spree::Calculator::Shipping::FlatRate
|
@@ -487,11 +508,6 @@ module Spree
|
|
487
508
|
Spree::Calculator::DefaultTax
|
488
509
|
]
|
489
510
|
|
490
|
-
env.stock_splitters = %w[
|
491
|
-
Spree::Stock::Splitter::ShippingCategory
|
492
|
-
Spree::Stock::Splitter::Backordered
|
493
|
-
]
|
494
|
-
|
495
511
|
env.payment_methods = %w[
|
496
512
|
Spree::PaymentMethod::BogusCreditCard
|
497
513
|
Spree::PaymentMethod::SimpleBogusCreditCard
|
@@ -499,53 +515,35 @@ module Spree
|
|
499
515
|
Spree::PaymentMethod::Check
|
500
516
|
]
|
501
517
|
|
502
|
-
env.promotions =
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
]
|
517
|
-
|
518
|
-
promos.actions = %w[
|
519
|
-
Spree::Promotion::Actions::CreateAdjustment
|
520
|
-
Spree::Promotion::Actions::CreateItemAdjustments
|
521
|
-
Spree::Promotion::Actions::CreateQuantityAdjustments
|
522
|
-
Spree::Promotion::Actions::FreeShipping
|
523
|
-
]
|
524
|
-
|
525
|
-
promos.shipping_actions = %w[
|
526
|
-
Spree::Promotion::Actions::FreeShipping
|
527
|
-
]
|
528
|
-
end
|
518
|
+
env.promotions.rules = %w[
|
519
|
+
Spree::Promotion::Rules::ItemTotal
|
520
|
+
Spree::Promotion::Rules::Product
|
521
|
+
Spree::Promotion::Rules::User
|
522
|
+
Spree::Promotion::Rules::FirstOrder
|
523
|
+
Spree::Promotion::Rules::UserLoggedIn
|
524
|
+
Spree::Promotion::Rules::OneUsePerUser
|
525
|
+
Spree::Promotion::Rules::Taxon
|
526
|
+
Spree::Promotion::Rules::NthOrder
|
527
|
+
Spree::Promotion::Rules::OptionValue
|
528
|
+
Spree::Promotion::Rules::FirstRepeatPurchaseSince
|
529
|
+
Spree::Promotion::Rules::UserRole
|
530
|
+
Spree::Promotion::Rules::Store
|
531
|
+
]
|
529
532
|
|
530
|
-
env.
|
531
|
-
Spree::
|
532
|
-
Spree::
|
533
|
-
Spree::
|
534
|
-
Spree::
|
535
|
-
Spree::Calculator::TieredFlatRate
|
533
|
+
env.promotions.actions = %w[
|
534
|
+
Spree::Promotion::Actions::CreateAdjustment
|
535
|
+
Spree::Promotion::Actions::CreateItemAdjustments
|
536
|
+
Spree::Promotion::Actions::CreateQuantityAdjustments
|
537
|
+
Spree::Promotion::Actions::FreeShipping
|
536
538
|
]
|
537
539
|
|
538
|
-
env.
|
539
|
-
Spree::
|
540
|
-
Spree::Calculator::FlatRate
|
541
|
-
Spree::Calculator::FlexiRate
|
542
|
-
Spree::Calculator::PercentOnLineItem
|
543
|
-
Spree::Calculator::TieredPercent
|
540
|
+
env.promotions.shipping_actions = %w[
|
541
|
+
Spree::Promotion::Actions::FreeShipping
|
544
542
|
]
|
545
543
|
|
546
|
-
env.
|
547
|
-
Spree::
|
548
|
-
Spree::
|
544
|
+
env.stock_splitters = %w[
|
545
|
+
Spree::Stock::Splitter::ShippingCategory
|
546
|
+
Spree::Stock::Splitter::Backordered
|
549
547
|
]
|
550
548
|
end
|
551
549
|
end
|
@@ -18,10 +18,16 @@ module Spree
|
|
18
18
|
klasses.each do |klass|
|
19
19
|
self << klass
|
20
20
|
end
|
21
|
+
|
22
|
+
self
|
21
23
|
end
|
22
24
|
|
23
25
|
delegate :clear, :empty?, to: :@collection
|
24
26
|
|
27
|
+
def delete(object)
|
28
|
+
@collection.delete(object.to_s)
|
29
|
+
end
|
30
|
+
|
25
31
|
def each
|
26
32
|
@collection.each do |klass|
|
27
33
|
yield klass.constantize
|
data/lib/spree/core/engine.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spree/config'
|
4
|
-
require 'spree/event/processors/mailer_processor'
|
5
4
|
|
6
5
|
module Spree
|
7
6
|
module Core
|
@@ -45,8 +44,15 @@ module Spree
|
|
45
44
|
Migrations.new(config, engine_name).check
|
46
45
|
end
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
# Setup Event Subscribers
|
48
|
+
initializer 'spree.core.initialize_subscribers' do |app|
|
49
|
+
app.reloader.to_prepare do
|
50
|
+
Spree::Event.subscribers.each(&:subscribe!)
|
51
|
+
end
|
52
|
+
|
53
|
+
app.reloader.before_class_unload do
|
54
|
+
Spree::Event.subscribers.each(&:unsubscribe!)
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
# Load in mailer previews for apps to use in development.
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree/core.rb
CHANGED
@@ -59,6 +59,7 @@ require 'spree/core/active_merchant_dependencies'
|
|
59
59
|
require 'spree/core/class_constantizer'
|
60
60
|
require 'spree/core/environment_extension'
|
61
61
|
require 'spree/core/environment/calculators'
|
62
|
+
require 'spree/core/environment/promotions'
|
62
63
|
require 'spree/core/environment'
|
63
64
|
require 'spree/promo/environment'
|
64
65
|
require 'spree/migrations'
|
@@ -1,8 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'spree/core/class_constantizer'
|
4
|
+
|
3
5
|
module Spree
|
4
6
|
module Event
|
5
7
|
class Configuration
|
8
|
+
def subscribers
|
9
|
+
@subscribers ||= ::Spree::Core::ClassConstantizer::Set.new.tap do |set|
|
10
|
+
set << 'Spree::MailerSubscriber'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
attr_writer :adapter, :suffix
|
7
15
|
|
8
16
|
def adapter
|
data/lib/spree/event.rb
CHANGED
@@ -21,7 +21,7 @@ module Spree
|
|
21
21
|
# @order.finalize!
|
22
22
|
# end
|
23
23
|
def fire(event_name, opts = {})
|
24
|
-
adapter.fire name_with_suffix(event_name), opts do
|
24
|
+
adapter.fire name_with_suffix(event_name.to_s), opts do
|
25
25
|
yield opts if block_given?
|
26
26
|
end
|
27
27
|
end
|
@@ -98,6 +98,12 @@ module Spree
|
|
98
98
|
Spree::Config.events.suffix
|
99
99
|
end
|
100
100
|
|
101
|
+
# @!attribute [r] subscribers
|
102
|
+
# @return [Array<Spree::Event::Subscriber>] A list of subscribers used to support class reloading for Spree::Event::Subscriber instances
|
103
|
+
def subscribers
|
104
|
+
Spree::Config.events.subscribers
|
105
|
+
end
|
106
|
+
|
101
107
|
private
|
102
108
|
|
103
109
|
def name_with_suffix(name)
|
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
module Promo
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
Environment =
|
6
|
+
ActiveSupport::Deprecation::DeprecatedConstantProxy.new(
|
7
|
+
'Spree::Promo::Environment',
|
8
|
+
'Spree::Core::Environment::Promotions',
|
9
|
+
Spree::Deprecation
|
10
|
+
)
|
12
11
|
end
|
13
12
|
end
|
File without changes
|
@@ -53,6 +53,81 @@ RSpec.describe Spree::AppConfiguration do
|
|
53
53
|
end
|
54
54
|
end
|
55
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
|
+
|
56
131
|
it 'has a default admin VAT location with nil values by default' do
|
57
132
|
expect(prefs.admin_vat_location).to eq(Spree::Tax::TaxLocation.new)
|
58
133
|
expect(prefs.admin_vat_location.state_id).to eq(nil)
|
@@ -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
|
@@ -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
|
@@ -14,21 +14,21 @@ RSpec.describe Spree::Event do
|
|
14
14
|
expect(subject.adapter).to eql Spree::Event::Adapters::ActiveSupportNotifications
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
after do
|
28
|
+
notifier.instance_variable_set '@subscribers', @old_subscribers
|
29
|
+
notifier.instance_variable_set '@listeners_for', @old_listeners
|
30
|
+
end
|
30
31
|
|
31
|
-
context 'with the default adapter' do
|
32
32
|
describe '#listeners' do
|
33
33
|
context 'when there is no subscription' do
|
34
34
|
it { expect(subject.listeners).to be_empty }
|
@@ -89,4 +89,30 @@ RSpec.describe Spree::Event do
|
|
89
89
|
end
|
90
90
|
end
|
91
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
|
92
118
|
end
|
@@ -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
|
@@ -29,14 +29,14 @@ RSpec.describe Spree::Order, type: :model do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# These specs show how notifications can be removed, one at a time or
|
32
|
-
# all the ones set by
|
32
|
+
# all the ones set by MailerSubscriber module
|
33
33
|
context 'when removing the default email notification subscription' do
|
34
34
|
before do
|
35
|
-
Spree::Event.unsubscribe Spree::
|
35
|
+
Spree::Event.unsubscribe Spree::MailerSubscriber.order_finalized_handler
|
36
36
|
end
|
37
37
|
|
38
38
|
after do
|
39
|
-
Spree::
|
39
|
+
Spree::MailerSubscriber.subscribe!
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'does not send the email' do
|
@@ -47,11 +47,11 @@ RSpec.describe Spree::Order, type: :model do
|
|
47
47
|
|
48
48
|
context 'when removing all the email notification subscriptions' do
|
49
49
|
before do
|
50
|
-
Spree::
|
50
|
+
Spree::MailerSubscriber.unsubscribe!
|
51
51
|
end
|
52
52
|
|
53
53
|
after do
|
54
|
-
Spree::
|
54
|
+
Spree::MailerSubscriber.subscribe!
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not send the email' do
|
data/spec/rails_helper.rb
CHANGED
@@ -18,6 +18,7 @@ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
|
18
18
|
|
19
19
|
require 'spree/testing_support/factories'
|
20
20
|
require 'spree/testing_support/preferences'
|
21
|
+
require 'spree/testing_support/rake'
|
21
22
|
require 'cancan/matchers'
|
22
23
|
|
23
24
|
ActiveJob::Base.queue_adapter = :test
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.0
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -635,6 +635,7 @@ files:
|
|
635
635
|
- app/models/spree/wallet_payment_source.rb
|
636
636
|
- app/models/spree/zone.rb
|
637
637
|
- app/models/spree/zone_member.rb
|
638
|
+
- app/subscribers/spree/mailer_subscriber.rb
|
638
639
|
- app/views/layouts/spree/base_mailer.html.erb
|
639
640
|
- app/views/spree/carton_mailer/shipped_email.html.erb
|
640
641
|
- app/views/spree/carton_mailer/shipped_email.text.erb
|
@@ -729,6 +730,7 @@ files:
|
|
729
730
|
- lib/spree/core/engine.rb
|
730
731
|
- lib/spree/core/environment.rb
|
731
732
|
- lib/spree/core/environment/calculators.rb
|
733
|
+
- lib/spree/core/environment/promotions.rb
|
732
734
|
- lib/spree/core/environment_extension.rb
|
733
735
|
- lib/spree/core/importer.rb
|
734
736
|
- lib/spree/core/importer/order.rb
|
@@ -746,7 +748,6 @@ files:
|
|
746
748
|
- lib/spree/event.rb
|
747
749
|
- lib/spree/event/adapters/active_support_notifications.rb
|
748
750
|
- lib/spree/event/configuration.rb
|
749
|
-
- lib/spree/event/processors/mailer_processor.rb
|
750
751
|
- lib/spree/event/subscriber.rb
|
751
752
|
- lib/spree/i18n.rb
|
752
753
|
- lib/spree/localized_number.rb
|
@@ -866,6 +867,7 @@ files:
|
|
866
867
|
- lib/spree/testing_support/order_walkthrough.rb
|
867
868
|
- lib/spree/testing_support/partial_double_verification.rb
|
868
869
|
- lib/spree/testing_support/preferences.rb
|
870
|
+
- lib/spree/testing_support/rake.rb
|
869
871
|
- lib/spree/testing_support/sequences.rb
|
870
872
|
- lib/spree/testing_support/shared_examples/gallery.rb
|
871
873
|
- lib/spree/testing_support/url_helpers.rb
|
@@ -969,6 +971,7 @@ files:
|
|
969
971
|
- spec/lib/spree/migrations_spec.rb
|
970
972
|
- spec/lib/spree/money_spec.rb
|
971
973
|
- spec/lib/spree/permission_sets/default_customer_spec.rb
|
974
|
+
- spec/lib/spree/promo/environment_spec.rb
|
972
975
|
- spec/lib/tasks/dummy_task.rake
|
973
976
|
- spec/lib/tasks/dummy_task_spec.rb
|
974
977
|
- spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb
|
@@ -1204,7 +1207,6 @@ files:
|
|
1204
1207
|
- spec/support/concerns/payment_source.rb
|
1205
1208
|
- spec/support/concerns/working_factories.rb
|
1206
1209
|
- spec/support/dummy_ability.rb
|
1207
|
-
- spec/support/shared_contexts/rake.rb
|
1208
1210
|
- vendor/assets/javascripts/jquery.payment.js
|
1209
1211
|
- vendor/assets/javascripts/jsuri.js
|
1210
1212
|
- vendor/assets/stylesheets/normalize.css
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module Event
|
5
|
-
module Processors
|
6
|
-
module MailerProcessor
|
7
|
-
include Spree::Event::Subscriber
|
8
|
-
|
9
|
-
event_action :order_finalized
|
10
|
-
event_action :send_reimbursement_email, event_name: :reimbursement_reimbursed
|
11
|
-
|
12
|
-
def order_finalized(event)
|
13
|
-
order = event.payload[:order]
|
14
|
-
unless order.confirmation_delivered?
|
15
|
-
Spree::Config.order_mailer_class.confirm_email(order).deliver_later
|
16
|
-
order.update_column(:confirmation_delivered, true)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def send_reimbursement_email(event)
|
21
|
-
reimbursement = event.payload[:reimbursement]
|
22
|
-
Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|