solidus_core 2.9.0 → 2.9.6

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: '0094b02cd702626b2e096ec98561a32fb8493227a6e5fa265f66abae656fdaf3'
4
- data.tar.gz: 79dbb067dacfc98477078c1a48e812c6d5ac19596c897f573dcd892e8504b2d1
3
+ metadata.gz: 482b41309b1c87feff6b32679da923ed2f6077ca241fd0d1bb358647f4261bb1
4
+ data.tar.gz: db5b3124cc3b7c29b916e037d0e1f16ba378aaa386282f59bb873225cee6c33d
5
5
  SHA512:
6
- metadata.gz: 6b2a0aa8d08f5474ab3e531d5b50b667650183e175daf4ed2f2e4ac2d1b9cbdab012a90bb9ccb488624b1a56eaf460faa07f3a56e566d5075d58bb10c7275317
7
- data.tar.gz: 7daf2551e03bf901f010279aa59deb43ea215e0456b27e5cbf80e70d843ae54b41a47a92e1dbcc13f0a7bb720cf2d7805478bf69cffcc5611457f798436b6856
6
+ metadata.gz: bc163558062f4da4c642a1946bfa1fc1d6dfc9a47dddf0fb3f3c3c44c06810e33fe02cbddca9ef007469eb594a19644ce1344d51cc5b04f6b5a039cf57dcc335
7
+ data.tar.gz: e70cf50bf8049770f9fa7ad1be437969dda338298f5dd62b0a44cf545a38f24a57a7d8ccb4e536c8cae5ec899ecd9e18cf40d177adf664bf104ea5d1990e286a
@@ -435,6 +435,13 @@ module Spree
435
435
  touch :completed_at
436
436
 
437
437
  Spree::Event.fire 'order_finalized', order: self
438
+
439
+ if method(:deliver_order_confirmation_email).owner != self.class
440
+ Spree::Deprecation.warn \
441
+ "deliver_order_confirmation_email has been deprecated and moved to " \
442
+ "Spree::MailerSubscriber#order_finalized, please move there any customizations.",
443
+ caller(1)
444
+ end
438
445
  end
439
446
 
440
447
  def fulfill!
@@ -443,6 +450,16 @@ module Spree
443
450
  save!
444
451
  end
445
452
 
453
+ def deliver_order_confirmation_email
454
+ Spree::Deprecation.warn \
455
+ "deliver_order_confirmation_email has been deprecated and moved to " \
456
+ "Spree::MailerSubscriber#order_finalized.",
457
+ caller(1)
458
+
459
+ Spree::Config.order_mailer_class.confirm_email(order).deliver_later
460
+ order.update_column(:confirmation_delivered, true)
461
+ end
462
+
446
463
  # Helper methods for checkout steps
447
464
  def paid?
448
465
  %w(paid credit_owed).include?(payment_state)
@@ -58,6 +58,9 @@ module Spree
58
58
 
59
59
  def setup_assets
60
60
  @lib_name = 'spree'
61
+
62
+ empty_directory 'app/assets/images'
63
+
61
64
  %w{javascripts stylesheets images}.each do |path|
62
65
  empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
63
66
  empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
@@ -31,16 +31,30 @@ module Spree
31
31
  end
32
32
 
33
33
  def permitted_checkout_attributes
34
- permitted_attributes.checkout_attributes + [
35
- bill_address_attributes: permitted_address_attributes,
36
- ship_address_attributes: permitted_address_attributes,
37
- payments_attributes: permitted_payment_attributes,
38
- shipments_attributes: permitted_shipment_attributes
39
- ]
34
+ permitted_attributes.checkout_attributes
35
+ end
36
+
37
+ def permitted_checkout_address_attributes
38
+ permitted_attributes.checkout_address_attributes
39
+ end
40
+
41
+ def permitted_checkout_delivery_attributes
42
+ permitted_attributes.checkout_delivery_attributes
43
+ end
44
+
45
+ def permitted_checkout_payment_attributes
46
+ permitted_attributes.checkout_payment_attributes
47
+ end
48
+
49
+ def permitted_checkout_confirm_attributes
50
+ permitted_attributes.checkout_confirm_attributes
40
51
  end
41
52
 
42
53
  def permitted_order_attributes
