solidus_support 0.4.0 → 0.7.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: 06f44b07249f357975f818d24cd533b0e4419c957c1608c6dfd398956176a456
4
- data.tar.gz: 7a5c3c693cb6a9c0d36a056bbab25338c54a756a4a2f745a997a3ae1f1a221cc
3
+ metadata.gz: '07148224b06a9d4a742b7fdf8d9d5a61a7637122bab0b18df1c32ccf69401e78'
4
+ data.tar.gz: c315077b626b83202aadf873cca2020f87a14983b5acd2b50d19facf608d85ac
5
5
  SHA512:
6
- metadata.gz: aa4396cf0f842d9c14a3a846cb6e49b053eeaebbfc43d7f6f9b42523054f0d1574eaaa8756a433d2c62902fed6b8ac0539bcb4a6da87d4671285d2db87fff866
7
- data.tar.gz: 2674c879410db8025d8dba10e961598c7bc28b7b17e8bb6d771ece89ae280aad1c257acb948c5ee6c0c810e9574874529c66c3563968bcefc15dc54c5e3162e1
6
+ metadata.gz: f5d3b639b91329457f5178afccb7ec30af0b523ec57bf3ba94b310bc8992c343b5841144797ac12a0912ae41b3faae7f909eca0ae6cd7484bb754c21af1ab83b
7
+ data.tar.gz: a70259d8ea10233f470896a75973b2f063ff259a2c2331191f1dadc21086e9339d193352d5c08a9895cb4802d4cae4a54951dc12fd252fc77ddec7f9c4921300
@@ -0,0 +1,5 @@
1
+ bump:
2
+ recurse: false
3
+ file: 'lib/solidus_support/version.rb'
4
+ message: Bump SolidusSupport to %{version}
5
+ branch: false
@@ -0,0 +1,17 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 60
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: wontfix
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This issue has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
data/.gitignore CHANGED
@@ -1,12 +1,17 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /log/
11
- /spec/
12
-
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.swp
15
+ spec/dummy
16
+ spec/examples.txt
17
+ log
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --require spec_helper
2
+ --color
@@ -1,2 +1,2 @@
1
1
  require:
