Merge pull request #1904 from oeoeaio/spree-test-config

Use Spree's approach for preventing config caching when testing
This commit is contained in:
Enrico Stano
2017-12-04 15:57:11 +11:00
committed by GitHub
9 changed files with 24 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ class Enterprise < ActiveRecord::Base
# This is hopefully a temporary measure, pending the arrival of multiple named inventories
# for shops. We need this here to allow hubs to restrict visible variants to only those in
# their inventory if they so choose
# TODO: delegate this to a separate model instead of abusing Preferences.
preference :product_selection_from_inventory_only, :boolean, default: false
devise :confirmable, reconfirmable: true, confirmation_keys: [ :id, :email ]

View File

@@ -103,7 +103,6 @@ describe EnterprisesController, type: :controller do
order.set_distribution! current_distributor, order_cycle
order.line_items << line_item
Spree::Config.set allow_backorders: false
variant.on_hand = 0
variant.save!
end

View File

@@ -51,7 +51,6 @@ describe Spree::OrdersController, type: :controller do
let(:line_item) { order.line_items.last }
before do
Spree::Config.allow_backorders = false
order.set_distribution! d, oc
order.add_variant variant, 5
variant.update_attributes! on_hand: 3

View File

@@ -109,7 +109,6 @@ feature %q{
let!(:li1) { create(:line_item, order: o1, :quantity => 5 ) }
before :each do
Spree::Config.set(allow_backorders: false)
li1.variant.update_attributes(on_hand: 1, on_demand: false)
visit '/admin/orders/bulk_management'
end

View File

@@ -273,6 +273,10 @@ feature %q{
before do
Delayed::Job.destroy_all
quick_login_as_admin
# This test relies on preference persistence, so we'll turn it on for this spec only.
# It will be turned off again automatically by reset_spree_preferences in spec_helper.
Spree::Preferences::Store.instance.persistence = true
end
it "refreshes the cache when I change what products appear on my shopfront" do

View File

@@ -20,13 +20,6 @@ feature "full-page cart", js: true do
set_order order
end
around do |example|
allow_backorders = Spree::Config.allow_backorders
Spree::Config.allow_backorders = false
example.run
Spree::Config.allow_backorders = allow_backorders
end
describe "product description" do
it "does not link to the product page" do
add_product_to_cart order, product_fee, quantity: 2

View File

@@ -47,7 +47,6 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
describe "when I have an out of stock product in my cart" do
before do
Spree::Config.set allow_backorders: false
variant.on_hand = 0
variant.save!
end
@@ -392,7 +391,6 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
end
it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do
Spree::Config.set allow_backorders: false
variant.on_hand = 0
variant.save!

View File

@@ -196,8 +196,6 @@ module Spree
let(:v) { double(:variant, on_hand: 10) }
context "when backorders are not allowed" do
before { Spree::Config.allow_backorders = false }
context "when max_quantity is not provided" do
it "returns full amount when available" do
op.quantities_to_add(v, 5, nil).should == [5, nil]
@@ -220,10 +218,8 @@ module Spree
end
context "when backorders are allowed" do
around do |example|
before do
Spree::Config.allow_backorders = true
example.run
Spree::Config.allow_backorders = false
end
it "does not limit quantity" do

View File

@@ -29,6 +29,7 @@ require 'spree/api/testing_support/setup'
require 'spree/api/testing_support/helpers'
require 'spree/api/testing_support/helpers_decorator'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/preferences'
# Capybara config
require 'capybara/poltergeist'
@@ -101,8 +102,23 @@ RSpec.configure do |config|
# Geocoding
config.before(:each) { allow_any_instance_of(Spree::Address).to receive(:geocode).and_return([1,1]) }
default_country_id = Spree::Config[:default_country_id]
checkout_zone = Spree::Config[:checkout_zone]
currency = Spree::Config[:currency]
# Ensure we start with consistent config settings
config.before(:each) { Spree::Config.products_require_tax_category = false }
config.before(:each) do
reset_spree_preferences do |spree_config|
# These are all settings that differ from Spree's defaults
spree_config.default_country_id = default_country_id
spree_config.checkout_zone = checkout_zone
spree_config.currency = currency
spree_config.shipping_instructions = true
spree_config.auto_capture = true
spree_config.allow_backorders = false
end
Spree::Api::Config[:requires_authentication] = true
end
# Helpers
config.include Rails.application.routes.url_helpers
@@ -110,6 +126,7 @@ RSpec.configure do |config|
config.include Spree::CheckoutHelpers
config.include Spree::MoneyHelper
config.include Spree::TestingSupport::ControllerRequests, :type => :controller
config.include Spree::TestingSupport::Preferences
config.include Devise::TestHelpers, :type => :controller
config.extend Spree::Api::TestingSupport::Setup, :type => :controller
config.include Spree::Api::TestingSupport::Helpers, :type => :controller