solidus_support 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '07148224b06a9d4a742b7fdf8d9d5a61a7637122bab0b18df1c32ccf69401e78'
4
- data.tar.gz: c315077b626b83202aadf873cca2020f87a14983b5acd2b50d19facf608d85ac
3
+ metadata.gz: c78d734eb4b421be9efa6eb57baee461ef4fe899bb1d734b17f9b467aa6856fd
4
+ data.tar.gz: eb7ac669aed3124a9b418862abfb9daaaf9f9b6493e278363f437f09bad37c00
5
5
  SHA512:
6
- metadata.gz: f5d3b639b91329457f5178afccb7ec30af0b523ec57bf3ba94b310bc8992c343b5841144797ac12a0912ae41b3faae7f909eca0ae6cd7484bb754c21af1ab83b
7
- data.tar.gz: a70259d8ea10233f470896a75973b2f063ff259a2c2331191f1dadc21086e9339d193352d5c08a9895cb4802d4cae4a54951dc12fd252fc77ddec7f9c4921300
6
+ metadata.gz: 9db377ce30fbb4818a7e6a29440b8fd61310f84227e5e9c1f1e21d97c7c14ade8609aed46e4e1abc23afb2e116cef98202597cae4defefe331df6b4b69722bf2
7
+ data.tar.gz: aa70ce113298641e54738f9362717150d9261744e23ef17d6377724bdfc361882571f2647652273a83ec35bdd20fac89e3630352e92d32601d380dd472512099
data/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
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
+
38
+ ## [v0.7.0](https://github.com/solidusio/solidus_support/tree/v0.7.0) (2020-10-28)
39
+
40
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.6.0...v0.7.0)
41
+
42
+ **Closed issues:**
43
+
44
+ - Could we get a new release? [\#49](https://github.com/solidusio/solidus_support/issues/49)
45
+
46
+ **Merged pull requests:**
47
+
48
+ - Use `Spree::Event. activate_all_subscribers` when available [\#53](https://github.com/solidusio/solidus_support/pull/53) ([spaghetticode](https://github.com/spaghetticode))
49
+ - Support Rails 5.1.x [\#51](https://github.com/solidusio/solidus_support/pull/51) ([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))
51
+
3
52
  ## [v0.6.0](https://github.com/solidusio/solidus_support/tree/v0.6.0) (2020-07-24)
4
53
 
5
54
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.5.1...v0.6.0)
@@ -36,7 +85,11 @@
36
85
  **Merged pull requests:**
37
86
 
38
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))
39
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))
40
93
 
41
94
  ## [v0.4.1](https://github.com/solidusio/solidus_support/tree/v0.4.1) (2020-01-16)
42
95
 
