Module: SolidusDevSupport::TestingSupport::Preferences

Defined in:
lib/solidus_dev_support/testing_support/preferences.rb

Instance Method Summary collapse

Instance Method Details

#stub_spree_preferences(prefs_or_conf_class, prefs = nil) ⇒ Object

This wrapper method allows to stub spree preferences using the new standard way of solidus core but also works with old versions that does not have the stub_spree_preferences method yet. This way we can start using this method in our extensions safely.

To have this available, it is needed to require in the spec/spec_helper.rb of the extension both:

require ‘spree/testing_support/preferences’ require ‘solidus_dev_support/testing_support/preferences’

Examples:

Set a preference on Spree::Config

stub_spree_preferences(allow_guest_checkout: false)

Set a preference on Spree::Api::Config

stub_spree_preferences(Spree::Api::Config, requires_authentication: false)

Set a preference on a custom Spree::CustomExtension::Config

stub_spree_preferences(Spree::CustomExtension::Config, custom_pref: true)

Parameters:

  • prefs_or_conf_class (Class, Hash)

    the class we want to stub preferences for or the preferences hash (see prefs param). If this param is an Hash, preferences will be stubbed on Spree::Config.

  • prefs (Hash, nil) (defaults to: nil)

    names and values to be stubbed



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/solidus_dev_support/testing_support/preferences.rb', line 31

def stub_spree_preferences(prefs_or_conf_class, prefs = nil)
  super && return if SolidusDevSupport.reset_spree_preferences_deprecated?

  if prefs_or_conf_class.is_a?(Hash)
    preference_store_class = Spree::Config
    preferences = prefs_or_conf_class
  else
    preference_store_class = prefs_or_conf_class
    preferences = prefs
  end
  preference_store_class.set(preferences)
end