Add product spec when supplier is empty and remove error status code from product create action [OFN-12591]

This commit is contained in:
wandji20
2024-07-23 13:02:33 +01:00
parent 287f65ec8e
commit ebc794194f
5 changed files with 26 additions and 27 deletions

View File

@@ -12,22 +12,6 @@ Layout/EmptyLines:
Exclude:
- 'app/services/products_renderer.rb'
# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Exclude:
- 'app/services/products_renderer.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'app/services/products_renderer.rb'
# Offense count: 16
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
@@ -101,7 +85,7 @@ Lint/UselessMethodDefinition:
Exclude:
- 'app/models/spree/gateway.rb'
# Offense count: 23
# Offense count: 24
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
@@ -114,6 +98,7 @@ Metrics/AbcSize:
- 'app/helpers/spree/admin/navigation_helper.rb'
- 'app/models/enterprise_group.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/product_import/entry_processor.rb'
- 'app/models/spree/ability.rb'
- 'app/models/spree/address.rb'
- 'app/models/spree/order/checkout.rb'
@@ -142,7 +127,7 @@ Metrics/BlockNesting:
Exclude:
- 'app/models/spree/payment/processing.rb'
# Offense count: 47
# Offense count: 46
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
@@ -178,7 +163,6 @@ Metrics/ClassLength:
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
- 'app/reflexes/admin/orders_reflex.rb'
- 'app/reflexes/products_reflex.rb'
- 'app/serializers/api/cached_enterprise_serializer.rb'
- 'app/serializers/api/enterprise_shopfront_serializer.rb'
- 'app/services/cart_service.rb'
@@ -408,7 +392,6 @@ RSpecRails/HaveHttpStatus:
- 'spec/controllers/stripe/webhooks_controller_spec.rb'
- 'spec/controllers/user_passwords_controller_spec.rb'
- 'spec/controllers/user_registrations_controller_spec.rb'
- 'spec/requests/admin/images_spec.rb'
- 'spec/requests/api/routes_spec.rb'
- 'spec/requests/checkout/stripe_sca_spec.rb'
- 'spec/requests/home_controller_spec.rb'
@@ -725,7 +708,7 @@ Style/ClassAndModuleChildren:
- 'lib/open_food_network/locking.rb'
- 'spec/models/spree/payment_method_spec.rb'
# Offense count: 2
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never

View File

@@ -46,7 +46,7 @@ module Spree
# Re-fill the form with deleted params on product
@on_hand = request.params[:product][:on_hand]
@on_demand = request.params[:product][:on_demand]
render :new, status: :unprocessable_entity
render :new
end
end
end

View File

@@ -149,7 +149,6 @@ module ProductImport
end
end
# rubocop:disable Metrics/AbcSize
def save_new_product(entry)
@already_created ||= {}
# If we've already added a new product with these attributes
@@ -178,7 +177,6 @@ module ProductImport
@already_created.deep_merge! entry.enterprise_id => { entry.name => product.id }
end
# rubocop:enable Metrics/AbcSize
def save_variant(entry)
variant = entry.product_object

View File

@@ -168,17 +168,18 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
spree_put :create, product: product_attrs_with_image
expect(response.status).to eq 422
expect(response.status).to eq 200
end
end
describe "when variant attributes are missing" do
it 'renders 422 error' do
it 'renders form with errors' do
spree_post :create, product: product_attrs.merge!(
{ supplier_id: nil, primary_taxon_id: nil }
),
button: 'create'
expect(response.status).to eq 422
expect(response.status).to eq 200
expect(response).to render_template('spree/admin/products/new')
end
end
end

View File

@@ -187,6 +187,23 @@ RSpec.describe '
expect(page).to have_content "Product Category must exist"
end
it "creating product with empty product supplier fails" do
fill_in 'product_name', with: 'Hot Cakes'
select "Weight (kg)", from: 'product_variant_unit_with_scale'
fill_in "product_unit_value", with: '1'
fill_in 'product_price', with: '1.99'
select taxon.name, from: "product_primary_taxon_id"
fill_in 'product_on_hand', with: 0
check 'product_on_demand'
select 'Test Tax Category', from: 'product_tax_category_id'
fill_in_trix_editor 'product_description',
with: 'In demand, and on_demand! The hottest cakes in town.'
click_button 'Create'
expect(current_path).to eq spree.admin_products_path
expect(page).to have_content "Supplier must exist"
end
describe "localization settings" do
shared_examples "with different price values" do |localized_number, price|
context "when enable_localized_number is set to #{localized_number}" do