solidus_support 0.8.0 → 0.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d0b61a92f9ea8174330391a7bad3543dc0725f68e9fd380011391e580abab75
4
- data.tar.gz: 269a38d161f392811ed2ec1c2a523b67a92557b7a9828c2c2639a2d504df06a6
3
+ metadata.gz: 8c47f29279cf2922b38a65fd166de8cbc1e2c220166f8c9f6a29a678591bcc7f
4
+ data.tar.gz: 597472813f4a5afa136d10c1be1f106bf66c277616a3d083d03fa5a9d33a467f
5
5
  SHA512:
6
- metadata.gz: 34ab8b557078b085cd966e3e45652ba7f20e4b26588f74a66f94da5f0dc7cd1824f68672d354656d346baa97bc1f8d3e37b469ab0871d5a247af1a7368b23bb2
7
- data.tar.gz: 4401a91bdecea435d21f175ea4c1dd77b3f68006ed6221338435e6e1f8a27de6b0533dfdb88ec3ab6401554125d0de187fd38ff7a77a99fc59350292734eab4f
6
+ metadata.gz: ba3d4fb41d2268a51f448da89adac7ffeb7f2b543c60db3f734f54e42a14b60dcf0332f2478ccf94cf9f64c053c98f7a71a631f86b4ac05362a0330b257a8569
7
+ data.tar.gz: 0c3f781f43b12300e52903e3b94d2f0b38d2da83b79b3719e21a6b2031ee45e6af9e8195df1d880888f4849d4e7071dc1671cf3448e5682aeeb39bc43107718d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.9.1](https://github.com/solidusio/solidus_support/tree/v0.9.1) (2022-06-01)
4
+
5
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.9.0...v0.9.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add extension paths before `initialize_cache` [\#71](https://github.com/solidusio/solidus_support/pull/71) ([gsmendoza](https://github.com/gsmendoza))
10
+
11
+ ## [v0.9.0](https://github.com/solidusio/solidus_support/tree/v0.9.0) (2022-05-25)
12
+
13
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.8.1...v0.9.0)
14
+
15
+ **Closed issues:**
16
+
17
+ - Release 0.5.2 version [\#64](https://github.com/solidusio/solidus_support/issues/64)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - 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))
22
+ - 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))
23
+ - Remove support for Solidus \<= 2.3 [\#62](https://github.com/solidusio/solidus_support/pull/62) ([elia](https://github.com/elia))
24
+ - Update the changelog with the latest releases [\#61](https://github.com/solidusio/solidus_support/pull/61) ([elia](https://github.com/elia))
25
+
26
+ ## [v0.8.1](https://github.com/solidusio/solidus_support/tree/v0.8.1) (2021-01-27)
27
+
28
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.8.0...v0.8.1)
29
+
30
+ **Merged pull requests:**
31
+
32
+ - Fix combined\_first\_and\_last\_name\_in\_address version [\#59](https://github.com/solidusio/solidus_support/pull/59) ([kennyadsl](https://github.com/kennyadsl))
33
+
34
+ ## [v0.8.0](https://github.com/solidusio/solidus_support/tree/v0.8.0) (2021-01-19)
35
+
36
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.7.0...v0.8.0)
37
+
38
+ **Implemented enhancements:**
39
+
40
+ - 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))
41
+
42
+ **Fixed bugs:**
43
+
44
+ - Fix project' specs [\#57](https://github.com/solidusio/solidus_support/pull/57) ([kennyadsl](https://github.com/kennyadsl))
45
+
3
46
  ## [v0.7.0](https://github.com/solidusio/solidus_support/tree/v0.7.0) (2020-10-28)
4
47
 
5
48
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.6.0...v0.7.0)
@@ -10,9 +53,9 @@
10
53
 
11
54
  **Merged pull requests:**
12
55
 
13
- - Use `Spree::Event. activate\_all\_subscribers` when available [\#53](https://github.com/solidusio/solidus_support/pull/53) ([spaghetticode](https://github.com/spaghetticode))
56
+ - Use `Spree::Event. activate_all_subscribers` when available [\#53](https://github.com/solidusio/solidus_support/pull/53) ([spaghetticode](https://github.com/spaghetticode))
14
57
  - 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))
