Update shipping category factory with default

This commit is contained in:
Dan Ingenthron
2019-09-25 12:38:06 -05:00
parent dbf34da87b
commit 560fa6b949
4 changed files with 11 additions and 7 deletions

View File

@@ -72,7 +72,7 @@ class ProductFactory
variant_unit: "weight",
variant_unit_scale: 1,
unit_value: 1,
shipping_category: Spree::ShippingCategory.find_or_create_by_name('Default')
shipping_category: DefaultShippingCategory.find_or_create
)
product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name])
product.variants.first.update_attribute :on_demand, true

View File

@@ -194,4 +194,9 @@ FactoryBot.modify do
# sets the default value for variant.on_demand
backorderable_default false
end
factory :shipping_category, class: Spree::ShippingCategory do
initialize_with { DefaultShippingCategory.find_or_create }
transient { name 'Default' }
end
end

View File

@@ -75,7 +75,7 @@ feature 'shipping methods' do
let(:sm1) { create(:shipping_method, name: 'One', distributors: [distributor1]) }
let(:sm2) { create(:shipping_method, name: 'Two', distributors: [distributor1, distributor2]) }
let(:sm3) { create(:shipping_method, name: 'Three', distributors: [distributor3]) }
let(:shipping_category) { DefaultShippingCategory.find_or_create }
let(:shipping_category) { create(:shipping_category) }
before(:each) do
enterprise_user.enterprise_roles.build(enterprise: distributor1).save
@@ -89,7 +89,6 @@ feature 'shipping methods' do
within(".side_menu") do
click_link "Shipping Methods"
end
DefaultShippingCategory.find_or_create
click_link 'Create One Now'
# Show the correct fields

View File

@@ -4,18 +4,18 @@ describe DefaultShippingCategory do
describe '.create!' do
it "names the location 'Default'" do
shipping_category = described_class.create!
expect(shipping_category.name).to eq('Default')
expect(shipping_category.name).to eq 'Default'
end
end
describe 'find_or_create' do
context 'when a Default category already exists' do
let!(:category) do
let! :category do
Spree::ShippingCategory.create!(name: 'Default')
end
it 'returns the category' do
expect(described_class.find_or_create).to eq(category)
expect(described_class.find_or_create).to eq category
end
it 'does not create another category' do
@@ -26,7 +26,7 @@ describe DefaultShippingCategory do
context 'when a Default category does not exist' do
it 'returns the category' do
category = described_class.find_or_create
expect(category.name).to eq('Default')
expect(category.name).to eq 'Default'
end
it 'does not create another category' do