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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71217c9617a1dc11ee7ffa67f022200e9cc9e5e81f0d79fad8712e6264f30d7b
4
- data.tar.gz: 2a51df897566b8347205712578172e75cb3ea4d5b8852c98c6a99cdb6de5e40c
3
+ metadata.gz: '0094b02cd702626b2e096ec98561a32fb8493227a6e5fa265f66abae656fdaf3'
4
+ data.tar.gz: 79dbb067dacfc98477078c1a48e812c6d5ac19596c897f573dcd892e8504b2d1
5
5
  SHA512:
6
- metadata.gz: 713cea25167eb830ff1274b1e2b8ca163342f28ebd89e0d148a963dff83fc94d038def70e4713b255cd5df05448580fba1cfbcbd968d1a80dae3429be1dc90f8
7
- data.tar.gz: 1b1b5b6321c5df0de1e9bafda1d6cae35b53c8c59671137aefd0cba54a05b457ae1f3ef26b38302dd4ef16780364de0e4591db40b919e370d498c78ee0d990a5
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 <<-APP
83
-
84
- config.to_prepare do
85
- # Load application's model / class decorators
86
- Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
87
- require_dependency(c)
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
- # Load application's view overrides
91
- Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
92
- require_dependency(c)
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
- APP
100
+ RUBY
96
101
 
97
102
  if !options[:enforce_available_locales].nil?
98
- application <<-APP
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
- APP
106
+ RUBY
102
107
  end
103
108
  end
104
109
 
105
110
  def include_seed_data
106
- append_file "db/seeds.rb", <<-SEEDS.strip_heredoc
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
- SEEDS
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
- <<-ROUTES
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
- ROUTES
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::Gateway::StripeGateway,
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 = Spree::Promo::Environment.new.tap do |promos|
503
- promos.rules = %w[
504
- Spree::Promotion::Rules::ItemTotal
505
- Spree::Promotion::Rules::Product
506
- Spree::Promotion::Rules::User
507
- Spree::Promotion::Rules::FirstOrder
508
- Spree::Promotion::Rules::UserLoggedIn
509
- Spree::Promotion::Rules::OneUsePerUser
510
- Spree::Promotion::Rules::Taxon
511
- Spree::Promotion::Rules::NthOrder
512
- Spree::Promotion::Rules::OptionValue
513
- Spree::Promotion::Rules::FirstRepeatPurchaseSince
514
- Spree::Promotion::Rules::UserRole
515
- Spree::Promotion::Rules::Store
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.calculators.promotion_actions_create_adjustments = %w[
531
- Spree::Calculator::FlatPercentItemTotal
532
- Spree::Calculator::FlatRate
533
- Spree::Calculator::FlexiRate
534
- Spree::Calculator::TieredPercent
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.calculators.promotion_actions_create_item_adjustments = %w[
539
- Spree::Calculator::DistributedAmount
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.calculators.promotion_actions_create_quantity_adjustments = %w[
547
- Spree::Calculator::PercentOnLineItem
548
- Spree::Calculator::FlatRate
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
@@ -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
- initializer 'spree.core.subscribe_event_mailer_processor' do
49
- Spree::Event::Processors::MailerProcessor.subscribe!
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.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ class Environment
6
+ class Promotions
7
+ include EnvironmentExtension
8
+
9
+ add_class_set :rules
10
+ add_class_set :actions
11
+ add_class_set :shipping_actions
12
+ end
13
+ end
14
+ end
15
+ end
@@ -15,7 +15,7 @@ module Spree
15
15
  def initialize(spree_config)
16
16
  @calculators = Calculators.new
17
17
  @preferences = spree_config
18
- @promotions = Spree::Promo::Environment.new
18
+ @promotions = Promotions.new
19
19
  end
20
20
  end
21
21
  end
@@ -22,10 +22,6 @@ module Spree
22
22
  end
23
23
  end
24
24
  end
25
-
26
- def add_class(name)
27
- singleton_class.send(:add_class_set, name)
28
- end
29
25
  end
30
26
  end
31
27
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "2.9.0.rc.1"
4
+ VERSION = "2.9.0"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
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
- class Environment
6
- include Core::EnvironmentExtension
7
-
8
- add_class_set :rules
9
- add_class_set :actions
10
- add_class_set :shipping_actions
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
@@ -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
- subject { DummyClass.new }
7
+ let(:base) { Class.new }
8
+ subject! { base.include(described_class).new }
16
9
 
17
- before { subject.add_class('random_name') }
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
- describe 'Basis' do
20
- it { respond_to?(:random_name) }
21
- it { respond_to?(:random_name=) }
22
- end
14
+ let(:class_one) { String }
15
+ let(:class_two) { Array }
16
+ let(:class_three) { Hash }
23
17
 
24
- describe '#getter' do
25
- it { expect(subject.random_name).to be_empty }
26
- it { expect(subject.random_name).to be_kind_of Spree::Core::ClassConstantizer::Set }
27
- end
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
- describe '#setter' do
30
- before { subject.random_name = [C1, C2]; @set = subject.random_name.to_a }
27
+ before { subject.foo = [class_one, class_two] }
31
28
 
32
- it { expect(@set).to include(C1) }
33
- it { expect(@set).to include(C2) }
34
- it { expect(@set).not_to include(C3) }
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
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
  require 'spree/event'
5
5
 
6
- RSpec.describe Spree::Event do
6
+ RSpec.describe Spree::Event::Subscriber do
7
7
  module M
8
8
  include Spree::Event::Subscriber
9
9
 
@@ -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
- before do
18
- # ActiveSupport::Notifications does not provide an interface to clean all
19
- # subscribers at once, so some low level brittle code is required
20
- @old_subscribers = notifier.instance_variable_get('@subscribers').dup
21
- @old_listeners = notifier.instance_variable_get('@listeners_for').dup
22
- notifier.instance_variable_get('@subscribers').clear
23
- notifier.instance_variable_get('@listeners_for').clear
24
- end
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
- after do
27
- notifier.instance_variable_set '@subscribers', @old_subscribers
28
- notifier.instance_variable_set '@listeners_for', @old_listeners
29
- end
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 MailerProcessor module
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::Event::Processors::MailerProcessor.order_finalized_handler
35
+ Spree::Event.unsubscribe Spree::MailerSubscriber.order_finalized_handler
36
36
  end
37
37
 
38
38
  after do
39
- Spree::Event::Processors::MailerProcessor.subscribe!
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::Event::Processors::MailerProcessor.unsubscribe!
50
+ Spree::MailerSubscriber.unsubscribe!
51
51
  end
52
52
 
53
53
  after do
54
- Spree::Event::Processors::MailerProcessor.subscribe!
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.rc.1
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-01 00:00:00.000000000 Z
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