58
+ - Remove redundant `solidus_core` dev dependency [\#50](https://github.com/solidusio/solidus_support/pull/50) ([brchristian](https://github.com/brchristian))
16
59
 
17
60
  ## [v0.6.0](https://github.com/solidusio/solidus_support/tree/v0.6.0) (2020-07-24)
18
61
 
@@ -50,7 +93,11 @@
50
93
  **Merged pull requests:**
51
94
 
52
95
  - Load Solidus engine extension files automatically [\#42](https://github.com/solidusio/solidus_support/pull/42) ([aldesantis](https://github.com/aldesantis))
96
+ - Update solidus\_dev\_support [\#41](https://github.com/solidusio/solidus_support/pull/41) ([aldesantis](https://github.com/aldesantis))
97
+ - Replace manual cache checks w/ require\_dependency [\#39](https://github.com/solidusio/solidus_support/pull/39) ([elia](https://github.com/elia))
98
+ - Fixes isse when zeitwerk is not enabled [\#38](https://github.com/solidusio/solidus_support/pull/38) ([softr8](https://github.com/softr8))
53
99
  - Deprecate SolidusSupport.solidus\_gem\_version [\#37](https://github.com/solidusio/solidus_support/pull/37) ([kennyadsl](https://github.com/kennyadsl))
100
+ - Spring cleaning [\#33](https://github.com/solidusio/solidus_support/pull/33) ([aldesantis](https://github.com/aldesantis))
54
101
 
55
102
  ## [v0.4.1](https://github.com/solidusio/solidus_support/tree/v0.4.1) (2020-01-16)
56
103
 
@@ -61,13 +108,6 @@
61
108
  - Should use require\_dependency instead of require/load [\#34](https://github.com/solidusio/solidus_support/issues/34)
62
109
  - Add a LICENSE [\#20](https://github.com/solidusio/solidus_support/issues/20)
63
110
 
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
111
  ## [v0.4.0](https://github.com/solidusio/solidus_support/tree/v0.4.0) (2019-12-16)
72
112
 
73
113
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.3.2...v0.4.0)
@@ -95,7 +135,7 @@
95
135
  - Add `capybara-screenshot` dependency [\#23](https://github.com/solidusio/solidus_support/pull/23) ([spaghetticode](https://github.com/spaghetticode))
96
136
  - Do not reset spree preferences starting from v2.9 [\#22](https://github.com/solidusio/solidus_support/pull/22) ([kennyadsl](https://github.com/kennyadsl))
97
137
  - 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))
138
+ - Override Capybara JS driver via `CAPYBARA_DRIVER` ENV variable [\#18](https://github.com/solidusio/solidus_support/pull/18) ([spaghetticode](https://github.com/spaghetticode))
99
139
  - Migrate from Poltergeist to Headless Chrome [\#16](https://github.com/solidusio/solidus_support/pull/16) ([aitbw](https://github.com/aitbw))
100
140
  - Remove running rubocop on rake task [\#14](https://github.com/solidusio/solidus_support/pull/14) ([kennyadsl](https://github.com/kennyadsl))
101
141
  - 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,40 @@ 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
+ # In the past, view and controller paths of Solidus extensions were
86
+ # added at extension loading time. As a result, if an extension
87
+ # customizing a Solidus engine is loaded before that engine
88
+ # (for example, the extension is declared before the `solidus_frontend`
89
+ # engine in the `Gemfile`), then the extension's paths for that Solidus
90
+ # engine wouldn't be loaded.
91
+
92
+ # The initializer below runs before `initialize_cache` because
93
+ # `initialize_cache` runs 1) after the Solidus engines have already
94
+ # loaded BUT 2) before Rails has added the paths to `$LOAD_PATH`.
95
+ # Normally, it would be sufficient to run the initializer below before
96
+ # the `set_load_path` initializer. However, external gems such as
97
+ # Deface may also change the load paths immediately before
98
+ # `set_load_path`. To ensure that our extension paths are not affected
99
+ # by those gems, we work around those gems by adding our paths before
100
+ # `initialize_cache`, which is the Rails initializer called before
101
+ # `set_load_path`.
102
+ initializer "#{name}_#{engine}_paths", before: :initialize_cache do
103
+ if SolidusSupport.send(:"#{engine}_available?")
104
+ paths['app/controllers'] << "lib/controllers/#{engine}"
105
+ paths['app/views'] << "lib/views/#{engine}"
106
+ end
107
+ end
87
108
 
88
- path = root.join("lib/decorators/#{engine}")
109
+ if SolidusSupport.send(:"#{engine}_available?")
110
+ path = root.join("lib/decorators/#{engine}")
89
111
 
90
- config.autoload_paths += path.glob('*')
112
+ config.autoload_paths += path.glob('*')
91
113
 
92
- engine_context = self
93
- config.to_prepare do
94
- engine_context.instance_eval do
95
- load_solidus_decorators_from(path)
114
+ engine_context = self
115
+ config.to_prepare do
116
+ engine_context.instance_eval do
117
+ load_solidus_decorators_from(path)
118
+ end
96
119
  end
97
120
  end
98
121
  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.0'
4
+ VERSION = '0.9.1'
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
 
@@ -22,7 +23,7 @@ module SolidusSupport
22
23
  end
23
24
 
24
25
  def combined_first_and_last_name_in_address?
25
- versions_before_preference = Gem::Requirement.new('< 2.10')
26
+ versions_before_preference = Gem::Requirement.new('< 2.11.0')
26
27
  versions_after_preference = Gem::Requirement.new('>= 3.0.0.alpha')
27
28
 
28
29
  return false if versions_before_preference.satisfied_by?(Spree.solidus_gem_version)
@@ -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.00015 seconds |
4
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:1] | passed | 0.00016 seconds |
5
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:2] | passed | 0.00021 seconds |
6
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:3] | passed | 0.00019 seconds |
7
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:4] | passed | 0.00025 seconds |
8
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:5] | passed | 0.00033 seconds |
9
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:6] | passed | 0.0006 seconds |
10
+ ./spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb[1:1:7] | passed | 0.00102 seconds |
11
+ ./spec/solidus_support_spec.rb[1:1:1:1] | passed | 0.00042 seconds |
12
+ ./spec/solidus_support_spec.rb[1:1:2:1] | passed | 0.21514 seconds |
13
+ ./spec/solidus_support_spec.rb[1:2:1:1] | passed | 0.00021 seconds |
14
+ ./spec/solidus_support_spec.rb[1:2:2:1] | passed | 0.00042 seconds |
15
+ ./spec/solidus_support_spec.rb[1:2:3:1] | passed | 0.00104 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
@@ -59,7 +42,7 @@ RSpec.describe SolidusSupport do
59
42
  end
60
43
 
61
44
  context 'when Solidus has preference to choose if combine addresses fields' do
62
- let(:solidus_version) { '2.10.3' }
45
+ let(:solidus_version) { '2.11.3' }
63
46
  before do
64
47
  allow(Spree::Config)
65
48
  .to receive(:use_combined_first_and_last_name_in_address)
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.0
4
+ version: 0.9.1
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-21 00:00:00.000000000 Z
11
+ date: 2022-06-02 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,13 +175,15 @@ 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.1.6
179
+ signing_key:
161
180
  specification_version: 4
162
181
  summary: Common runtime helpers for Solidus extensions.
163
182
  test_files:
164
- - spec/spec_helper.rb
165
183
  - spec/examples.txt
166
- - spec/solidus_support_spec.rb
184
+ - spec/solidus_support/legacy_event_compat/legacy_event_compat_spec.rb
185
+ - spec/solidus_support/legacy_event_compat/bus_spec.rb
167
186
  - spec/support/dummy_app.rb
168
187
  - spec/support/dummy_app/database.yml
188
+ - spec/spec_helper.rb
189
+ - spec/solidus_support_spec.rb