Skip to content

Commit

Permalink
Add product spec when supplier is empty and remove error status code …
Browse files Browse the repository at this point in the history
…from product create action [OFN-12591]
  • Loading branch information
wandji20 committed Aug 1, 2024
1 parent 287f65e commit ebc7941
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
25 changes: 4 additions & 21 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create
# 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
Expand Down
2 changes: 0 additions & 2 deletions app/models/product_import/entry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def save_existing_inventory_item(entry)
end
end

# rubocop:disable Metrics/AbcSize
def save_new_product(entry)
@already_created ||= {}
# If we've already added a new product with these attributes
Expand Down Expand Up @@ -178,7 +177,6 @@ def save_new_product(entry)

@already_created.deep_merge! entry.enterprise_id => { entry.name => product.id }
end
# rubocop:enable Metrics/AbcSize

def save_variant(entry)
variant = entry.product_object
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/spree/admin/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,18 @@

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
Expand Down
17 changes: 17 additions & 0 deletions spec/system/admin/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@
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
Expand Down

0 comments on commit ebc7941

Please sign in to comment.