Skip to content

Commit

Permalink
Deprecate reset_spree_preferences
Browse files Browse the repository at this point in the history
Helper method `reset_spree_preferences` has been deprecated, as its usage
contributed to the bad practice of changing Spree::Config preference values
without returning them to the original values.

Also, by using `reset_spree_preferences`, preference values set in application
initializers such as `dummy_app.rb` are lost.

As the method is now deprecated, specs that test it must temporarily change
the deprecation behavior or the test suite on circleci will fail.
  • Loading branch information
spaghetticode committed Jun 13, 2019
1 parent 62d5c01 commit b3fe321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/lib/spree/testing_support/preferences.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'spree/deprecation'

module Spree
module TestingSupport
module Preferences
Expand All @@ -10,6 +12,7 @@ module Preferences
# config.track_inventory_levels = false
# end
#
# @deprecated
def reset_spree_preferences(&config_block)
Spree::Config.instance_variables.each { |iv| Spree::Config.remove_instance_variable(iv) }
Spree::Config.preference_store = Spree::Config.default_preferences
Expand All @@ -21,6 +24,8 @@ def reset_spree_preferences(&config_block)
configure_spree_preferences(&config_block) if block_given?
end

deprecate :reset_spree_preferences, deprecator: Spree::Deprecation

def configure_spree_preferences
yield(Spree::Config) if block_given?
end
Expand Down
4 changes: 3 additions & 1 deletion core/spec/lib/spree/core/testing_support/preferences_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
describe 'resetting the app configuration' do
around do |example|
with_unfrozen_spree_preference_store do
example.run
Spree::Deprecation.silence do
example.run
end
end
end

Expand Down

0 comments on commit b3fe321

Please sign in to comment.