43
- permitted_checkout_attributes + [
54
+ permitted_checkout_address_attributes +
55
+ permitted_checkout_delivery_attributes +
56
+ permitted_checkout_payment_attributes +
57
+ permitted_checkout_confirm_attributes + [
44
58
  line_items_attributes: permitted_line_item_attributes
45
59
  ]
46
60
  end
@@ -22,6 +22,15 @@ module Spree
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ def add_class(name)
27
+ Spree::Deprecation.warn(
28
+ 'This method is deprecated. ' \
29
+ "Please use `#{self.class}.add_class_set(#{name.inspect})` instead.",
30
+ caller,
31
+ )
32
+ singleton_class.send(:add_class_set, name)
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -133,7 +133,8 @@ module Spree
133
133
  # spree_wombat serializes payment state as status so imported orders should fall back to status field.
134
134
  payment.state = p[:state] || p[:status] || 'completed'
135
135
  payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
136
- payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
136
+ source_attributes = p[:source] || p[:source_attributes]
137
+ payment.source = create_source_payment_from_params(source_attributes, payment) if source_attributes
137
138
  payment.save!
138
139
  end
139
140
  end
@@ -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.6"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
@@ -8,7 +8,10 @@ module Spree
8
8
  ATTRIBUTES = [
9
9
  :address_attributes,
10
10
  :address_book_attributes,
11
- :checkout_attributes,
11
+ :checkout_address_attributes,
12
+ :checkout_delivery_attributes,
13
+ :checkout_payment_attributes,
14
+ :checkout_confirm_attributes,
12
15
  :credit_card_update_attributes,
13
16
  :customer_return_attributes,
14
17
  :image_attributes,
@@ -45,10 +48,6 @@ module Spree
45
48
 
46
49
  @@address_book_attributes = address_attributes + [:default]
47
50
 
48
- @@checkout_attributes = [
49
- :coupon_code, :email, :special_instructions, :use_billing
50
- ]
51
-
52
51
  @@credit_card_update_attributes = [
53
52
  :month, :year, :expiry, :first_name, :last_name, :name
54
53
  ]
@@ -91,7 +90,7 @@ module Spree
91
90
  :number, :month, :year, :expiry, :verification_value,
92
91
  :first_name, :last_name, :cc_type, :gateway_customer_profile_id,
93
92
  :gateway_payment_profile_id, :last_digits, :name, :encrypted_data,
94
- :existing_card_id, :wallet_payment_source_id
93
+ :existing_card_id, :wallet_payment_source_id, address_attributes: address_attributes
95
94
  ]
96
95
 
97
96
  @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]
@@ -129,5 +128,75 @@ module Spree
129
128
  :product_id, :product, :option_values_attributes, :price,
130
129
  :weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
131
130
  ]
131
+
132
+ @@checkout_address_attributes = [
133
+ :use_billing,
134
+ :email,
135
+ bill_address_attributes: address_attributes,
136
+ ship_address_attributes: address_attributes
137
+ ]
138
+
139
+ @@checkout_delivery_attributes = [
140
+ :special_instructions,
141
+ shipments_attributes: shipment_attributes
142
+ ]
143
+
144
+ @@checkout_payment_attributes = [
145
+ :coupon_code,
146
+ payments_attributes: payment_attributes + [
147
+ source_attributes: source_attributes
148
+ ]
149
+ ]
150
+
151
+ @@checkout_confirm_attributes = []
152
+
153
+ def self.checkout_attributes
154
+ Spree::Deprecation.warn <<-WARN.squish, caller
155
+ checkout_attributes is deprecated, please use the permitted
156
+ attributes set for the specific step that needs to be updated.
157
+
158
+ E.g. permitted_checkout_address_attributes
159
+ WARN
160
+
161
+ CheckoutAdditionalAttributes.new(
162
+ checkout_address_attributes +
163
+ checkout_delivery_attributes +
164
+ checkout_payment_attributes +
165
+ checkout_confirm_attributes
166
+ )
167
+ end
168
+ end
169
+
170
+ class CheckoutAdditionalAttributes < Array
171
+ def <<(*attributes)
172
+ super
173
+
174
+ inject_attributes_to_all_steps(attributes, :<<)
175
+ end
176
+
177
+ def push(*attributes)
178
+ super
179
+
180
+ inject_attributes_to_all_steps(attributes, :push)
181
+ end
182
+ alias append push
183
+
184
+ def prepend(*attributes)
185
+ super
186
+
187
+ inject_attributes_to_all_steps(attributes, :prepend)
188
+ end
189
+ alias unshift prepend
190
+
191
+ private
192
+
193
+ def inject_attributes_to_all_steps(attributes, method)
194
+ attributes.each do |attribute|
195
+ PermittedAttributes.checkout_address_attributes.send(method, attribute)
196
+ PermittedAttributes.checkout_delivery_attributes.send(method, attribute)
197
+ PermittedAttributes.checkout_payment_attributes.send(method, attribute)
198
+ PermittedAttributes.checkout_confirm_attributes.send(method, attribute)
199
+ end
200
+ end
132
201
  end
