Skip to content

Commit

Permalink
12626: add explaination for clone failure
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz committed Sep 11, 2024
1 parent 6849155 commit 1092bbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions app/controllers/admin/products_v3_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def clone
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
rescue ActiveRecord::ActiveRecordError => _e
flash.now[:error] = t('.error')
rescue ActiveRecord::ActiveRecordError => e
flash.now[:error] = clone_error_message(e)
status = :unprocessable_entity
@product_index = "-1" # Create a unique enough index
end
Expand Down Expand Up @@ -209,6 +209,15 @@ def products_bulk_params
params.permit(products: ::PermittedAttributes::Product.attributes)
.to_h.with_indifferent_access
end

def clone_error_message(error)
case error
when ActiveRecord::RecordInvalid
error.record.errors.map(&:full_message).join("; ")
else
t('.error')
end
end
end
end
# rubocop:enable Metrics/ClassLength
2 changes: 1 addition & 1 deletion spec/system/admin/products_v3/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def expect_other_columns_visible

click_product_clone "Apples"

expect(page).to have_content "Unable to clone the product"
expect(page).to have_content "Variant Unit can't be blank"

within "table.products" do
# Products does not include the cloned product.
Expand Down

0 comments on commit 1092bbe

Please sign in to comment.