diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index 09cc60d3d3..01e92dddb7 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 450984f89c..4f9c6478f5 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/features/admin/shipping_methods_spec.rb b/spec/features/admin/shipping_methods_spec.rb index 3b1c9386ea..ca00af3457 100644 --- a/spec/features/admin/shipping_methods_spec.rb +++ b/spec/features/admin/shipping_methods_spec.rb @@ -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 diff --git a/spec/services/default_shipping_category_spec.rb b/spec/services/default_shipping_category_spec.rb index 24a718a262..0afef46cbe 100644 --- a/spec/services/default_shipping_category_spec.rb +++ b/spec/services/default_shipping_category_spec.rb @@ -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