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 Jul 23, 2024
1 parent 9b62d13 commit 75e095e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
21 changes: 2 additions & 19 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 @@ -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 Expand Up @@ -872,7 +855,7 @@ Style/ReturnNilInPredicateMethodDefinition:
- 'app/serializers/api/admin/customer_serializer.rb'
- 'engines/order_management/app/services/order_management/subscriptions/validator.rb'

# Offense count: 207
# Offense count: 204
Style/Send:
Exclude:
- 'spec/controllers/admin/subscriptions_controller_spec.rb'
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
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 75e095e

Please sign in to comment.