solidus_core 2.9.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0094b02cd702626b2e096ec98561a32fb8493227a6e5fa265f66abae656fdaf3'
4
- data.tar.gz: 79dbb067dacfc98477078c1a48e812c6d5ac19596c897f573dcd892e8504b2d1
3
+ metadata.gz: a2edabaa78d1ec9b196da1fe62c6597ea1fd392a37185f48c6786e6d00f4566a
4
+ data.tar.gz: fb268588d3df1204706a1d89026b9de2b5967f5b9d5c3bcce91c52e05280a0cd
5
5
  SHA512:
6
- metadata.gz: 6b2a0aa8d08f5474ab3e531d5b50b667650183e175daf4ed2f2e4ac2d1b9cbdab012a90bb9ccb488624b1a56eaf460faa07f3a56e566d5075d58bb10c7275317
7
- data.tar.gz: 7daf2551e03bf901f010279aa59deb43ea215e0456b27e5cbf80e70d843ae54b41a47a92e1dbcc13f0a7bb720cf2d7805478bf69cffcc5611457f798436b6856
6
+ metadata.gz: 521bcc28081f5ad38b84736fa159e616fd22985b1ccf2022921945533dc00144b9688827fd1405b70212de8cc222b1482eac7f143f4b71f729c931a4bea319c4
7
+ data.tar.gz: e9a8edbd1fe694e5dd4d823d08dff30db1e036212c37837421702b9e31514db48fa1b5f58441b46a490c96d171dfe1964a776b13477826160b2f01ac24fbaa8e
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "2.9.0"
4
+ VERSION = "2.9.1"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
@@ -44,21 +44,36 @@ module Spree
44
44
  # This method may be used for stubbing one or more different preferences
45
45
  # at the same time.
46
46
  #
47
- # @param [Hash] preferences names and values to be stubbed
47
+ # @param prefs_or_conf_class [Class, Hash] the class we want to stub
48
+ # preferences for or the preferences hash (see prefs param). If this
49
+ # param is an Hash, preferences will be stubbed on Spree::Config.
50
+ # @param prefs [Hash, nil] names and values to be stubbed
48
51
  #
49
- # @example Stubs `currency` and `track_inventory_levels` preferences
52
+ # @example Stubs `currency` and `track_inventory_levels` on `Spree::Config`:
50
53
  # stub_spree_preferences(currency: 'EUR', track_inventory_levels: false)
51
54
  # expect(Spree::Config.currency).to eql 'EUR'
52
55
  #
56
+ # @example Stubs `locale` preference on `Spree::Backend::Config`:
57
+ # stub_spree_preferences(Spree::Backend::Config, locale: 'fr'),
58
+ # expect(Spree::Backend::Config.locale).to eql 'fr'
59
+ #
53
60
  # @see https://github.com/solidusio/solidus/issues/3219
54
61
  # Solidus #3219 for more details and motivations.
55
- def stub_spree_preferences(preferences)
62
+ def stub_spree_preferences(prefs_or_conf_class, prefs = nil)
63
+ if prefs_or_conf_class.is_a?(Hash)
64
+ preference_store_class = Spree::Config
65
+ preferences = prefs_or_conf_class
66
+ else
67
+ preference_store_class = prefs_or_conf_class
68
+ preferences = prefs
69
+ end
70
+
56
71
  preferences.each do |name, value|
57
- if Spree::Config.method(:[]).owner >= Spree::Config.class
58
- allow(Spree::Config).to receive(:[]).and_call_original
72
+ if preference_store_class.method(:[]).owner >= preference_store_class.class
73
+ allow(preference_store_class).to receive(:[]).and_call_original
59
74
  end
60
- allow(Spree::Config).to receive(:[]).with(name) { value }
61
- allow(Spree::Config).to receive(name) { value }
75
+ allow(preference_store_class).to receive(:[]).with(name) { value }
76
+ allow(preference_store_class).to receive(name) { value }
62
77
  end
63
78
  end
64
79
 
@@ -75,12 +90,30 @@ module Spree
75
90
  # expect(Spree::Config.currency).to eql 'EUR'
76
91
  # end
77
92
  # @see Spree::TestingSupport::Preferences#stub_spree_preferences
78
- def with_unfrozen_spree_preference_store
79
- frozen_store = Spree::Config.preference_store
80
- Spree::Config.preference_store = Spree::Config[:unfrozen_preference_store].dup
93
+ def with_unfrozen_spree_preference_store(preference_store_class: Spree::Config)
94
+ frozen_store = preference_store_class.preference_store
95
+ preference_store_class.preference_store = preference_store_class[:unfrozen_preference_store].dup
81
96
  yield
82
97
  ensure
83
- Spree::Config.preference_store = frozen_store
98
+ preference_store_class.preference_store = frozen_store
99
+ end
100
+
101
+ # This class method allows to freeze preferences for a specific
102
+ # configuration store class. It also stores the current state into
103
+ # a new preference of that store, so it can be reused when needed
104
+ # (eg. with_unfrozen_spree_preference_store)
105
+ #
106
+ # It is meant to be used by extensions as well, for example if one
107
+ # extension has its own Spree::ExtensionName::Config class, we can
108
+ # freeze it and be sure we always stub values on it during tests.
109
+ #
110
+ # @param preference_store_class [Class] the configuration class we want
111
+ # to freeze.
112
+ def self.freeze_preferences(preference_store_class)
113
+ config_class = preference_store_class.class
114
+ config_class.preference :unfrozen_preference_store, :hash
115
+ preference_store_class.unfrozen_preference_store = preference_store_class.preference_store.dup
116
+ preference_store_class.preference_store.freeze
84
117
  end
85
118
  end
86
119
  end
@@ -88,9 +121,15 @@ end
88
121
 
89
122
  RSpec.configure do |config|
90
123
  config.before :suite do
91
- # keep a copy of the original unfrozen preference_store for later use:
92
- Spree::AppConfiguration.preference :unfrozen_preference_store, :hash
93
- Spree::Config.unfrozen_preference_store = Spree::Config.preference_store.dup
94
- Spree::Config.preference_store.freeze
124
+ %w[
125
+ Spree::Config
126
+ Spree::Frontend::Config
127
+ Spree::Backend::Config
128
+ Spree::Api::Config
129
+ ].each do |configuration_class|
130
+ if Object.const_defined?(configuration_class)
131
+ Spree::TestingSupport::Preferences.freeze_preferences(configuration_class.constantize)
132
+ end
133
+ end
95
134
  end
96
135
  end
@@ -27,7 +27,7 @@ module Spree
27
27
  end
28
28
 
29
29
  context 'when track_inventory_levels is false' do
30
- before { stub_spree_preferences track_inventory_levels: false }
30
+ before { stub_spree_preferences(track_inventory_levels: false) }
31
31
 
32
32
  specify { expect(subject.total_on_hand).to eq(Float::INFINITY) }
33
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer