solidus_core 2.8.6 → 2.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.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/logo/solidus.svg +1 -18
  3. data/app/assets/images/logo/solidus_logo.png +0 -0
  4. data/app/mailers/spree/test_mailer.rb +2 -0
  5. data/app/models/concerns/spree/default_price.rb +1 -1
  6. data/app/models/concerns/spree/ransackable_attributes.rb +1 -1
  7. data/app/models/concerns/spree/user_reporting.rb +1 -1
  8. data/app/models/spree/billing_integration.rb +7 -2
  9. data/app/models/spree/country.rb +2 -0
  10. data/app/models/spree/customer_return.rb +1 -1
  11. data/app/models/spree/image/paperclip_attachment.rb +55 -0
  12. data/app/models/spree/image.rb +2 -44
  13. data/app/models/spree/inventory_unit.rb +0 -1
  14. data/app/models/spree/option_type.rb +2 -0
  15. data/app/models/spree/option_value.rb +1 -1
  16. data/app/models/spree/order.rb +8 -13
  17. data/app/models/spree/payment.rb +1 -1
  18. data/app/models/spree/payment_method.rb +8 -4
  19. data/app/models/spree/product.rb +1 -1
  20. data/app/models/spree/promotion/rules/first_order.rb +1 -3
  21. data/app/models/spree/promotion/rules/item_total.rb +9 -1
  22. data/app/models/spree/promotion/rules/one_use_per_user.rb +2 -2
  23. data/app/models/spree/promotion/rules/product.rb +3 -3
  24. data/app/models/spree/promotion/rules/taxon.rb +5 -8
  25. data/app/models/spree/promotion/rules/user_logged_in.rb +1 -1
  26. data/app/models/spree/promotion.rb +18 -11
  27. data/app/models/spree/promotion_handler/coupon.rb +19 -3
  28. data/app/models/spree/property.rb +2 -0
  29. data/app/models/spree/reimbursement.rb +5 -5
  30. data/app/models/spree/return_item.rb +6 -2
  31. data/app/models/spree/state.rb +6 -0
  32. data/app/models/spree/stock/location_filter/active.rb +14 -0
  33. data/app/models/spree/stock/location_filter/base.rb +43 -0
  34. data/app/models/spree/stock/simple_coordinator.rb +4 -1
  35. data/app/models/spree/stock_location.rb +2 -0
  36. data/app/models/spree/tax_category.rb +11 -0
  37. data/app/models/spree/taxon/paperclip_attachment.rb +21 -0
  38. data/app/models/spree/taxon.rb +4 -11
  39. data/app/models/spree/taxonomy.rb +2 -0
  40. data/app/models/spree/unit_cancel.rb +12 -1
  41. data/app/models/spree/variant/pricing_options.rb +10 -0
  42. data/app/models/spree/variant.rb +1 -1
  43. data/app/models/spree/wallet_payment_source.rb +26 -10
  44. data/app/models/spree/zone.rb +1 -1
  45. data/app/subscribers/spree/mailer_subscriber.rb +25 -0
  46. data/app/views/spree/order_mailer/inventory_cancellation_email.text.erb +3 -3
  47. data/config/locales/en.yml +26 -53
  48. data/db/default/spree/store_credit.rb +1 -0
  49. data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +1 -1
  50. data/db/migrate/20170608074534_rename_bogus_gateways.rb +9 -8
  51. data/db/migrate/20190220093635_drop_spree_store_credit_update_reasons.rb +19 -0
  52. data/lib/generators/spree/install/install_generator.rb +21 -19
  53. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +29 -1
  54. data/lib/solidus/migrations/rename_gateways.rb +2 -0
  55. data/lib/spree/app_configuration.rb +69 -47
  56. data/lib/spree/core/class_constantizer.rb +6 -0
  57. data/lib/spree/core/controller_helpers/pricing.rb +1 -4
  58. data/lib/spree/core/controller_helpers/strong_parameters.rb +7 -21
  59. data/lib/spree/core/engine.rb +11 -0
  60. data/lib/spree/core/environment/promotions.rb +15 -0
  61. data/lib/spree/core/environment.rb +1 -1
  62. data/lib/spree/core/environment_extension.rb +0 -4
  63. data/lib/spree/core/importer/order.rb +1 -3
  64. data/lib/spree/core/stock_configuration.rb +5 -0
  65. data/lib/spree/core/version.rb +3 -1
  66. data/lib/spree/core.rb +2 -0
  67. data/lib/spree/deprecation.rb +50 -0
  68. data/lib/spree/event/adapters/active_support_notifications.rb +35 -0
  69. data/lib/spree/event/configuration.rb +25 -0
  70. data/lib/spree/event/subscriber.rb +84 -0
  71. data/lib/spree/event.rb +117 -0
  72. data/lib/spree/permitted_attributes.rb +7 -76
  73. data/lib/spree/promo/environment.rb +6 -7
  74. data/lib/spree/testing_support/capybara_ext.rb +15 -0
  75. data/lib/spree/testing_support/common_rake.rb +1 -1
  76. data/lib/spree/testing_support/dummy_app.rb +3 -10
  77. data/lib/spree/testing_support/factories/promotion_factory.rb +10 -0
  78. data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
  79. data/lib/spree/testing_support/preferences.rb +62 -0
  80. data/lib/tasks/email.rake +2 -0
  81. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +4 -0
  82. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +2 -0
  83. data/lib/tasks/migrations/migrate_user_addresses.rake +3 -0
  84. data/lib/tasks/migrations/rename_gateways.rake +2 -0
  85. data/lib/tasks/order_capturing.rake +2 -0
  86. data/spec/helpers/base_helper_spec.rb +3 -3
  87. data/spec/helpers/products_helper_spec.rb +2 -2
  88. data/spec/lib/spree/app_configuration_spec.rb +140 -0
  89. data/spec/lib/spree/core/class_constantizer_spec.rb +20 -0
  90. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +13 -0
  91. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +1 -8
  92. data/spec/lib/spree/core/environment_extension_spec.rb +22 -23
  93. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +1 -1
  94. data/spec/lib/spree/core/testing_support/preferences_spec.rb +33 -0
  95. data/spec/lib/spree/event/subscriber_spec.rb +85 -0
  96. data/spec/lib/spree/event_spec.rb +118 -0
  97. data/spec/lib/spree/money_spec.rb +3 -9
  98. data/spec/lib/spree/promo/environment_spec.rb +53 -0
  99. data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +5 -3
  100. data/spec/mailers/order_mailer_spec.rb +1 -1
  101. data/spec/mailers/test_mailer_spec.rb +3 -1
  102. data/spec/models/spree/address_spec.rb +5 -4
  103. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  104. data/spec/models/spree/country_spec.rb +5 -5
  105. data/spec/models/spree/customer_return_spec.rb +1 -1
  106. data/spec/models/spree/order/checkout_spec.rb +3 -7
  107. data/spec/models/spree/order/finalizing_spec.rb +1 -1
  108. data/spec/models/spree/order/payment_spec.rb +3 -3
  109. data/spec/models/spree/order_inventory_spec.rb +1 -1
  110. data/spec/models/spree/order_spec.rb +67 -2
  111. data/spec/models/spree/order_updater_spec.rb +2 -2
  112. data/spec/models/spree/payment_spec.rb +12 -0
  113. data/spec/models/spree/product_spec.rb +3 -3
  114. data/spec/models/spree/promotion/rules/first_order_spec.rb +13 -3
  115. data/spec/models/spree/promotion/rules/item_total_spec.rb +15 -0
  116. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +10 -0
  117. data/spec/models/spree/promotion/rules/product_spec.rb +15 -0
  118. data/spec/models/spree/promotion/rules/taxon_spec.rb +59 -8
  119. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +5 -0
  120. data/spec/models/spree/promotion_handler/shipping_spec.rb +1 -1
  121. data/spec/models/spree/promotion_spec.rb +80 -0
  122. data/spec/models/spree/reimbursement_spec.rb +3 -2
  123. data/spec/models/spree/return_item_spec.rb +9 -0
  124. data/spec/models/spree/shipment_spec.rb +3 -3
  125. data/spec/models/spree/stock/availability_spec.rb +1 -1
  126. data/spec/models/spree/stock/estimator_spec.rb +5 -7
  127. data/spec/models/spree/stock/location_filter/active_spec.rb +22 -0
  128. data/spec/models/spree/stock/location_sorter/default_first_spec.rb +4 -2
  129. data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +3 -1
  130. data/spec/models/spree/stock/quantifier_spec.rb +1 -1
  131. data/spec/models/spree/stock/simple_coordinator_spec.rb +5 -0
  132. data/spec/models/spree/stock_item_spec.rb +3 -2
  133. data/spec/models/spree/stock_movement_spec.rb +1 -1
  134. data/spec/models/spree/store_credit_spec.rb +1 -1
  135. data/spec/models/spree/tax/order_adjuster_spec.rb +1 -1
  136. data/spec/models/spree/tax/taxation_integration_spec.rb +1 -1
  137. data/spec/models/spree/tax_category_spec.rb +21 -0
  138. data/spec/models/spree/taxon_spec.rb +28 -0
  139. data/spec/models/spree/unit_cancel_spec.rb +41 -0
  140. data/spec/models/spree/user_spec.rb +3 -3
  141. data/spec/models/spree/variant/pricing_options_spec.rb +23 -0
  142. data/spec/models/spree/variant/vat_price_generator_spec.rb +1 -1
  143. data/spec/models/spree/variant_spec.rb +11 -8
  144. data/spec/models/spree/wallet_payment_source_spec.rb +35 -6
  145. data/spec/models/spree/wallet_spec.rb +1 -1
  146. data/spec/rails_helper.rb +1 -0
  147. data/spec/spec_helper.rb +0 -4
  148. data/spec/support/concerns/default_price.rb +8 -0
  149. metadata +21 -6
  150. data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
  151. data/spec/models/spree/app_configuration_spec.rb +0 -55
  152. /data/{spec/support/shared_contexts → lib/spree/testing_support}/rake.rb +0 -0
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'event/adapters/active_support_notifications'
4
+ require_relative 'event/configuration'
5
+ require_relative 'event/subscriber'
6
+
7
+ module Spree
8
+ module Event
9
+ extend self
10
+
11
+ # Allows to trigger events that can be subscribed using #subscribe. An
12
+ # optional block can be passed that will be executed immediately. The
13
+ # actual code implementation is delegated to the adapter.
14
+ #
15
+ # @param [String] event_name the name of the event. The suffix ".spree"
16
+ # will be added automatically if not present
17
+ # @param [Hash] opts a list of options to be passed to the triggered event
18
+ #
19
+ # @example Trigger an event named 'order_finalized'
20
+ # Spree::Event.fire 'order_finalized', order: @order do
21
+ # @order.finalize!
22
+ # end
23
+ def fire(event_name, opts = {})
24
+ adapter.fire name_with_suffix(event_name.to_s), opts do
25
+ yield opts if block_given?
26
+ end
27
+ end
28
+
29
+ # Subscribe to an event with the given name. The provided block is executed
30
+ # every time the subscribed event is fired.
31
+ #
32
+ # @param [String] event_name the name of the event. The suffix ".spree"
33
+ # will be added automatically if not present
34
+ #
35
+ # @return a subscription object that can be used as reference in order
36
+ # to remove the subscription
37
+ #
38
+ # @example Subscribe to the `order_finalized` event
39
+ # Spree::Event.subscribe 'order_finalized' do |event|
40
+ # order = event.payload[:order]
41
+ # Spree::Mailer.order_finalized(order).deliver_later
42
+ # end
43
+ #
44
+ # @see Spree::Event#unsubscribe
45
+ def subscribe(event_name, &block)
46
+ name = name_with_suffix(event_name)
47
+ listener_names << name
48
+ adapter.subscribe(name, &block)
49
+ end
50
+
51
+ # Unsubscribes a whole event or a specific subscription object
52
+ #
53
+ # @param [String, Object] subscriber the event name as a string (with
54
+ # or without the ".spree" suffix) or the subscription object
55
+ #
56
+ # @example Unsubscribe a single subscription
57
+ # subscription = Spree::Event.fire 'order_finalized'
58
+ # Spree::Event.unsubscribe(subscription)
59
+ # @example Unsubscribe all `order_finalized` event subscriptions
60
+ # Spree::Event.unsubscribe('order_finalized')
61
+ # @example Unsubscribe an event by name with explicit prefix
62
+ # Spree::Event.unsubscribe('order_finalized.spree')
63
+ def unsubscribe(subscriber)
64
+ name_or_subscriber = subscriber.is_a?(String) ? name_with_suffix(subscriber) : subscriber
65
+ adapter.unsubscribe(name_or_subscriber)
66
+ end
67
+
68
+ # Lists all subscriptions currently registered under the ".spree"
69
+ # namespace. Actual implementation is delegated to the adapter
70
+ #
71
+ # @return [Hash] an hash with event names as keys and arrays of subscriptions
72
+ # as values
73
+ #
74
+ # @example Current subscriptions
75
+ # Spree::Event.listeners
76
+ # # => {"order_finalized.spree"=> [#<ActiveSupport...>],
77
+ # "reimbursement_reimbursed.spree"=> [#<ActiveSupport...>]}
78
+ def listeners
79
+ adapter.listeners_for(listener_names)
80
+ end
81
+
82
+ # The adapter used by Spree::Event, defaults to
83
+ # Spree::Event::Adapters::ActiveSupportNotifications
84
+ #
85
+ # @example Change the adapter
86
+ # Spree::Config.events.adapter = "Spree::EventBus.new"
87
+ #
88
+ # @see Spree::AppConfiguration
89
+ def adapter
90
+ Spree::Config.events.adapter
91
+ end
92
+
93
+ # The suffix used for namespacing Solidus events, defaults to
94
+ # `.spree`
95
+ #
96
+ # @see Spree::Event::Configuration#suffix
97
+ def suffix
98
+ Spree::Config.events.suffix
99
+ end
100
+
101
+ # @!attribute [r] subscribers
102
+ # @return [Array<Spree::Event::Subscriber>] A list of subscribers used to support class reloading for Spree::Event::Subscriber instances
103
+ def subscribers
104
+ Spree::Config.events.subscribers
105
+ end
106
+
107
+ private
108
+
109
+ def name_with_suffix(name)
110
+ name.end_with?(suffix) ? name : [name, suffix].join
111
+ end
112
+
113
+ def listener_names
114
+ @listeners_names ||= Set.new
115
+ end
116
+ end
117
+ end
@@ -8,10 +8,7 @@ module Spree
8
8
  ATTRIBUTES = [
9
9
  :address_attributes,
10
10
  :address_book_attributes,
11
- :checkout_address_attributes,
12
- :checkout_delivery_attributes,
13
- :checkout_payment_attributes,
14
- :checkout_confirm_attributes,
11
+ :checkout_attributes,
15
12
  :credit_card_update_attributes,
16
13
  :customer_return_attributes,
17
14
  :image_attributes,
@@ -48,6 +45,10 @@ module Spree
48
45
 
49
46
  @@address_book_attributes = address_attributes + [:default]
50
47
 
48
+ @@checkout_attributes = [
49
+ :coupon_code, :email, :special_instructions, :use_billing
50
+ ]
51
+
51
52
  @@credit_card_update_attributes = [
52
53
  :month, :year, :expiry, :first_name, :last_name, :name
53
54
  ]
@@ -78,7 +79,7 @@ module Spree
78
79
 
79
80
  @@property_attributes = [:name, :presentation]
80
81
 
81
- @@return_authorization_attributes = [:memo, :stock_location_id, :return_reason_id, return_items_attributes: [:inventory_unit_id, :exchange_variant_id, :return_reason_id]]
82
+ @@return_authorization_attributes = [:memo, :stock_location_id, :return_reason_id, return_items_attributes: [:inventory_unit_id, :exchange_variant_id, :return_reason_id, :preferred_reimbursement_type_id]]
82
83
 
83
84
  @@shipment_attributes = [
84
85
  :special_instructions, :stock_location_id, :id, :tracking,
@@ -90,7 +91,7 @@ module Spree
90
91
  :number, :month, :year, :expiry, :verification_value,
91
92
  :first_name, :last_name, :cc_type, :gateway_customer_profile_id,
92
93
  :gateway_payment_profile_id, :last_digits, :name, :encrypted_data,
93
- :existing_card_id, :wallet_payment_source_id, address_attributes: address_attributes
94
+ :existing_card_id, :wallet_payment_source_id
94
95
  ]
95
96
 
96
97
  @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]
@@ -128,75 +129,5 @@ module Spree
128
129
  :product_id, :product, :option_values_attributes, :price,
129
130
  :weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
130
131
  ]
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
201
132
  end
202
133
  end
@@ -2,12 +2,11 @@
2
2
 
3
3
  module Spree
4
4
  module Promo
5
- class Environment
6
- include Core::EnvironmentExtension
7
-
8
- add_class_set :rules
9
- add_class_set :actions
10
- add_class_set :shipping_actions
11
- end
5
+ Environment =
6
+ ActiveSupport::Deprecation::DeprecatedConstantProxy.new(
7
+ 'Spree::Promo::Environment',
8
+ 'Spree::Core::Environment::Promotions',
9
+ Spree::Deprecation
10
+ )
12
11
  end
13
12
  end
@@ -12,6 +12,21 @@ module Spree
12
12
  fill_in field, options
13
13
  end
14
14
 
15
+ def fill_in_with_force(locator, with:)
16
+ if Capybara.current_driver == Capybara.javascript_driver
17
+ field_id = find_field(locator)[:id]
18
+ page.execute_script <<-JS
19
+ var field = document.getElementById('#{field_id}');
20
+ field.value = '#{with}';
21
+
22
+ var event = new Event('change', { bubbles: true });
23
+ field.dispatchEvent(event);
24
+ JS
25
+ else
26
+ fill_in locator, with: with
27
+ end
28
+ end
29
+
15
30
  def within_row(num, &block)
16
31
  within("table.index tbody tr:nth-of-type(#{num})", &block)
17
32
  end
@@ -24,7 +24,7 @@ namespace :common do
24
24
  begin
25
25
  require "generators/#{ENV['LIB_NAME']}/install/install_generator"
26
26
  puts 'Running extension installation generator...'
27
- "#{ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
27
+ "#{ENV['LIB_NAMESPACE'] || ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
28
28
  rescue LoadError
29
29
  # No extension generator to run
30
30
  end
@@ -12,14 +12,11 @@ Rails.env = 'test'
12
12
 
13
13
  require 'solidus_core'
14
14
 
15
- # @private
16
- def forgery_protected_by_default?
17
- Gem::Version.new(Rails.version) >= Gem::Version.new('5.2')
18
- end
15
+ RAILS_52_OR_ABOVE = Gem::Version.new(Rails.version) >= Gem::Version.new('5.2')
19
16
 
20
17
  # @private
21
18
  class ApplicationController < ActionController::Base
22
- if !forgery_protected_by_default?
19
+ unless RAILS_52_OR_ABOVE
23
20
  protect_from_forgery with: :exception
24
21
  end
25
22
  end
@@ -65,12 +62,8 @@ module DummyApp
65
62
  config.active_support.deprecation = :stderr
66
63
  config.secret_key_base = 'SECRET_TOKEN'
67
64
 
68
- if forgery_protected_by_default?
65
+ if RAILS_52_OR_ABOVE
69
66
  config.action_controller.default_protect_from_forgery = true
70
- end
71
-
72
- if config.active_record.sqlite3
73
- # Rails >= 5.2
74
67
  config.active_record.sqlite3.represent_boolean_as_integer = true
75
68
  end
76
69
 
@@ -60,5 +60,15 @@ FactoryBot.define do
60
60
  end
61
61
  end
62
62
  factory :promotion_with_item_total_rule, traits: [:with_item_total_rule]
63
+ trait :with_first_order_rule do
64
+ after(:create) do |promotion, _evaluator|
65
+ rule = Spree::Promotion::Rules::FirstOrder.create!(
66
+ promotion: promotion,
67
+ )
68
+ promotion.rules << rule
69
+ promotion.save!
70
+ end
71
+ end
72
+ factory :promotion_with_first_order_rule, traits: [:with_first_order_rule]
63
73
  end
64
74
  end
@@ -6,6 +6,7 @@ require 'spree/testing_support/factories/return_authorization_factory'
6
6
 
7
7
  FactoryBot.define do
8
8
  factory :return_item, class: 'Spree::ReturnItem' do
