solidus_support 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 290b6b3d8d102c5a9346057f08c18b039395082f0d4a8ee7b59cff3f110d57a1
4
- data.tar.gz: f6354f111b2875c3baac252f4046498f7f0e69cb7189f9d86a8c050a389c1c39
3
+ metadata.gz: c78d734eb4b421be9efa6eb57baee461ef4fe899bb1d734b17f9b467aa6856fd
4
+ data.tar.gz: eb7ac669aed3124a9b418862abfb9daaaf9f9b6493e278363f437f09bad37c00
5
5
  SHA512:
6
- metadata.gz: 193f63e10976f25a5b167603d53c0b9187e6edd2928dc2a5a56fb32b1599d58eec9afff4335a2dca4de6bd322e6b484a7866f8a19e3c5aebe6b69d6d2d426dd3
7
- data.tar.gz: 602577640b806f17fd30d5bd90bda6b21bfd6fdf73b74674b88ae288365f1a5bb3eced6897e239fb3b2a415c396c2ed2612fdcc9ca87712c427b461194ac73d8
6
+ metadata.gz: 9db377ce30fbb4818a7e6a29440b8fd61310f84227e5e9c1f1e21d97c7c14ade8609aed46e4e1abc23afb2e116cef98202597cae4defefe331df6b4b69722bf2
7
+ data.tar.gz: aa70ce113298641e54738f9362717150d9261744e23ef17d6377724bdfc361882571f2647652273a83ec35bdd20fac89e3630352e92d32601d380dd472512099
data/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased](https://github.com/solidusio/solidus_support/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.8.1...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Release 0.5.2 version [\#64](https://github.com/solidusio/solidus_support/issues/64)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Compatibility layer for the legacy/new event system [\#70](https://github.com/solidusio/solidus_support/pull/70) ([waiting-for-dev](https://github.com/waiting-for-dev))
14
+ - Fix dependency on the engines load order when adding paths [\#65](https://github.com/solidusio/solidus_support/pull/65) ([waiting-for-dev](https://github.com/waiting-for-dev))
15
+ - Remove support for Solidus \<= 2.3 [\#62](https://github.com/solidusio/solidus_support/pull/62) ([elia](https://github.com/elia))
16
+ - Update the changelog with the latest releases [\#61](https://github.com/solidusio/solidus_support/pull/61) ([elia](https://github.com/elia))
17
+
18
+ ## [v0.8.1](https://github.com/solidusio/solidus_support/tree/v0.8.1) (2021-01-27)
19
+
20
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.8.0...v0.8.1)
21
+
22
+ **Merged pull requests:**
23
+
24
+ - Fix combined\_first\_and\_last\_name\_in\_address version [\#59](https://github.com/solidusio/solidus_support/pull/59) ([kennyadsl](https://github.com/kennyadsl))
25
+
26
+ ## [v0.8.0](https://github.com/solidusio/solidus_support/tree/v0.8.0) (2021-01-19)
27
+
28
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.7.0...v0.8.0)
29
+
30
+ **Implemented enhancements:**
31
+
32
+ - Add a method to check if combined address name is being used [\#58](https://github.com/solidusio/solidus_support/pull/58) ([kennyadsl](https://github.com/kennyadsl))
33
+
34
+ **Fixed bugs:**
35
+
36
+ - Fix project' specs [\#57](https://github.com/solidusio/solidus_support/pull/57) ([kennyadsl](https://github.com/kennyadsl))
37
+
3
38
  ## [v0.7.0](https://github.com/solidusio/solidus_support/tree/v0.7.0) (2020-10-28)
4
39
 
5
40
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.6.0...v0.7.0)
@@ -10,9 +45,9 @@
10
45
 
11
46
  **Merged pull requests:**
12
47
 
13
- - Use `Spree::Event. activate\_all\_subscribers` when available [\#53](https://github.com/solidusio/solidus_support/pull/53) ([spaghetticode](https://github.com/spaghetticode))
48
+ - Use `Spree::Event. activate_all_subscribers` when available [\#53](https://github.com/solidusio/solidus_support/pull/53) ([spaghetticode](https://github.com/spaghetticode))
14
49
  - Support Rails 5.1.x [\#51](https://github.com/solidusio/solidus_support/pull/51) ([brchristian](https://github.com/brchristian))
15
- - Remove redundant `solidus\_core` dev dependency [\#50](https://github.com/solidusio/solidus_support/pull/50) ([brchristian](https://github.com/brchristian))
50
+ - Remove redundant `solidus_core` dev dependency [\#50](https://github.com/solidusio/solidus_support/pull/50) ([brchristian](https://github.com/brchristian))
16
51
 
17
52
  ## [v0.6.0](https://github.com/solidusio/solidus_support/tree/v0.6.0) (2020-07-24)
18
53
 
@@ -50,7 +85,11 @@
50
85
  **Merged pull requests:**
51
86
 
52
87
  - Load Solidus engine extension files automatically [\#42](https://github.com/solidusio/solidus_support/pull/42) ([aldesantis](https://github.com/aldesantis))
88
+ - Update solidus\_dev\_support [\#41](https://github.com/solidusio/solidus_support/pull/41) ([aldesantis](https://github.com/aldesantis))
89
+ - Replace manual cache checks w/ require\_dependency [\#39](https://github.com/solidusio/solidus_support/pull/39) ([elia](https://github.com/elia))
90
+ - Fixes isse when zeitwerk is not enabled [\#38](https://github.com/solidusio/solidus_support/pull/38) ([softr8](https://github.com/softr8))
53
91
  - Deprecate SolidusSupport.solidus\_gem\_version [\#37](https://github.com/solidusio/solidus_support/pull/37) ([kennyadsl](https://github.com/kennyadsl))
92
+ - Spring cleaning [\#33](https://github.com/solidusio/solidus_support/pull/33) ([aldesantis](https://github.com/aldesantis))
54
93
 
55
94
  ## [v0.4.1](https://github.com/solidusio/solidus_support/tree/v0.4.1) (2020-01-16)
56
95
 
@@ -61,13 +100,6 @@
61
100
  - Should use require\_dependency instead of require/load [\#34](https://github.com/solidusio/solidus_support/issues/34)
62
101
  - Add a LICENSE [\#20](https://github.com/solidusio/solidus_support/issues/20)
63
102
 
64
- **Merged pull requests:**
65
-
66
- - Update solidus\_dev\_support [\#41](https://github.com/solidusio/solidus_support/pull/41) ([aldesantis](https://github.com/aldesantis))
67
- - Replace manual cache checks w/ require\_dependency [\#39](https://github.com/solidusio/solidus_support/pull/39) ([elia](https://github.com/elia))
68
- - Fixes isse when zeitwerk is not enabled [\#38](https://github.com/solidusio/solidus_support/pull/38) ([softr8](https://github.com/softr8))
69
- - Spring cleaning [\#33](https://github.com/solidusio/solidus_support/pull/33) ([aldesantis](https://github.com/aldesantis))
70
-
71
103
  ## [v0.4.0](https://github.com/solidusio/solidus_support/tree/v0.4.0) (2019-12-16)
72
104
 
73
105
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.3.2...v0.4.0)
@@ -95,7 +127,7 @@
95
127
  - Add `capybara-screenshot` dependency [\#23](https://github.com/solidusio/solidus_support/pull/23) ([spaghetticode](https://github.com/spaghetticode))
96
128
  - Do not reset spree preferences starting from v2.9 [\#22](https://github.com/solidusio/solidus_support/pull/22) ([kennyadsl](https://github.com/kennyadsl))
97
129
  - Update Travis config [\#19](https://github.com/solidusio/solidus_support/pull/19) ([aitbw](https://github.com/aitbw))
98
- - Override Capybara JS driver via `CAPYBARA\_DRIVER` ENV variable [\#18](https://github.com/solidusio/solidus_support/pull/18) ([spaghetticode](https://github.com/spaghetticode))
130
+ - Override Capybara JS driver via `CAPYBARA_DRIVER` ENV variable [\#18](https://github.com/solidusio/solidus_support/pull/18) ([spaghetticode](https://github.com/spaghetticode))
99
131
  - Migrate from Poltergeist to Headless Chrome [\#16](https://github.com/solidusio/solidus_support/pull/16) ([aitbw](https://github.com/aitbw))
100
132
  - Remove running rubocop on rake task [\#14](https://github.com/solidusio/solidus_support/pull/14) ([kennyadsl](https://github.com/kennyadsl))
101
133
  - Cleanup extension [\#13](https://github.com/solidusio/solidus_support/pull/13) ([kennyadsl](https://github.com/kennyadsl))
@@ -15,9 +15,9 @@ module SolidusSupport
15
15
 
16
16
  config.to_prepare(&method(:activate))
17
17
 
18
- enable_solidus_engine_support('backend') if SolidusSupport.backend_available?
19
- enable_solidus_engine_support('frontend') if SolidusSupport.frontend_available?
20
- enable_solidus_engine_support('api') if SolidusSupport.api_available?
18
+ enable_solidus_engine_support('backend')
19
+ enable_solidus_engine_support('frontend')
20
+ enable_solidus_engine_support('api')
21
21
  end
22
22
  end
23
23
 
@@ -32,7 +32,7 @@ module SolidusSupport
32
32
  # This allows to add event subscribers to extensions without explicitly subscribing them,
33
33
  # similarly to what happens in Solidus core.
34
34
  def load_solidus_subscribers_from(path)
35
- if defined? Spree::Event
35
+ if SolidusSupport::LegacyEventCompat.using_legacy?
36
36
  path.glob("**/*_subscriber.rb") do |subscriber_path|
37
37
  require_dependency(subscriber_path)
38
38
  end
@@ -82,17 +82,23 @@ module SolidusSupport
82
82
  #
83
83
  # @see #load_solidus_decorators_from
84
84
  def enable_solidus_engine_support(engine)
85
- paths['app/controllers'] << "lib/controllers/#{engine}"
86
- paths['app/views'] << "lib/views/#{engine}"
85
+ initializer "#{name}_#{engine}_paths", before: :initialize_dependency_mechanism do
86
+ if SolidusSupport.send(:"#{engine}_available?")
87
+ paths['app/controllers'] << "lib/controllers/#{engine}"
88
+ paths['app/views'] << "lib/views/#{engine}"
89
+ end
90
+ end
87
91
 
88
- path = root.join("lib/decorators/#{engine}")
92
+ if SolidusSupport.send(:"#{engine}_available?")
93
+ path = root.join("lib/decorators/#{engine}")
89
94
 
90
- config.autoload_paths += path.glob('*')
95
+ config.autoload_paths += path.glob('*')
91
96
 
92
- engine_context = self
93
- config.to_prepare do
94
- engine_context.instance_eval do
95
- load_solidus_decorators_from(path)
97
+ engine_context = self
98
+ config.to_prepare do
99
+ engine_context.instance_eval do
100
+ load_solidus_decorators_from(path)
101
+ end
96
102
  end
97
103
  end
98
104
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusSupport
4
+ module LegacyEventCompat
5
+ # Compatibility for some event-driven operations
6
+ module Bus
7
+ # Publication of an event
8
+ #
9
+ # If extensions want to support the legacy sytem, they need to use a
10
+ # compatible API. That means it's not possible to publish an instance as
11
+ # event, which is something supported by Omnes but not the legacy adapter.
12
+ # Instead, a payload can be given. E.g.:
13
+ #
14
+ # ```
15
+ # SolidusSupport::LegacyEventCompat::Bus.publish(:foo, bar: :baz)
16
+ # ```
17
+ #
18
+ # Legacy subscribers will receive an
19
+ # `ActiveSupport::Notifications::Fanout`, while omnes subscribers will get
20
+ # an `Omnes::UnstructuredEvent`. Both instances are compatible as they
21
+ # implement a `#payload` method.
22
+ #
23
+ # @param event_name [Symbol]
24
+ # @param payload [Hash<Symbol, Any>]
25
+ def self.publish(event_name, **payload)
26
+ if SolidusSupport::LegacyEventCompat.using_legacy?
27
+ Spree::Event.fire(event_name, payload)
28
+ else
29
+ Spree::Bus.publish(event_name, **payload, caller_location: caller_locations(1)[0])
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "omnes"
5
+ rescue LoadError
6
+ end
7
+
8
+ module SolidusSupport
9
+ module LegacyEventCompat
10
+ # Compatibility for subscriber modules
11
+ #
12
+ # Thanks to this module, extensions can create legacy subscriber modules
13
+ # (see {Spree::Event::Subscriber}) and translate them automatically to an
14
+ # {Omnes::Subscriber}). E.g.:
15
+ #
16
+ # ```
17
+ # module MyExtension
18
+ # module MySubscriber
19
+ # include Spree::Event::Subscriber
20
+ # include SolidusSupport::LegacyEventCompat::Subscriber
21
+ #
22
+ # event_action :order_finalized
23
+ #
24
+ # def order_finalized(event)
25
+ # event.payload[:order].do_something
26
+ # end
27
+ # end
28
+ # end
29
+ #
30
+ # MyExtension::MySubscriber.omnes_subscriber.subscribe_to(Spree::Bus)
31
+ # ```
32
+ #
33
+ # The generated omnes subscriptions will call the corresponding legacy
34
+ # subscriber method with the omnes event. It'll compatible as long as the
35
+ # omnes event responds to the `#payload` method (see
36
+ # {Omnes::UnstructuredEvent}).
37
+ module Subscriber
38
+ # @api private
39
+ ADAPTER = lambda do |legacy_subscriber, legacy_subscriber_method, _omnes_subscriber, omnes_event|
40
+ legacy_subscriber.send(legacy_subscriber_method, omnes_event)
41
+ end
42
+
43
+ def self.included(legacy_subscriber)
44
+ legacy_subscriber.define_singleton_method(:omnes_subscriber) do
45
+ @omnes_subscriber ||= Class.new.include(::Omnes::Subscriber).tap do |subscriber|
46
+ legacy_subscriber.event_actions.each do |(legacy_subscriber_method, event_name)|
47
+ subscriber.handle(event_name.to_sym, with: ADAPTER.curry[legacy_subscriber, legacy_subscriber_method])
48
+ end
49
+ end.new
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_support/legacy_event_compat/bus'
4
+ require 'solidus_support/legacy_event_compat/subscriber'
5
+
6
+ module SolidusSupport
7
+ # Compatibility middleman for {Spree::Event} and {Spree::Bus}
8
+ #
9
+ # Solidus v3.2 changed to use [Omnes](https://github.com/nebulab/omnes) as the
10
+ # backbone for event-driven behavior (see {Spree::Bus}) by default. Before
11
+ # that, a custom adapter based on {ActiveSupport::Notifications} was used (see
12
+ # {Spree::Event}. Both systems are still supported on v3.2.
13
+ #
14
+ # This module provides compatibility support so that extensions can easily
15
+ # target both systems regardless of the underlying circumstances:
16
+ #
17
+ # - Solidus v3.2 with the new system.
18
+ # - Solidus v3.2 with the legacy system.
19
+ # - Solidus v2.9 to v3.1, when only {Spree::Event} existed.
20
+ # - Possible future versions of Solidus, whether the legacy system is
21
+ # eventually removed or not.
22
+ module LegacyEventCompat
23
+ # Returns whether the application is using the legacy event system
24
+ #
25
+ # @return [Boolean]
26
+ def self.using_legacy?
27
+ legacy_present? &&
28
+ (legacy_alone? ||
29
+ legacy_chosen?)
30
+ end
31
+
32
+ def self.legacy_present?
33
+ defined?(Spree::Event)
34
+ end
35
+ private_class_method :legacy_present?
36
+
37
+ def self.legacy_alone?
38
+ !Spree::Config.respond_to?(:use_legacy_events)
39
+ end
40
+ private_class_method :legacy_alone?
41
+
42
+ def self.legacy_chosen?
43
+ Spree::Config.use_legacy_events
44
+ end
45
+ private_class_method :legacy_chosen?
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusSupport
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'solidus_support/version'
4
4
  require 'solidus_support/migration'
5
+ require 'solidus_support/legacy_event_compat'
5
6
  require 'solidus_support/engine_extensions'
6
7
  require 'solidus_core'
7
8
 
@@ -32,27 +33,38 @@ module SolidusSupport
32
33
  end
33
34
 
34
35
  def new_gateway_code?
35
- first_version_with_new_gateway_code = Gem::Requirement.new('>= 2.3')
36
- first_version_with_new_gateway_code.satisfied_by?(Spree.solidus_gem_version)
36
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
37
+ SolidusSupport.new_gateway_code? is deprecated without replacement and will be removed
38
+ in solidus_support 1.0.
39
+ WARN
40
+
41
+ true
37
42
  end
38
43
 
39
44
  def payment_source_parent_class
40
- if new_gateway_code?
41
- Spree::PaymentSource
42
- else
43
- Spree::Base
44
- end
45
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
46
+ SolidusSupport.payment_source_parent_class is deprecated and will be removed
47
+ in solidus_support 1.0. Please use Spree::PaymentSource instead.
48
+ WARN
49
+
50
+ Spree::PaymentSource
45
51
  end
46
52
 
47
53
  def payment_method_parent_class(credit_card: false)
48
- if new_gateway_code?
49
- if credit_card
50
- Spree::PaymentMethod::CreditCard
51
- else
52
- Spree::PaymentMethod
53
- end
54
+ if credit_card
55
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
56
+ SolidusSupport.payment_method_parent_class(credit_card: true) is deprecated and will be removed
57
+ in solidus_support 1.0. Please use Spree::PaymentMethod::CreditCard instead.
58
+ WARN
59
+
60
+ Spree::PaymentMethod::CreditCard
54
61
  else
55
- Spree::Gateway
62
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
63
+ SolidusSupport.payment_method_parent_class(credit_card: false) is deprecated and will be removed
64
+ in solidus_support 1.0. Please use Spree::PaymentMethod instead.
65
+ WARN
66
+
67
+ Spree::PaymentMethod
56
68
  end
57
69
  end
58
70
 
@@ -28,4 +28,5 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'rubocop'
29
29
  s.add_development_dependency 'rubocop-rspec'
30
30
  s.add_development_dependency 'solidus_dev_support'
31
+ s.add_development_dependency 'omnes', '~> 0.2.2'
31
32
  end
data/spec/examples.txt CHANGED
@@ -1,9 +1,15 @@
1
- example_id | status | run_time |
2
- ----------------------------------------- | ------ | --------------- |
3
- ./spec/solidus_support_spec.rb[1:1:1:1] | passed | 0.00024 seconds |
4
- ./spec/solidus_support_spec.rb[1:1:2:1] | passed | 0.00028 seconds |
5
- ./spec/solidus_support_spec.rb[1:1:3:1:1] | passed | 0.00094 seconds |
6
- ./spec/solidus_support_spec.rb[1:1:3:2:1] | passed | 0.25256 seconds |
7
- ./spec/solidus_support_spec.rb[1:2:1:1] | passed | 0.00599 seconds |
8
- ./spec/solidus_support_spec.rb[1:2:2:1] | passed | 0.00026 seconds |
9
- ./spec/solidus_support_spec.rb[1:2:3:1] | passed | 0.0002 seconds |
1
+ example_id | status | run_time |
2
+ ----------------------------------------------------------------------------- | ------ | --------------- |
3
+ ./spec/solidus_support/legacy_event_compat/bus_spec.rb[1:1:1] | passed | 0.00525 seconds |
4
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:1] | passed | 0.00032 seconds |
5
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:2] | passed | 0.00026 seconds |
6
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:3] | passed | 0.00031 seconds |
7
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:4] | passed | 0.0006 seconds |
8
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:5] | passed | 0.00035 seconds |
9
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:6] | passed | 0.00019 seconds |
10
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:7] | passed | 0.00656 seconds |
11
+ ./spec/solidus_support_spec.rb[1:1:1:1] | passed | 0.00095 seconds |
12
+ ./spec/solidus_support_spec.rb[1:1:2:1] | passed | 1.11 seconds |
13
+ ./spec/solidus_support_spec.rb[1:2:1:1] | passed | 0.0055 seconds |
14
+ ./spec/solidus_support_spec.rb[1:2:2:1] | passed | 0.00081 seconds |
15
+ ./spec/solidus_support_spec.rb[1:2:3:1] | passed | 0.0003 seconds |
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SolidusSupport::LegacyEventCompat::Bus do
4
+ describe '#publish' do
5
+ if SolidusSupport::LegacyEventCompat.using_legacy?
6
+ it 'forwards to Spree::Event' do
7
+ box = nil
8
+ subscription = Spree::Event.subscribe(:foo) { |event| box = event.payload[:bar] }
9
+
10
+ described_class.publish(:foo, bar: :baz)
11
+
12
+ expect(box).to be(:baz)
13
+ ensure
14
+ Spree::Event.unsubscribe(subscription)
15
+ end
16
+ else
17
+ it 'forwards to Spree::Bus' do
18
+ box = nil
19
+ Spree::Bus.register(:foo)
20
+ subscription = Spree::Bus.subscribe(:foo) { |event| box = event.payload[:bar] }
21
+
22
+ described_class.publish(:foo, bar: :baz)
23
+
24
+ expect(box).to be(:baz)
25
+ ensure
26
+ Spree::Bus.unsubscribe(subscription)
27
+ Spree::Bus.registry.unregister(:foo)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omnes'
4
+
5
+ RSpec.describe SolidusSupport::LegacyEventCompat::Subscriber do
6
+ subject { Module.new.include(Spree::Event::Subscriber).include(described_class) }
7
+
8
+ describe '#omnes_subscriber' do
9
+ it 'returns an Omnes::Subscriber' do
10
+ subject.module_eval do
11
+ event_action :foo
12
+
13
+ def foo(_event); end
14
+ end
15
+
16
+ expect(subject.omnes_subscriber.is_a?(Omnes::Subscriber)).to be(true)
17
+ end
18
+
19
+ it 'adds single-event definitions matching legacy event actions' do
20
+ subject.module_eval do
21
+ event_action :foo
22
+
23
+ def foo(_event); end
24
+ end
25
+ bus = Omnes::Bus.new
26
+ bus.register(:foo)
27
+
28
+ subscriptions = subject.omnes_subscriber.subscribe_to(bus)
29
+
30
+ event = Struct.new(:omnes_event_name).new(:foo)
31
+ expect(subscriptions.first.matches?(event)).to be(true)
32
+ end
33
+
34
+ it 'coerces event names given as Strings' do
35
+ subject.module_eval do
36
+ event_action 'foo'
37
+
38
+ def foo(_event); end
39
+ end
40
+ bus = Omnes::Bus.new
41
+ bus.register(:foo)
42
+
43
+ subscriptions = subject.omnes_subscriber.subscribe_to(bus)
44
+
45
+ event = Struct.new(:omnes_event_name).new(:foo)
46
+ expect(subscriptions.first.matches?(event)).to be(true)
47
+ end
48
+
49
+ it 'executes legacy event action methods as handlers with the omnes event' do
50
+ subject.module_eval do
51
+ event_action :foo
52
+
53
+ def foo(event)
54
+ event[:bar]
55
+ end
56
+ end
57
+ bus = Omnes::Bus.new
58
+ bus.register(:foo)
59
+
60
+ subscriptions = subject.omnes_subscriber.subscribe_to(bus)
61
+
62
+ expect(
63
+ bus.publish(:foo, bar: :baz).executions.first.result
64
+ ).to be(:baz)
65
+ end
66
+
67
+ it 'distingish when event name is given explicitly' do
68
+ subject.module_eval do
69
+ event_action :foo, event_name: :bar
70
+
71
+ def foo(_event)
72
+ :bar
73
+ end
74
+ end
75
+ bus = Omnes::Bus.new
76
+ bus.register(:bar)
77
+
78
+ subscriptions = subject.omnes_subscriber.subscribe_to(bus)
79
+
80
+ expect(
81
+ bus.publish(:bar).executions.first.result
82
+ ).to be(:bar)
83
+ end
84
+
85
+ it "returns the same omnes subscriber instance if called again" do
86
+ expect(subject.omnes_subscriber).to be(subject.omnes_subscriber)
87
+ end
88
+
89
+ it "doesn't fail when no event action has been defined" do
90
+ expect { subject.omnes_subscriber }.not_to raise_error
91
+ end
92
+ end
93
+ end
@@ -12,35 +12,18 @@ RSpec.describe SolidusSupport do
12
12
  end
13
13
  end
14
14
 
15
- context 'with Solidus < 2.3' do
16
- let(:solidus_version) { '2.2.1' }
17
-
18
- it { is_expected.to eq(Spree::Gateway) }
19
- end
20
-
21
- context 'with Solidus >= 2.3' do
15
+ context 'with credit_card: false' do
22
16
  let(:solidus_version) { '2.3.1' }
23
17
 
24
18
  it { is_expected.to eq(Spree::PaymentMethod) }
25
19
  end
26
20
 
27
- # rubocop:disable RSpec/NestedGroups
28
21
  context 'with credit_card: true' do
29
22
  let(:credit_card) { true }
23
+ let(:solidus_version) { '2.3.1' }
30
24
 
31
- context 'with Solidus < 2.3' do
32
- let(:solidus_version) { '2.2.1' }
33
-
34
- it { is_expected.to eq(Spree::Gateway) }
35
- end
36
-
37
- context 'with Solidus >= 2.3' do
38
- let(:solidus_version) { '2.3.1' }
39
-
40
- it { is_expected.to eq(Spree::PaymentMethod::CreditCard) }
41
- end
25
+ it { is_expected.to eq(Spree::PaymentMethod::CreditCard) }
42
26
  end
43
- # rubocop:enable RSpec/NestedGroups
44
27
  end
45
28
 
46
29
  describe '.combined_first_and_last_name_in_address?' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,7 +108,21 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ - !ruby/object:Gem::Dependency
112
+ name: omnes
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.2.2
125
+ description:
112
126
  email: john@stembolt.com
113
127
  executables: []
114
128
  extensions: []
@@ -129,10 +143,15 @@ files:
129
143
  - bin/setup
130
144
  - lib/solidus_support.rb
131
145
  - lib/solidus_support/engine_extensions.rb
146
+ - lib/solidus_support/legacy_event_compat.rb
147
+ - lib/solidus_support/legacy_event_compat/bus.rb
148
+ - lib/solidus_support/legacy_event_compat/subscriber.rb
132
149
  - lib/solidus_support/migration.rb
133
150
  - lib/solidus_support/version.rb
134
151
  - solidus_support.gemspec
135
152
  - spec/examples.txt
153
+ - spec/solidus_support/legacy_event_compat/bus_spec.rb
154
+ - spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb
136
155
  - spec/solidus_support_spec.rb
137
156
  - spec/spec_helper.rb
138
157
  - spec/support/dummy_app.rb
@@ -141,7 +160,7 @@ homepage: https://github.com/solidusio/solidus_support
141
160
  licenses:
142
161
  - BSD-3-Clause
143
162
  metadata: {}
144
- post_install_message:
163
+ post_install_message:
145
164
  rdoc_options: []
146
165
  require_paths:
147
166
  - lib
@@ -156,12 +175,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
175
  - !ruby/object:Gem::Version
157
176
  version: '0'
158
177
  requirements: []
159
- rubygems_version: 3.1.4
160
- signing_key:
178
+ rubygems_version: 3.0.3.1
179
+ signing_key:
161
180
  specification_version: 4
162
181
  summary: Common runtime helpers for Solidus extensions.
163
182
  test_files:
164
183
  - spec/spec_helper.rb
184
+ - spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb
185
+ - spec/solidus_support/legacy_event_compat/bus_spec.rb
165
186
  - spec/examples.txt
166
187
  - spec/solidus_support_spec.rb
167
188
  - spec/support/dummy_app.rb