2
- - solidus_extension_dev_tools/rubocop
2
+ - solidus_dev_support/rubocop
@@ -0,0 +1,140 @@
1
+ # Changelog
2
+
3
+ ## [v0.6.0](https://github.com/solidusio/solidus_support/tree/v0.6.0) (2020-07-24)
4
+
5
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.5.1...v0.6.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Autoload Solidus Event subscribers from extensions [\#45](https://github.com/solidusio/solidus_support/pull/45) ([spaghetticode](https://github.com/spaghetticode))
10
+
11
+ **Fixed bugs:**
12
+
13
+ - Load event subscribers only when Spree::Event is available [\#47](https://github.com/solidusio/solidus_support/pull/47) ([spaghetticode](https://github.com/spaghetticode))
14
+
15
+ **Closed issues:**
16
+
17
+ - Namespace Conflicts [\#48](https://github.com/solidusio/solidus_support/issues/48)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Stop using SolidusSupport.solidus\_gem\_version [\#46](https://github.com/solidusio/solidus_support/pull/46) ([elia](https://github.com/elia))
22
+ - Add frontend/backend/api decorators to autoload path [\#44](https://github.com/solidusio/solidus_support/pull/44) ([kennyadsl](https://github.com/kennyadsl))
23
+
24
+ ## [v0.5.1](https://github.com/solidusio/solidus_support/tree/v0.5.1) (2020-04-15)
25
+
26
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.5.0...v0.5.1)
27
+
28
+ **Merged pull requests:**
29
+
30
+ - Push decorators to autoload path using config.autoload\_paths [\#43](https://github.com/solidusio/solidus_support/pull/43) ([kennyadsl](https://github.com/kennyadsl))
31
+
32
+ ## [v0.5.0](https://github.com/solidusio/solidus_support/tree/v0.5.0) (2020-02-18)
33
+
34
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.4.1...v0.5.0)
35
+
36
+ **Merged pull requests:**
37
+
38
+ - Load Solidus engine extension files automatically [\#42](https://github.com/solidusio/solidus_support/pull/42) ([aldesantis](https://github.com/aldesantis))
39
+ - Deprecate SolidusSupport.solidus\_gem\_version [\#37](https://github.com/solidusio/solidus_support/pull/37) ([kennyadsl](https://github.com/kennyadsl))
40
+
41
+ ## [v0.4.1](https://github.com/solidusio/solidus_support/tree/v0.4.1) (2020-01-16)
42
+
43
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.4.0...v0.4.1)
44
+
45
+ **Closed issues:**
46
+
47
+ - Should use require\_dependency instead of require/load [\#34](https://github.com/solidusio/solidus_support/issues/34)
48
+ - Add a LICENSE [\#20](https://github.com/solidusio/solidus_support/issues/20)
49
+
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
+ ## [v0.4.0](https://github.com/solidusio/solidus_support/tree/v0.4.0) (2019-12-16)
58
+
59
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.3.2...v0.4.0)
60
+
61
+ **Closed issues:**
62
+
63
+ - Configure CircleCI [\#30](https://github.com/solidusio/solidus_support/issues/30)
64
+ - Models::SolidusGlobalize::Spree::TaxonomyDecorator \(NameError\) [\#26](https://github.com/solidusio/solidus_support/issues/26)
65
+
66
+ **Merged pull requests:**
67
+
68
+ - Fix issues with test runs [\#32](https://github.com/solidusio/solidus_support/pull/32) ([aldesantis](https://github.com/aldesantis))
69
+ - Add CircleCI configuration [\#31](https://github.com/solidusio/solidus_support/pull/31) ([aldesantis](https://github.com/aldesantis))
70
+ - Introduce solidus\_extension\_dev\_tools [\#29](https://github.com/solidusio/solidus_support/pull/29) ([aldesantis](https://github.com/aldesantis))
71
+ - Remove support for testing and extensions [\#28](https://github.com/solidusio/solidus_support/pull/28) ([MinasMazar](https://github.com/MinasMazar))
72
+ - Add SolidusSupport::EngineExtension::Decorators to load decorators [\#27](https://github.com/solidusio/solidus_support/pull/27) ([kennyadsl](https://github.com/kennyadsl))
73
+ - Add support for Codecov [\#24](https://github.com/solidusio/solidus_support/pull/24) ([aldesantis](https://github.com/aldesantis))
74
+
75
+ ## [v0.3.2](https://github.com/solidusio/solidus_support/tree/v0.3.2) (2019-08-08)
76
+
77
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.2.1...v0.3.2)
78
+
79
+ **Merged pull requests:**
80
+
81
+ - Add `capybara-screenshot` dependency [\#23](https://github.com/solidusio/solidus_support/pull/23) ([spaghetticode](https://github.com/spaghetticode))
82
+ - Do not reset spree preferences starting from v2.9 [\#22](https://github.com/solidusio/solidus_support/pull/22) ([kennyadsl](https://github.com/kennyadsl))
83
+ - 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))
85
+ - Migrate from Poltergeist to Headless Chrome [\#16](https://github.com/solidusio/solidus_support/pull/16) ([aitbw](https://github.com/aitbw))
86
+ - Remove running rubocop on rake task [\#14](https://github.com/solidusio/solidus_support/pull/14) ([kennyadsl](https://github.com/kennyadsl))
87
+ - Cleanup extension [\#13](https://github.com/solidusio/solidus_support/pull/13) ([kennyadsl](https://github.com/kennyadsl))
88
+ - Fix how we compare gem versions to determine new gateway code usage [\#12](https://github.com/solidusio/solidus_support/pull/12) ([kennyadsl](https://github.com/kennyadsl))
89
+ - Add payment method parent class [\#8](https://github.com/solidusio/solidus_support/pull/8) ([tvdeyen](https://github.com/tvdeyen))
90
+ - Improve gem documentation [\#7](https://github.com/solidusio/solidus_support/pull/7) ([kennyadsl](https://github.com/kennyadsl))
91
+
92
+ ## [v0.2.1](https://github.com/solidusio/solidus_support/tree/v0.2.1) (2018-02-22)
93
+
94
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.2.0...v0.2.1)
95
+
96
+ **Merged pull requests:**
97
+
98
+ - Ensure database cleaning is very last in each spec [\#9](https://github.com/solidusio/solidus_support/pull/9) ([jhawthorn](https://github.com/jhawthorn))
99
+
100
+ ## [v0.2.0](https://github.com/solidusio/solidus_support/tree/v0.2.0) (2017-10-25)
101
+
102
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.5...v0.2.0)
103
+
104
+ **Merged pull requests:**
105
+
106
+ - Rename FactoryBot [\#6](https://github.com/solidusio/solidus_support/pull/6) ([tvdeyen](https://github.com/tvdeyen))
107
+ - 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
+
110
+ ## [v0.1.5](https://github.com/solidusio/solidus_support/tree/v0.1.5) (2017-07-27)
111
+
112
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.4...v0.1.5)
113
+
114
+ ## [v0.1.4](https://github.com/solidusio/solidus_support/tree/v0.1.4) (2017-07-26)
115
+
116
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.3...v0.1.4)
117
+
118
+ ## [v0.1.3](https://github.com/solidusio/solidus_support/tree/v0.1.3) (2017-07-26)
119
+
120
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.2...v0.1.3)
121
+
122
+ ## [v0.1.2](https://github.com/solidusio/solidus_support/tree/v0.1.2) (2017-07-24)
123
+
124
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.1...v0.1.2)
125
+
126
+ **Merged pull requests:**
127
+
128
+ - Add SolidusSupport.payment\_source\_parent\_class [\#1](https://github.com/solidusio/solidus_support/pull/1) ([jordan-brough](https://github.com/jordan-brough))
129
+
130
+ ## [v0.1.1](https://github.com/solidusio/solidus_support/tree/v0.1.1) (2017-05-03)
131
+
132
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/v0.1.0...v0.1.1)
133
+
134
+ ## [v0.1.0](https://github.com/solidusio/solidus_support/tree/v0.1.0) (2017-03-21)
135
+
136
+ [Full Changelog](https://github.com/solidusio/solidus_support/compare/b34d603b2b603e8799ce801913b577322bd39bdc...v0.1.0)
137
+
138
+
139
+
140
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -1,22 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
5
 
5
6
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
7
  gem 'solidus_core', github: 'solidusio/solidus', branch: branch
7
8
 
8
- # Specify your gem's dependencies in solidus_support.gemspec
9
- gemspec
10
-
11
- gem 'solidus_extension_dev_tools', github: 'solidusio-contrib/solidus_extension_dev_tools'
12
- gem 'sprockets', '~> 3'
13
- gem 'sprockets-rails'
14
-
15
9
  case ENV['DB']
16
- when 'postgresql'
17
- gem 'pg'
18
10
  when 'mysql'
19
11
  gem 'mysql2'
12
+ when 'postgresql'
13
+ gem 'pg'
20
14
  else
21
15
  gem 'sqlite3'
22
16
  end
17
+
18
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2017 Solidus
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Solidus nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  # SolidusSupport
2
2
 
3
- This gem holds some common functionality for Solidus Extensions.
3
+ This gem contains common runtime functionality for Solidus extensions.
4
4
 
5
- It has some utilities to make it easier to support multiple versions of Solidus.
5
+ If you are looking for development tools instead, see
6
+ [solidus_dev_support](https://github.com/solidusio-contrib/solidus_dev_support).
6
7
 
7
8
  ## Usage
8
9
 
9
10
  ### `SolidusSupport::Migration`
10
11
 
11
- Rails >= 5 introduced the concept of specifying what rails version your migration was written for, like `ActiveRecord::Migration[5.0]`.
12
- Not specifying a version is deprecated in Rails 5.0 and removed in rails 5.1.
13
- This wasn't backported to Rails 4.2, but Rails 4.2 _is_ Rails 4.2. So we provide this helper.
12
+ Rails >= 5 introduced the concept of specifying what Rails version your migration was written for,
13
+ like `ActiveRecord::Migration[5.0]`. Not specifying a version is deprecated in Rails 5.0 and removed
14
+ in Rails 5.1. This wasn't backported to Rails 4.2, so we provide this helper to return the right
15
+ parent class:
14
16
 
15
17
  ``` ruby
16
18
  # On Rails 4.2
@@ -22,29 +24,28 @@ SolidusSupport::Migration[4.2] # same as `ActiveRecord::Migration[4.2]`
22
24
  SolidusSupport::Migration[5.0] # same as `ActiveRecord::Migration[5.0]`
23
25
  ```
24
26
 
25
- There's no reason to use `SolidusSupport::Migration[5.0]` over `ActiveRecord::Migration[5.0]`, but it is provided.
27
+ There's no reason to use `SolidusSupport::Migration[5.0]` over `ActiveRecord::Migration[5.0]`, but
28
+ it is provided.
26
29
 
27
- ### Engine Extensions
30
+ ### Engine extensions
28
31
 
29
- This extension provides a module that extends `Rails::Engine` functionalities
30
- to support loading correctly the decorators class created into an extension
31
- both for development and production enviroments.
32
-
33
- To use it just include the provided module in the Engine as follow:
32
+ This extension provides a module that decorates `Rails::Engine` to seamlessly support autoloading
33
+ decorators both with the classic autoloader and with Zeitwerk on Rails 6. In order to use it, just
34
+ include the provided module in your `Engine` class:
34
35
 
35
36
  ```ruby
36
37
  module SolidusExtensionName
37
38
  class Engine < Rails::Engine
38
39
  engine_name 'solidus_extension_name'
39
40
 
40
- include SolidusSupport::EngineExtensions::Decorators
41
+ include SolidusSupport::EngineExtensions
42
+
41
43
  # ...
42
44
  end
43
45
  end
44
46
  ```
45
47
 
46
- To make it work, be sure to remove the previous implementation from the
47
- Engine, that should be something like:
48
+ If needed, also ensure to remove the original implementation of `.activate`:
48
49
 
49
50
  ```ruby
50
51
  def self.activate
@@ -56,11 +57,32 @@ end
56
57
  config.to_prepare(&method(:activate).to_proc)
57
58
  ```
58
59
 
59
- ## Development
60
+ #### Loading files conditionally
61
+
62
+ If you include `EngineExtensions` in your extension and structure your files according to the
63
+ expected paths, they will be loaded automagically only when the relevant Solidus engines are
64
+ available.
65
+
66
+ Here's what an example structure may look like:
60
67
 
61
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+ - `lib/views/backend`: will only be added to the view paths when `solidus_backend` is available.
69
+ - `lib/controllers/backend`: will only be added to the controller paths when `solidus_backend` is
70
+ available.
71
+ - `lib/decorators/backend`: will only be added to the decorator paths when `solidus_backend` is
72
+ available.
73
+
74
+ The same goes for `frontend` and `api`.
75
+
76
+ We strongly recommend following this structure and making your extensions so that they're not
77
+ dependent on anything other than `solidus_core`, only augmenting the functionality of the other
78
+ engines when they are available.
79
+
80
+ ## Development
62
81
 
63
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new
83
+ version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
84
+ will create a git tag for the version, push git commits and tags, and push the `.gem` file to
85
+ [rubygems.org](https://rubygems.org).
64
86
 
65
87
  ## Contributing
66
88
 
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_support"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
@@ -8,25 +8,22 @@ require 'solidus_core'
8
8
  module SolidusSupport
9
9
  class << self
10
10
  def solidus_gem_version
11
- if Spree.respond_to?(:solidus_gem_version)
12
- Spree.solidus_gem_version
13
- elsif Spree.respond_to?(:gem_version)
14
- # 1.1 doesn't have solidus_gem_version
15
- Gem::Version.new(Spree.solidus_version)
16
- else
17
- # 1.0 doesn't have gem_version
18
- Gem::Specification.detect { |x| x.name == 'solidus_core' }.version
19
- end
11
+ ActiveSupport::Deprecation.warn <<-WARN.squish, caller
12
+ SolidusSupport.solidus_gem_version is deprecated and will be removed
13
+ in solidus_support 1.0. Please use Spree.solidus_gem_version instead.
14
+ WARN
15
+
16
+ Spree.solidus_gem_version
20
17
  end
21
18
 
22
19
  def reset_spree_preferences_deprecated?
23
20
  first_version_without_reset = Gem::Requirement.new('>= 2.9')
24
- first_version_without_reset.satisfied_by?(solidus_gem_version)
21
+ first_version_without_reset.satisfied_by?(Spree.solidus_gem_version)
25
22
  end
26
23
 
27
24
  def new_gateway_code?
28
25
  first_version_with_new_gateway_code = Gem::Requirement.new('>= 2.3')
29
- first_version_with_new_gateway_code.satisfied_by?(solidus_gem_version)
26
+ first_version_with_new_gateway_code.satisfied_by?(Spree.solidus_gem_version)
30
27
  end
31
28
 
32
29
  def payment_source_parent_class
@@ -1,3 +1,101 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'engine_extensions/decorators'
3
+ module SolidusSupport
4
+ module EngineExtensions
5
+ include ActiveSupport::Deprecation::DeprecatedConstantAccessor
6
+ deprecate_constant 'Decorators', 'SolidusSupport::EngineExtensions'
7
+
8
+ def self.included(engine)
9
+ engine.extend ClassMethods
10
+
11
+ engine.class_eval do
12
+ solidus_decorators_root.glob('*') do |decorators_folder|
13
+ config.autoload_paths += [decorators_folder]
14
+ end
15
+
16
+ config.to_prepare(&method(:activate))
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?
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ def activate
26
+ load_solidus_decorators_from(solidus_decorators_root)
27
+ load_solidus_subscribers_from(solidus_subscribers_root)
28
+ end
29
+
30
+ # Loads Solidus event subscriber files.
31
+ #
32
+ # This allows to add event subscribers to extensions without explicitly subscribing them,
33
+ # similarly to what happens in Solidus core.
34
+ def load_solidus_subscribers_from(path)
35
+ if defined? Spree::Event
36
+ path.glob("**/*_subscriber.rb") do |subscriber_path|
37
+ require_dependency(subscriber_path)
38
+ end
39
+
40
+ if Spree::Event.respond_to?(:activate_all_subscribers)
41
+ Spree::Event.activate_all_subscribers
42
+ else
43
+ Spree::Event.subscribers.each(&:subscribe!)
44
+ end
45
+ end
46
+ end
47
+
48
+ # Loads decorator files.
49
+ #
50
+ # This is needed since they are never explicitly referenced in the application code and
51
+ # won't be loaded by default. We need them to be executed regardless in order to decorate
52
+ # existing classes.
53
+ def load_solidus_decorators_from(path)
54
+ path.glob('**/*.rb') do |decorator_path|
55
+ require_dependency(decorator_path)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # Returns the root for this engine's decorators.
62
+ #
63
+ # @return [Path]
64
+ def solidus_decorators_root
65
+ root.join('app/decorators')
66
+ end
67
+
68
+ # Returns the root for this engine's Solidus event subscribers.
69
+ #
70
+ # @return [Path]
71
+ def solidus_subscribers_root
72
+ root.join("app/subscribers")
73
+ end
74
+
75
+ # Enables support for a Solidus engine.
76
+ #
77
+ # This will tell Rails to:
78
+ #
79
+ # * add +lib/controllers/[engine]+ to the controller paths;
80
+ # * add +lib/views/[engine]+ to the view paths;
81
+ # * load the decorators in +lib/decorators/[engine]+.
82
+ #
83
+ # @see #load_solidus_decorators_from
84
+ def enable_solidus_engine_support(engine)
85
+ paths['app/controllers'] << "lib/controllers/#{engine}"
86
+ paths['app/views'] << "lib/views/#{engine}"
87
+
88
+ path = root.join("lib/decorators/#{engine}")
89
+
90
+ config.autoload_paths += path.glob('*')
91
+
92
+ engine_context = self
93
+ config.to_prepare do
94
+ engine_context.instance_eval do
95
+ load_solidus_decorators_from(path)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusSupport
4
- VERSION = '0.4.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -1,27 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ $:.push File.expand_path('lib', __dir__)
5
4
  require 'solidus_support/version'
6
5
 
7
- Gem::Specification.new do |spec|
8
- spec.name = 'solidus_support'
9
- spec.version = SolidusSupport::VERSION
10
- spec.authors = ['John Hawthorn']
11
- spec.email = ['john@stembolt.com']
6
+ Gem::Specification.new do |s|
7
+ s.name = 'solidus_support'
8
+ s.version = SolidusSupport::VERSION
9
+ s.summary = 'Common runtime helpers for Solidus extensions.'
10
+ s.license = 'BSD-3-Clause'
12
11
 
13
- spec.summary = 'A common functionality for solidus extensions'
14
- spec.description = 'Collection of common functionality for solidus extensions'
15
- spec.homepage = 'https://solidus.io'
12
+ s.author = 'John Hawthorn'
13
+ s.email = 'john@stembolt.com'
14
+ s.homepage = 'https://github.com/solidusio/solidus_support'
16
15
 
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.require_paths = ['lib']
16
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ s.test_files = Dir['spec/**/*']
20
+ s.bindir = "exe"
21
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
19
23
 
20
- spec.add_development_dependency 'bundler'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec-rails'
23
- spec.add_development_dependency 'rubocop'
24
- spec.add_development_dependency 'rubocop-rspec'
25
- spec.add_development_dependency 'solidus_core'
26
- spec.add_development_dependency 'solidus_extension_dev_tools'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec-rails'
27
+ s.add_development_dependency 'rubocop'
28
+ s.add_development_dependency 'rubocop-rspec'
29
+ s.add_development_dependency 'solidus_dev_support'
27
30
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SolidusSupport do
4
+ describe '.payment_method_parent_class' do
5
+ subject { described_class.payment_method_parent_class(credit_card: credit_card) }
6
+
7
+ let(:credit_card) { nil }
8
+
9
+ before do
10
+ allow(Spree).to receive(:solidus_gem_version) do
11
+ Gem::Version.new(solidus_version)
12
+ end
13
+ end
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
22
+ let(:solidus_version) { '2.3.1' }
23
+
24
+ it { is_expected.to eq(Spree::PaymentMethod) }
25
+ end
26
+
27
+ # rubocop:disable RSpec/NestedGroups
28
+ context 'with credit_card: true' do
29
+ let(:credit_card) { true }
30
+
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
42
+ end
43
+ # rubocop:enable RSpec/NestedGroups
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configure Rails Environment
4
+ ENV['RAILS_ENV'] = 'test'
5
+
6
+ # Run Coverage report
7
+ require 'solidus_dev_support/rspec/coverage'
8
+
9
+ # Load dummy app
10
+ require_relative 'support/dummy_app'
11
+
12
+ # Requires factories and other useful helpers defined in spree_core.
13
+ require 'solidus_dev_support/rspec/spec_helper'
14
+
15
+ # Requires supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] = 'test'
4
+ ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1'
5
+
6
+ Bundler.setup
7
+
8
+ require 'rails'
9
+ require 'solidus_core'
10
+
11
+ Bundler.require(:default, :test)
12
+
13
+ module DummyApp
14
+ class Application < ::Rails::Application
15
+ config.eager_load = false
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
+ end
19
+ end
20
+
21
+ DummyApp::Application.initialize!
@@ -0,0 +1,16 @@
1
+ <% if ENV['DB'] == 'postgresql' %>
2
+ test:
3
+ adapter: postgresql
4
+ database: circle_test
5
+ username: root
6
+ <% elsif ENV['DB'] == 'mysql' %>
7
+ test:
8
+ adapter: mysql2
9
+ database: circle_test
10
+ username: root
11
+ <% else %>
12
+ test:
13
+ adapter: sqlite3
14
+ database: ':memory:'
15
+ timeout: 10000
16
+ <% end %>
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.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: solidus_core
84
+ name: solidus_dev_support
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -94,49 +94,40 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: solidus_extension_dev_tools
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- description: Collection of common functionality for solidus extensions
112
- email:
113
- - john@stembolt.com
97
+ description:
98
+ email: john@stembolt.com
114
99
  executables: []
115
100
  extensions: []
116
101
  extra_rdoc_files: []
117
102
  files:
118
103
  - ".circleci/config.yml"
104
+ - ".gem_release.yml"
105
+ - ".github/stale.yml"
119
106
  - ".gitignore"
120
107
  - ".rspec"
121
108
  - ".rubocop.yml"
122
- - ".travis.yml"
109
+ - CHANGELOG.md
123
110
  - Gemfile
111
+ - LICENSE
124
112
  - README.md
125
113
  - Rakefile
114
+ - bin/console
115
+ - bin/setup
126
116
  - lib/solidus_support.rb
127
117
  - lib/solidus_support/engine_extensions.rb
128
- - lib/solidus_support/engine_extensions/decorators.rb
129
118
  - lib/solidus_support/migration.rb
130
119
  - lib/solidus_support/version.rb
131
120
  - solidus_support.gemspec
121
+ - spec/examples.txt
132
122
  - spec/solidus_support_spec.rb
133
123
  - spec/spec_helper.rb
134
124
  - spec/support/dummy_app.rb
135
125
  - spec/support/dummy_app/database.yml
136
- homepage: https://solidus.io
137
- licenses: []
126
+ homepage: https://github.com/solidusio/solidus_support
127
+ licenses:
128
+ - BSD-3-Clause
138
129
  metadata: {}
139
- post_install_message:
130
+ post_install_message:
140
131
  rdoc_options: []
141
132
  require_paths:
142
133
  - lib
@@ -151,8 +142,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
142
  - !ruby/object:Gem::Version
152
143
  version: '0'
153
144
  requirements: []
154
- rubygems_version: 3.0.6
155
- signing_key:
145
+ rubygems_version: 3.0.3
146
+ signing_key:
156
147
  specification_version: 4
157
- summary: A common functionality for solidus extensions
158
- test_files: []
148
+ summary: Common runtime helpers for Solidus extensions.
149
+ test_files:
150
+ - spec/spec_helper.rb
151
+ - spec/examples.txt
152
+ - spec/solidus_support_spec.rb
153
+ - spec/support/dummy_app.rb
154
+ - spec/support/dummy_app/database.yml
@@ -1,18 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- dist: trusty
4
- cache:
5
- bundler: true
6
- before_install:
7
- - "gem install bundler --pre"
8
- - "bundler -v"
9
- rvm:
10
- - 2.4.2
11
- env:
12
- matrix:
13
- - SOLIDUS_BRANCH=v2.4
14
- - SOLIDUS_BRANCH=v2.5
15
- - SOLIDUS_BRANCH=v2.6
16
- - SOLIDUS_BRANCH=v2.7
17
- - SOLIDUS_BRANCH=v2.8
18
- - SOLIDUS_BRANCH=master
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusSupport
4
- module EngineExtensions
5
- module Decorators
6
- def self.included(engine)
7
- engine.class_eval do
8
- extend ClassMethods
9
- config.to_prepare(&method(:activate).to_proc)
10
- end
11
- end
12
-
13
- module ClassMethods
14
- def activate
15
- base_path = root.join('app/decorators')
16
-
17
- if Rails.respond_to?(:autoloaders)
18
- # Add decorators folder to the Rails autoloader. This
19
- # allows Zeitwerk to resolve decorators paths correctly,
20
- # when used.
21
- Dir.glob(base_path.join('*')) do |decorators_folder|
22
- Rails.autoloaders.main.push_dir(decorators_folder)
23
- end
24
- end
25
-
26
- # Load decorator files. This is needed since they are
27
- # never explicitely referenced in the application code
28
- # and won't be loaded by default. We need them to be
29
- # executed anyway to extend exisiting classes.
30
- Dir.glob(base_path.join('**/*.rb')) do |decorator_path|
31
- Rails.configuration.cache_classes ? require(decorator_path) : load(decorator_path)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end