9
+ skip_customer_return_processing { true }
9
10
  association(:inventory_unit, factory: :inventory_unit, state: :shipped)
10
11
  association(:return_reason, factory: :return_reason)
11
12
  return_authorization do |_return_item|
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/deprecation'
4
+
3
5
  module Spree
4
6
  module TestingSupport
5
7
  module Preferences
@@ -10,6 +12,7 @@ module Spree
10
12
  # config.track_inventory_levels = false
11
13
  # end
12
14
  #
15
+ # @deprecated
13
16
  def reset_spree_preferences(&config_block)
14
17
  Spree::Config.instance_variables.each { |iv| Spree::Config.remove_instance_variable(iv) }
15
18
  Spree::Config.preference_store = Spree::Config.default_preferences
@@ -21,6 +24,8 @@ module Spree
21
24
  configure_spree_preferences(&config_block) if block_given?
22
25
  end
23
26
 
27
+ deprecate :reset_spree_preferences, deprecator: Spree::Deprecation
28
+
24
29
  def configure_spree_preferences
25
30
  yield(Spree::Config) if block_given?
26
31
  end
@@ -29,6 +34,63 @@ module Spree
29
34
  find("#preferences_#{preference}")['checked'].should be false
30
35
  Spree::Config[preference].should be false
31
36
  end
