Skip to content

Commit

Permalink
Switch core to use Spree::Config.environment
Browse files Browse the repository at this point in the history
This is clearer and more direct than going through the rails
environment, as we're setting and retrieving settings we directly
control.
  • Loading branch information
Clarke Brunsdon committed Oct 16, 2017
1 parent f182f71 commit c6dc9bb
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/app/models/concerns/spree/calculated_adjustments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def model_name_without_spree_namespace
end

def spree_calculators
Rails.application.config.spree.calculators
Spree::Config.environment.calculators
end
end

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.description
def self.calculators
Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")

Rails.application.config.spree.calculators
Spree::Config.environment.calculators
end

def to_s
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class << self
def providers
Spree::Deprecation.warn 'Spree::PaymentMethod.providers is deprecated and will be deleted in Solidus 3.0. ' \
'Please use Rails.application.config.spree.payment_methods instead'
Rails.application.config.spree.payment_methods
Spree::Config.environment.payment_methods
end

def available(display_on = nil, store: nil)
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/promotion_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PromotionAction < Spree::Base
belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions

scope :of_type, ->(t) { where(type: Array.wrap(t).map(&:to_s)) }
scope :shipping, -> { of_type(Rails.application.config.spree.promotions.shipping_actions.to_a) }
scope :shipping, -> { of_type(Spree::Config.environment.promotions.shipping_actions.to_a) }

# Updates the state of the order or performs some other action depending on
# the subclass options will contain the payload from the event that
Expand Down
4 changes: 2 additions & 2 deletions core/app/models/spree/stock/simple_coordinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Stock
# * Combine allocated and on hand inventory into a single shipment per-location
#
# After allocation, splitters are run on each Package (as configured in
# Rails.application.config.spree.stock_splitters)
# Spree::Config.environment.stock_splitters)
#
# Finally, shipping rates are calculated using the class configured as
# Spree::Config.stock.estimator_class.
Expand All @@ -20,7 +20,7 @@ class SimpleCoordinator
def initialize(order, inventory_units = nil)
@order = order
@inventory_units = inventory_units || InventoryUnitBuilder.new(order).units
@splitters = Rails.application.config.spree.stock_splitters
@splitters = Spree::Config.environment.stock_splitters
@stock_locations = Spree::StockLocation.active

@inventory_units_by_variant = @inventory_units.group_by(&:variant)
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/preferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Preferences
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
Rails.application.config.spree = Spree::Config.environment

configure_spree_preferences(&config_block) if block_given?
end
Expand Down
7 changes: 1 addition & 6 deletions core/spec/models/spree/promotion_handler/shipping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,11 @@ module PromotionHandler
before do
stub_const('CustomShippingAction', custom_klass)

@old_shipping_actions = Rails.application.config.spree.promotions.shipping_actions
Rails.application.config.spree.promotions.shipping_actions = ['CustomShippingAction']
Spree::Config.environment.promotions.shipping_actions = ['CustomShippingAction']

order.order_promotions.create!(promotion: promotion, promotion_code: promotion.codes.first)
end

after do
Rails.application.config.spree.promotions.shipping_actions = @old_shipping_actions
end

let(:action) { custom_klass.new }
let(:custom_klass) { Class.new(Spree::Promotion::Actions::FreeShipping) }
let(:promotion) { create(:promotion, code: 'customshipping', promotion_actions: [action]) }
Expand Down

0 comments on commit c6dc9bb

Please sign in to comment.