diff --git a/app/controllers/batches_controller.rb b/app/controllers/batches_controller.rb index 3af889990..2c9e23e53 100644 --- a/app/controllers/batches_controller.rb +++ b/app/controllers/batches_controller.rb @@ -11,7 +11,13 @@ def new end def create - @batch = Batch.new(batch_params.merge(team: current_user.team, vaccine:)) + begin + @batch = Batch.new(batch_params.merge(team: current_user.team, vaccine:)) + rescue ActiveRecord::MultiparameterAssignmentErrors + @batch = + Batch.new(name: batch_params[:name], team: current_user.team, vaccine:) + @batch.expiry = expiry_validator.date_params_as_struct + end if !expiry_validator.date_params_valid? @batch.expiry = expiry_validator.date_params_as_struct diff --git a/spec/features/manage_batches_spec.rb b/spec/features/manage_batches_spec.rb index 304bc5300..a8f6e76b5 100644 --- a/spec/features/manage_batches_spec.rb +++ b/spec/features/manage_batches_spec.rb @@ -10,7 +10,10 @@ when_i_manage_vaccines then_i_see_only_active_hpv_vaccines_with_no_batches_set_up - when_i_add_a_new_batch + when_i_try_to_add_a_batch_with_an_invalid_expiry_date + then_i_see_the_error_message + + when_i_add_a_valid_new_batch then_i_see_the_batch_i_just_added_on_the_vaccines_page when_i_edit_the_expiry_date_of_the_batch @@ -53,11 +56,25 @@ def then_i_see_only_active_hpv_vaccines_with_no_batches_set_up expect(page).not_to have_css("table") end - def when_i_add_a_new_batch + def when_i_try_to_add_a_batch_with_an_invalid_expiry_date click_on "Add a batch", match: :first fill_in "Batch", with: "AB1234" + # expiry date + fill_in "Day", with: "0" + fill_in "Month", with: "0" + fill_in "Year", with: "0" + + click_on "Add batch" + end + + def then_i_see_the_error_message + expect(page).to have_content("There is a problem") + expect(page).to have_content("Enter a year") + end + + def when_i_add_a_valid_new_batch # expiry date fill_in "Day", with: "30" fill_in "Month", with: "3"