37
+
38
+ # This is the preferred way for changing temporarily Spree preferences during
39
+ # tests via stubs, without changing the actual values stored in Spree::Config.
40
+ #
41
+ # By using stubs no global preference change will leak outside the lifecycle
42
+ # of each spec example, avoiding possible unpredictable side effects.
43
+ #
44
+ # This method may be used for stubbing one or more different preferences
45
+ # at the same time.
46
+ #
47
+ # @param [Hash] preferences names and values to be stubbed
48
+ #
49
+ # @example Stubs `currency` and `track_inventory_levels` preferences
50
+ # stub_spree_preferences(currency: 'EUR', track_inventory_levels: false)
51
+ # expect(Spree::Config.currency).to eql 'EUR'
52
+ #
53
+ # @see https://github.com/solidusio/solidus/issues/3219
54
+ # Solidus #3219 for more details and motivations.
55
+ def stub_spree_preferences(preferences)
56
+ preferences.each do |name, value|
57
+ if Spree::Config.method(:[]).owner >= Spree::Config.class
58
+ allow(Spree::Config).to receive(:[]).and_call_original
59
+ end
60
+ allow(Spree::Config).to receive(:[]).with(name) { value }
61
+ allow(Spree::Config).to receive(name) { value }
62
+ end
63
+ end
64
+
65
+ # This method allows to temporarily switch to an unfrozen Spree::Config preference
66
+ # store with all proper preferences values set.
67
+ #
68
+ # It should be used sparingly, only when `stub_spree_preferences` would not work.
69
+ #
70
+ # @example Temporarily switch to an unfrozen store and change some preferences:
71
+ # with_unfrozen_spree_preference_store do
72
+ # Spree::Config.currency = 'EUR'
73
+ # Spree::Config.track_inventory_levels = false
74
+ #
75
+ # expect(Spree::Config.currency).to eql 'EUR'
76
+ # end
77
+ # @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
81
+ yield
82
+ ensure
83
+ Spree::Config.preference_store = frozen_store
84
+ end
32
85
  end
33
86
  end
34
87
  end
88
+
89
+ RSpec.configure do |config|
90
+ 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
95
+ end
96
+ end
data/lib/tasks/email.rake CHANGED
@@ -3,6 +3,8 @@
3
3
  namespace :email do
4
4
  desc 'Sends test email to specified address - Example: EMAIL=spree@example.com bundle exec rake email:test'
5
5
  task test: :environment do
6
+ Spree::Deprecation.warn("rake email:test has been deprecated and will be removed with Solidus 3.0")
7
+
6
8
  raise ArgumentError, "Must pass EMAIL environment variable. Example: EMAIL=spree@example.com bundle exec rake email:test" unless ENV['EMAIL'].present?
7
9
  Spree::TestMailer.test_email(ENV['EMAIL']).deliver!
8
10
  end
@@ -13,6 +13,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
13
13
  # This task should be safe to run multiple times.
14
14
 
15
15
  task up: :environment do
16
+ Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:up has been deprecated and will be removed with Solidus 3.0.")
17
+
16
18
  if Spree::CreditCard.connection.adapter_name =~ /postgres/i
17
19
  postgres_copy
18
20
  else
@@ -21,6 +23,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
21
23
  end
22
24
 
23
25
  task down: :environment do
26
+ Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:down has been deprecated and will be removed with Solidus 3.0.")
27
+
24
28
  Spree::CreditCard.update_all(address_id: nil)
25
29
  end
26
30
 
@@ -4,6 +4,8 @@ namespace :solidus do
4
4
  namespace :migrations do
5
5
  namespace :migrate_shipping_rate_taxes do
6
6
  task up: :environment do
7
+ Spree::Deprecation.warn("rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated and will be removed with Solidus 3.0.")
8
+
7
9
  print "Adding persisted tax notes to historic shipping rates ... "
