mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Ensure that changes to Spree::Config.products_require_tax_category do not leak out of the relevant spec
This commit is contained in:
@@ -117,31 +117,34 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
scenario "creating a new product", js: true do
|
||||
Spree::Config.products_require_tax_category = false
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
context "products do not require a tax category" do
|
||||
around { |example| with_products_require_tax_category(false) { example.run } }
|
||||
|
||||
fill_in 'product_name', :with => 'A new product !!!'
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
scenario "creating a new product", js: true do
|
||||
click_link 'Products'
|
||||
click_link 'New Product'
|
||||
|
||||
page.should have_selector('#product_supplier_id')
|
||||
select 'Another Supplier', :from => 'product_supplier_id'
|
||||
select 'Weight (g)', from: 'product_variant_unit_with_scale'
|
||||
fill_in 'product_unit_value_with_description', with: '500'
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
select 'None', from: "product_tax_category_id"
|
||||
fill_in 'product_name', :with => 'A new product !!!'
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
|
||||
# Should only have suppliers listed which the user can manage
|
||||
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
|
||||
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
|
||||
page.should have_selector('#product_supplier_id')
|
||||
select 'Another Supplier', :from => 'product_supplier_id'
|
||||
select 'Weight (g)', from: 'product_variant_unit_with_scale'
|
||||
fill_in 'product_unit_value_with_description', with: '500'
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
select 'None', from: "product_tax_category_id"
|
||||
|
||||
click_button 'Create'
|
||||
# Should only have suppliers listed which the user can manage
|
||||
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
|
||||
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier2
|
||||
product.tax_category.should be_nil
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier2
|
||||
product.tax_category.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
scenario "editing a product" do
|
||||
|
||||
@@ -40,7 +40,7 @@ module Spree
|
||||
|
||||
describe "tax category" do
|
||||
context "when a tax category is required" do
|
||||
before { Spree::Config.products_require_tax_category = true }
|
||||
around { |example| with_products_require_tax_category(true) { example.run } }
|
||||
|
||||
it "is invalid when a tax category is not provided" do
|
||||
build(:product, tax_category_id: nil).should_not be_valid
|
||||
@@ -48,7 +48,7 @@ module Spree
|
||||
end
|
||||
|
||||
context "when a tax category is not required" do
|
||||
before { Spree::Config.products_require_tax_category = false }
|
||||
around { |example| with_products_require_tax_category(false) { example.run } }
|
||||
|
||||
it "is valid when a tax category is not provided" do
|
||||
build(:product, tax_category_id: nil).should be_valid
|
||||
|
||||
@@ -91,6 +91,7 @@ RSpec.configure do |config|
|
||||
config.include OpenFoodNetwork::ControllerHelper, :type => :controller
|
||||
config.include OpenFoodNetwork::FeatureToggleHelper
|
||||
config.include OpenFoodNetwork::EnterpriseGroupsHelper
|
||||
config.include OpenFoodNetwork::ProductsHelper
|
||||
config.include OpenFoodNetwork::DistributionHelper
|
||||
config.include OpenFoodNetwork::HtmlHelper
|
||||
config.include ActionView::Helpers::DateHelper
|
||||
|
||||
12
spec/support/products_helper.rb
Normal file
12
spec/support/products_helper.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module OpenFoodNetwork
|
||||
module ProductsHelper
|
||||
def with_products_require_tax_category(value)
|
||||
original_value = Spree::Config.products_require_tax_category
|
||||
|
||||
Spree::Config.products_require_tax_category = value
|
||||
yield
|
||||
ensure
|
||||
Spree::Config.products_require_tax_category = original_value
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user