Browse Source

Handle unanswered question

pull/1580/head
Jack S 3 years ago
parent
commit
0d4a58007c
  1. 8
      app/controllers/merge_requests_controller.rb
  2. 20
      spec/requests/merge_requests_controller_spec.rb

8
app/controllers/merge_requests_controller.rb

@ -10,6 +10,7 @@ class MergeRequestsController < ApplicationController
]
before_action :authenticate_user!
before_action :authenticate_scope!, except: [:create]
before_action :validate_response, only: %i[update]
def absorbing_organisation; end
def confirm_telephone_number; end
@ -113,6 +114,13 @@ private
merge_params
end
def validate_response
if page == "absorbing_organisation" && merge_request_params[:absorbing_organisation_id].blank? && merge_request_params[:new_absorbing_organisation].blank?
@merge_request.errors.add(:absorbing_organisation_id, "Select an option")
render previous_template
end
end
def merge_request_organisation_params
{
merge_request: @merge_request,

20
spec/requests/merge_requests_controller_spec.rb

@ -260,6 +260,26 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
context "when not answering the question" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: other_organisation) }
let(:params) do
{ merge_request: { page: "absorbing_organisation" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "renders the error" do
request
expect(page).to have_content("Select an option")
end
it "does not update the request" do
expect { request }.not_to(change { merge_request.reload.attributes })
end
end
context "when absorbing_organisation_id set to other" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: other_organisation) }
let(:params) do

Loading…
Cancel
Save