@@ -47,13 +100,6 @@
47
100
  - Should use require\_dependency instead of require/load [\#34](https://github.com/solidusio/solidus_support/issues/34)
48
101
  - Add a LICENSE [\#20](https://github.com/solidusio/solidus_support/issues/20)
49
102
 
50
- **Merged pull requests:**
51
-
52
- - Update solidus\_dev\_support [\#41](https://github.com/solidusio/solidus_support/pull/41) ([aldesantis](https://github.com/aldesantis))
53
- - Replace manual cache checks w/ require\_dependency [\#39](https://github.com/solidusio/solidus_support/pull/39) ([elia](https://github.com/elia))
54
- - Fixes isse when zeitwerk is not enabled [\#38](https://github.com/solidusio/solidus_support/pull/38) ([softr8](https://github.com/softr8))
55
- - Spring cleaning [\#33](https://github.com/solidusio/solidus_support/pull/33) ([aldesantis](https://github.com/aldesantis))
56
-
57
103
  ## [v0.4.0](https://github.com/solidusio/solidus_support/tree/v0.4.0) (2019-12-16)
58
104
 
59
105
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.3.2...v0.4.0)
@@ -81,7 +127,7 @@
81
127
  - Add `capybara-screenshot` dependency [\#23](https://github.com/solidusio/solidus_support/pull/23) ([spaghetticode](https://github.com/spaghetticode))
82
128
  - Do not reset spree preferences starting from v2.9 [\#22](https://github.com/solidusio/solidus_support/pull/22) ([kennyadsl](https://github.com/kennyadsl))
83
129
  - Update Travis config [\#19](https://github.com/solidusio/solidus_support/pull/19) ([aitbw](https://github.com/aitbw))
84
- - 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))
85
131
  - Migrate from Poltergeist to Headless Chrome [\#16](https://github.com/solidusio/solidus_support/pull/16) ([aitbw](https://github.com/aitbw))
86
132
  - Remove running rubocop on rake task [\#14](https://github.com/solidusio/solidus_support/pull/14) ([kennyadsl](https://github.com/kennyadsl))
87
133
  - Cleanup extension [\#13](https://github.com/solidusio/solidus_support/pull/13) ([kennyadsl](https://github.com/kennyadsl))
@@ -105,7 +151,6 @@
105
151
 
106
152
  - Rename FactoryBot [\#6](https://github.com/solidusio/solidus_support/pull/6) ([tvdeyen](https://github.com/tvdeyen))
107
153
  - Remove unused files [\#5](https://github.com/solidusio/solidus_support/pull/5) ([tvdeyen](https://github.com/tvdeyen))
108
- - Add a basic spec\_helper for extensions to include [\#2](https://github.com/solidusio/solidus_support/pull/2) ([jhawthorn](https://github.com/jhawthorn))
109
154
 
110
155
  ## [v0.1.5](https://github.com/solidusio/solidus_support/tree/v0.1.5) (2017-07-27)
111
156
 
@@ -119,6 +164,10 @@
119
164
 
120
165
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.2...v0.1.3)
121
166
 
167
+ **Merged pull requests:**
168
+
169
+ - Add a basic spec\_helper for extensions to include [\#2](https://github.com/solidusio/solidus_support/pull/2) ([jhawthorn](https://github.com/jhawthorn))
170
+
122
171
  ## [v0.1.2](https://github.com/solidusio/solidus_support/tree/v0.1.2) (2017-07-24)
123
172
 
124
173
  [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.1...v0.1.2)
data/Gemfile CHANGED
@@ -16,3 +16,15 @@ else
16
16
  end
17
17
 
18
18
  gemspec
19
+
20
+ # There is an issue with Sprockets 4 not accepting a custom path for
21
+ # the assets manifest, which doesn't play well with in-memory dummy
22
+ # apps such as the one we use in this gem.
23
+
24
+ # A fix was provided for sprockets-rails[1] but it was not accepted
25
+ # yet.
26
+
27
+ # [1]: rails/sprockets-rails#446
28
+ #
29
+ # Please do not remove this line until we have a solution.
30
+ gem 'sprockets', '~> 3'
data/bin/console CHANGED
@@ -3,6 +3,7 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require "bundler/setup"
6
+ require "rails/all"
6
7
  require "solidus_support"
7
8
 
8
9
  # You can add fixtures and/or initialization code here to make experimenting
@@ -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.7.0'
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
 
@@ -21,28 +22,49 @@ module SolidusSupport
21
22
  first_version_without_reset.satisfied_by?(Spree.solidus_gem_version)
22
23
  end
23
24
 
25
+ def combined_first_and_last_name_in_address?
26
+ versions_before_preference = Gem::Requirement.new('< 2.11.0')
27
+ versions_after_preference = Gem::Requirement.new('>= 3.0.0.alpha')
28
+
29
+ return false if versions_before_preference.satisfied_by?(Spree.solidus_gem_version)
30
+ return true if versions_after_preference.satisfied_by?(Spree.solidus_gem_version)
31
+
32
+ Spree::Config.use_combined_first_and_last_name_in_address
33
+ end
34
+
24
35
  def new_gateway_code?
25
- first_version_with_new_gateway_code = Gem::Requirement.new('>= 2.3')
26
- 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
27
42
  end
28
43
 
29
44
  def payment_source_parent_class
30
- if new_gateway_code?
31
- Spree::PaymentSource
32
- else
33
- Spree::Base
34
- 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
35
51
  end
36
52
 
37
53
  def payment_method_parent_class(credit_card: false)
38
- if new_gateway_code?
39
- if credit_card
40
- Spree::PaymentMethod::CreditCard
41
- else
42
- Spree::PaymentMethod
43
- 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
44
61
  else
45
- 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
46
68
  end
47
69
  end
48
70
 
@@ -21,10 +21,12 @@ Gem::Specification.new do |s|
21
21
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
+ s.add_development_dependency 'rails'
24
25
  s.add_development_dependency 'bundler'
25
26
  s.add_development_dependency 'rake'
26
27
  s.add_development_dependency 'rspec-rails'
27
28
  s.add_development_dependency 'rubocop'
28
29
  s.add_development_dependency 'rubocop-rspec'
29
30
  s.add_development_dependency 'solidus_dev_support'
31
+ s.add_development_dependency 'omnes', '~> 0.2.2'
30
32
  end
data/spec/examples.txt CHANGED
@@ -1,6 +1,15 @@
1
- example_id | status | run_time |
2
- ----------------------------------------- | ------ | --------------- |
3
- ./spec/solidus_support_spec.rb[1:1:1:1] | passed | 0.00027 seconds |
4
- ./spec/solidus_support_spec.rb[1:1:2:1] | passed | 0.00022 seconds |
5
- ./spec/solidus_support_spec.rb[1:1:3:1:1] | passed | 0.00134 seconds |
6
- ./spec/solidus_support_spec.rb[1:1:3:2:1] | passed | 0.04738 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,34 +12,50 @@ 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' }
25
+ it { is_expected.to eq(Spree::PaymentMethod::CreditCard) }
26
+ end
27
+ end
28
+
29
+ describe '.combined_first_and_last_name_in_address?' do
30
+ subject { described_class.combined_first_and_last_name_in_address? }
33
31
 
34
- it { is_expected.to eq(Spree::Gateway) }
32
+ before do
33
+ allow(Spree).to receive(:solidus_gem_version) do
34
+ Gem::Version.new(solidus_version)
35
35
  end
36
+ end
36
37
 
37
- context 'with Solidus >= 2.3' do
38
- let(:solidus_version) { '2.3.1' }
38
+ context 'when Solidus did not have the code to combine addresses fields' do
39
+ let(:solidus_version) { '2.9.3' }
40
+
41
+ it { is_expected.to be_falsey }
42
+ end
39
43
 
40
- it { is_expected.to eq(Spree::PaymentMethod::CreditCard) }
44
+ context 'when Solidus has preference to choose if combine addresses fields' do
45
+ let(:solidus_version) { '2.11.3' }
46
+ before do
47
+ allow(Spree::Config)
48
+ .to receive(:use_combined_first_and_last_name_in_address)
49
+ .and_return(true)
41
50
  end
51
+
52
+ it { is_expected.to be_truthy }
53
+ end
54
+
55
+ context 'when Solidus only has code to combine addresses fields' do
56
+ let(:solidus_version) { '3.0.0' }
57
+
58
+ it { is_expected.to be_truthy }
42
59
  end
43
- # rubocop:enable RSpec/NestedGroups
44
60
  end
45
61
  end
@@ -14,7 +14,6 @@ module DummyApp
14
14
  class Application < ::Rails::Application
15
15
  config.eager_load = false
16
16
  config.paths['config/database'] = File.expand_path('dummy_app/database.yml', __dir__)
17
- config.active_record.sqlite3.represent_boolean_as_integer = true unless Gem::Version.new(Rails.version) < Gem::Version.new('5.2')
18
17
  end
19
18
  end
20
19
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
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: 2020-10-28 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +108,21 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
- 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:
98
126
  email: john@stembolt.com
99
127
  executables: []
100
128
  extensions: []
@@ -115,10 +143,15 @@ files:
115
143
  - bin/setup
116
144
  - lib/solidus_support.rb
117
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
118
149
  - lib/solidus_support/migration.rb
119
150
  - lib/solidus_support/version.rb
120
151
  - solidus_support.gemspec
121
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
122
155
  - spec/solidus_support_spec.rb
123
156
  - spec/spec_helper.rb
124
157
  - spec/support/dummy_app.rb
@@ -127,7 +160,7 @@ homepage: https://github.com/solidusio/solidus_support
127
160
  licenses:
128
161
  - BSD-3-Clause
129
162
  metadata: {}
130
- post_install_message:
163
+ post_install_message:
131
164
  rdoc_options: []
132
165
  require_paths:
133
166
  - lib
@@ -142,12 +175,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
175
  - !ruby/object:Gem::Version
143
176
  version: '0'
144
177
  requirements: []
145
- rubygems_version: 3.0.3
146
- signing_key:
178
+ rubygems_version: 3.0.3.1
179
+ signing_key:
147
180
  specification_version: 4
148
181
  summary: Common runtime helpers for Solidus extensions.
149
182
  test_files:
150
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
151
186
  - spec/examples.txt
152
187
  - spec/solidus_support_spec.rb
153
188
  - spec/support/dummy_app.rb