8
10
  Spree::ShippingRate.where.not(tax_rate_id: nil).find_each do |shipping_rate|
9
11
  tax_rate = Spree::TaxRate.unscoped.find(shipping_rate.tax_rate_id)
@@ -10,6 +10,8 @@ namespace 'spree:migrations:migrate_user_addresses' do
10
10
  # to the user's address book. This will catch up all the historical data.
11
11
 
12
12
  task up: :environment do
13
+ Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:up has been deprecated and will be removed with Solidus 3.0.")
14
+
13
15
  Spree.user_class.find_each(batch_size: 500) do |user|
14
16
  ship_address = Spree::Address.find_by(id: user.ship_address_id)
15
17
  bill_address = Spree::Address.find_by(id: user.bill_address_id)
@@ -26,6 +28,7 @@ namespace 'spree:migrations:migrate_user_addresses' do
26
28
  end
27
29
 
28
30
  task down: :environment do
31
+ Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:down has been deprecated and will be removed with Solidus 3.0.")
29
32
  Spree::UserAddress.delete_all
30
33
  end
31
34
  end
@@ -4,6 +4,7 @@ require 'solidus/migrations/rename_gateways'
4
4
 
5
5
  namespace 'solidus:migrations:rename_gateways' do
6
6
  task up: :environment do
7
+ Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:up has been deprecated and will be removed with Solidus 3.0.")
7
8
  count = Solidus::Migrations::RenameGateways.new.up
8
9
 
9
10
  unless ENV['VERBOSE'] == 'false' || !verbose
@@ -12,6 +13,7 @@ namespace 'solidus:migrations:rename_gateways' do
12
13
  end
13
14
 
14
15
  task down: :environment do
16
+ Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:down has been deprecated and will be removed with Solidus 3.0.")
15
17
  count = Solidus::Migrations::RenameGateways.new.down
16
18
 
17
19
  unless ENV['VERBOSE'] == 'false' || !verbose
@@ -3,6 +3,8 @@
3
3
  namespace :order_capturing do
4
4
  desc "Looks for orders with inventory that is fully shipped/short-shipped, and captures money for it"
5
5
  task capture_payments: :environment do
6
+ Spree::Deprecation.warn("rake order_capturing:capture_payments has been deprecated and will be removed with Solidus 3.0.")
7
+
6
8
  failures = []
7
9
  orders = Spree::Order.complete.where(payment_state: 'balance_due').where('completed_at > ?', Spree::Config[:order_capturing_time_window].days.ago)
8
10
 
@@ -16,7 +16,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
16
16
 
17
17
  context "with no checkout zone defined" do
18
18
  before do
19
- Spree::Config[:checkout_zone] = nil
19
+ stub_spree_preferences(checkout_zone: nil)
20
20
  end
21
21
 
22
22
  it "return complete list of countries" do
@@ -33,7 +33,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
33
33
  before do
34
34
  @country_zone = create(:zone, name: "CountryZone")
35
35
  @country_zone.members.create(zoneable: country)
36
- Spree::Config[:checkout_zone] = @country_zone.name
36
+ stub_spree_preferences(checkout_zone: @country_zone.name)
37
37
  end
38
38
 
39
39
  it "return only the countries defined by the checkout zone" do
@@ -50,7 +50,7 @@ RSpec.describe Spree::BaseHelper, type: :helper do
50
50
  state_zone = create(:zone, name: "StateZone")
51
51
  state = create(:state, country: country)
52
52
  state_zone.members.create(zoneable: state)
53
- Spree::Config[:checkout_zone] = state_zone.name
53
+ stub_spree_preferences(checkout_zone: state_zone.name)
54
54
  end
55
55
 
56
56
  it "return complete list of countries" do
@@ -75,7 +75,7 @@ module Spree
75
75
  let(:variant_price) { 15 }
76
76
 
77
77
  before do
78
- Spree::Config[:show_variant_full_price] = true
78
+ stub_spree_preferences(show_variant_full_price: true)
79
79
  variant
80
80
  end
81
81
 
@@ -148,7 +148,7 @@ THIS IS THE BEST PRODUCT EVER!
148
148
 
149
149
  product.description = description
150
150
 
151
- Spree::Config[:show_raw_product_description] = true
151
+ stub_spree_preferences(show_raw_product_description: true)
152
152
  description = product_description(product)
153
153
  expect(description).to eq(description)
154
154
  end