diff --git a/rails_application/app/controllers/client/orders_controller.rb b/rails_application/app/controllers/client/orders_controller.rb index a7faff75..a093c12d 100644 --- a/rails_application/app/controllers/client/orders_controller.rb +++ b/rails_application/app/controllers/client/orders_controller.rb @@ -32,7 +32,7 @@ def edit def add_item read_model = ClientOrders::OrderLine.where(order_uid: params[:id], product_id: params[:product_id]).first - unless Availability.approximately_available?(params[:product_id], (read_model&.quantity || 0) + 1) + unless Availability.approximately_available?(params[:product_id], (read_model&.product_quantity || 0) + 1) redirect_to edit_client_order_path(params[:id]), alert: "Product not available in requested quantity!" and return end diff --git a/rails_application/test/integration/client_orders_test.rb b/rails_application/test/integration/client_orders_test.rb index cd50e2dd..a5ab23a9 100644 --- a/rails_application/test/integration/client_orders_test.rb +++ b/rails_application/test/integration/client_orders_test.rb @@ -98,6 +98,19 @@ def test_paid_orders_summary assert_orders_summary("$11.00") end + def test_adding_the_same_product_twice_bug + customer_id = register_customer("Customer Shop") + product_id = register_product("Fearless Refactoring", 4, 10) + Sidekiq::Job.drain_all + + login(customer_id) + visit_client_orders + + order_id = SecureRandom.uuid + as_client_add_item_to_basket_for_order(product_id, order_id) + as_client_add_item_to_basket_for_order(product_id, order_id) + end + private def submit_order_for_customer(customer_id, order_id)