133
202
  end
@@ -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
@@ -23,7 +23,14 @@ RSpec.describe Spree::Core::ControllerHelpers::StrongParameters, type: :controll
23
23
 
24
24
  describe '#permitted_checkout_attributes' do
25
25
  it 'returns Array class' do
26
- expect(controller.permitted_checkout_attributes.class).to eq Array
26
+ Spree::Deprecation.silence do
27
+ expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
28
+ end
29
+ end
30
+
31
+ it 'is deprecated' do
32
+ expect(Spree::Deprecation).to receive(:warn)
33
+ controller.permitted_checkout_attributes
27
34
  end
28
35
  end
29
36
 
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  require 'spree/core/environment_extension'
5
5
 
6
6
  RSpec.describe Spree::Core::EnvironmentExtension do
7
- let(:base) { Class.new }
7
+ let(:base) { Class.new { def self.to_s; 'ExampleClass'; end } }
8
8
  subject! { base.include(described_class).new }
9
9
 
10
10
  describe '.add_class_set' do
@@ -32,4 +32,15 @@ RSpec.describe Spree::Core::EnvironmentExtension do
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ describe '#add_class' do
37
+ it 'is deprecated' do
38
+ expect(Spree::Deprecation).to receive(:warn) do |message, _caller|
39
+ expect(message).to include('ExampleClass.add_class_set(:foo)')
40
+ end
41
+ expect(base).to receive(:add_class_set).with(:foo)
42
+
43
+ base.new.add_class(:foo)
44
+ end
45
+ end
35
46
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Spree::PermittedAttributes do
6
+ describe ".checkout_attributes" do
7
+ subject(:permitted_attributes) { described_class }
8
+
9
+ it "when read emits a deprecation warning and return all steps attributes" do
10
+ expect(Spree::Deprecation).to receive(:warn)
11
+ all_attributes = permitted_attributes.checkout_attributes
12
+
13
+ expect(all_attributes).to include(*permitted_attributes.checkout_address_attributes)
14
+ expect(all_attributes).to include(*permitted_attributes.checkout_delivery_attributes)
15
+ expect(all_attributes).to include(*permitted_attributes.checkout_payment_attributes)
16
+ end
17
+
18
+ it "when changed emits a deprecation warning and push changes to all steps' attributes" do
19
+ expect(Spree::Deprecation).to receive(:warn).exactly(4).times
20
+ permitted_attributes.checkout_attributes.push :appended_attribute
21
+ permitted_attributes.checkout_attributes.append :appended_with_alias_attribute
22
+ permitted_attributes.checkout_attributes << :another_appended_attribute
23
+ permitted_attributes.checkout_attributes.prepend :prepended_attribute
24
+
25
+ checkout_steps_attributes = [
26
+ permitted_attributes.checkout_address_attributes,
27
+ permitted_attributes.checkout_delivery_attributes,
28
+ permitted_attributes.checkout_payment_attributes,
29
+ permitted_attributes.checkout_confirm_attributes
30
+ ]
31
+
32
+ checkout_steps_attributes.each do |step_attributes|
33
+ expect(step_attributes).to include(
34
+ :appended_attribute,
35
+ :appended_with_alias_attribute,
36
+ :another_appended_attribute,
37
+ :prepended_attribute)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -101,6 +101,7 @@ RSpec.describe Spree::Promotion::Rules::Taxon, type: :model do
101
101
  before do
102
102
  taxon.children << taxon2
103
103
  taxon.save!
104
+ taxon.reload
104
105
  product.taxons = [taxon2, taxon3]
105
106
  rule.taxons = [taxon, taxon3]
106
107
  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.6
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: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -971,6 +971,7 @@ files:
971
971
  - spec/lib/spree/migrations_spec.rb
972
972
  - spec/lib/spree/money_spec.rb
973
973
  - spec/lib/spree/permission_sets/default_customer_spec.rb
974
+ - spec/lib/spree/permitted_attributes_spec.rb
974
975
  - spec/lib/spree/promo/environment_spec.rb
975
976
  - spec/lib/tasks/dummy_task.rake
976
977
  - spec/lib/tasks/dummy_task_spec.rb
@@ -1229,8 +1230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1229
1230
  - !ruby/object:Gem::Version
1230
1231
  version: 1.8.23
1231
1232
  requirements: []
1232
- rubyforge_project:
1233
- rubygems_version: 2.7.3
1233
+ rubygems_version: 3.0.3
1234
1234
  signing_key:
1235
1235
  specification_version: 4
1236
1236
  summary: Essential models, mailers, and classes for the Solidus e-commerce project.