Browse Source

Update absorbing organisation question and routing

pull/2564/head
Kat 2 years ago
parent
commit
c16a6ec07e
  1. 35
      app/controllers/merge_requests_controller.rb
  2. 30
      app/views/merge_requests/absorbing_organisation.html.erb
  3. 2
      app/views/organisations/index.html.erb
  4. 15
      spec/requests/merge_requests_controller_spec.rb
  5. 2
      spec/requests/organisations_controller_spec.rb

35
app/controllers/merge_requests_controller.rb

@ -1,21 +1,11 @@
class MergeRequestsController < ApplicationController
before_action :find_resource, only: %i[
update
organisations
update_organisations
remove_merging_organisation
absorbing_organisation
confirm_telephone_number
new_organisation_name
new_organisation_address
new_organisation_telephone_number
new_organisation_type
merge_date
]
before_action :find_resource, exclude: %i[create new]
before_action :authenticate_user!
before_action :authenticate_scope!
before_action :set_organisations_answer_options, only: %i[organisations absorbing_organisation update_organisations remove_merging_organisation update]
def absorbing_organisation; end
def organisations; end
def confirm_telephone_number; end
def new_organisation_name; end
def new_organisation_address; end
@ -32,10 +22,6 @@ class MergeRequestsController < ApplicationController
render_not_found
end
def organisations
@answer_options = organisations_answer_options
end
def update
validate_response
@ -48,7 +34,6 @@ class MergeRequestsController < ApplicationController
def update_organisations
merge_request_organisation = MergeRequestOrganisation.new(merge_request_organisation_params)
@answer_options = organisations_answer_options
if merge_request_organisation.save
render :organisations
else
@ -58,7 +43,6 @@ class MergeRequestsController < ApplicationController
def remove_merging_organisation
MergeRequestOrganisation.find_by(merge_request_organisation_params)&.destroy!
@answer_options = organisations_answer_options
render :organisations
end
@ -97,13 +81,16 @@ private
params.dig(:merge_request, :absorbing_organisation_id) == "other"
end
def organisations_answer_options
def set_organisations_answer_options
answer_options = { "" => "Select an option" }
Organisation.all.pluck(:id, :name).each do |organisation|
answer_options[organisation[0]] = organisation[1]
if current_user.support?
Organisation.all.pluck(:id, :name).each do |organisation|
answer_options[organisation[0]] = organisation[1]
end
end
answer_options
@answer_options = answer_options
end
def merge_request_params
@ -165,6 +152,8 @@ private
end
def find_resource
return if params[:id].blank?
@merge_request = MergeRequest.find(params[:id])
end

30
app/views/merge_requests/absorbing_organisation.html.erb

@ -1,32 +1,28 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link href: organisations_merge_request_path(id: @merge_request) %>
<%= govuk_back_link href: organisations_path(anchor: "merge-requests") %>
<% end %>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<h2 class="govuk-heading-l">Which organisation is absorbing the others?</h2>
<h1 class="govuk-heading-l">Which organisation is absorbing the others?</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Select the organisation that the other organisations are merging into.</p>
<p class="govuk-hint">If organisations are merging into a new organisation, <%= govuk_link_to "create the new organisation", new_organisation_path %> first and then select it here.</p>
<%= f.govuk_radio_buttons_fieldset(
:absorbing_organisation_id,
hint: { text: "For example, if Skype and Yammer merged into Microsoft, you would select Microsoft." },
legend: nil,
) do %>
<% @merge_request.merging_organisations.order(:name).each do |org| %>
<%= f.govuk_radio_button(
:absorbing_organisation_id,
org.id,
label: { text: org.name },
) %>
<%= f.govuk_select(:absorbing_organisation_id,
label: { text: "Select organisation name", class: "govuk-label--m" },
"data-controller": "accessible-autocomplete") do %>
<% @answer_options.map { |id, name| OpenStruct.new(id:, name:) }.each do |answer| %>
<option value="<%= answer.id %>"
data-synonyms="<%= answer_option_synonyms(answer.resource) %>"
data-append="<%= answer_option_append(answer.resource) %>"
data-hint="<%= answer_option_hint(answer.resource) %>"
<%= @merge_request.absorbing_organisation_id == answer.id ? "selected" : "" %>><%= answer.name || answer.resource %></option>
<% end %>
<% end %>
<%= f.govuk_radio_divider %>
<%= f.govuk_radio_button :absorbing_organisation_id, "other", checked: @merge_request.new_absorbing_organisation?, label: { text: "These organisations are merging into a new one" } %>
<% end %>
<%= f.hidden_field :page, value: "absorbing_organisation" %>

2
app/views/organisations/index.html.erb

@ -15,7 +15,7 @@
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %>
<% end %>
<% c.with_tab(label: "Merge requests") do %>
<%= govuk_button_link_to "Create new merge request", "/organisations/#{current_user.organisation_id}/merge-request", html: { method: :get } %>
<%= govuk_button_to "Create new merge request", merge_requests_path, html: { method: :post } %>
<%= render partial: "merge_request_list", locals: { merge_requests: @merge_requests, title: "Merge requests", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<% end %>
<% end %>

15
spec/requests/merge_requests_controller_spec.rb

@ -256,6 +256,21 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
describe "#absorbing_organisation" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation) }
before { get "/merge-request/#{merge_request.id}/absorbing-organisation", headers: }
it "asks for the absorbing organisation" do
expect(page).to have_content("Which organisation is absorbing the others?")
expect(page).to have_content("Select organisation name")
end
it "has the correct back button" do
expect(page).to have_link("Back", href: organisations_path(anchor: "merge-requests"))
end
end
describe "#update" do
describe "from absorbing_organisation page" do
context "when not answering the question" do

2
spec/requests/organisations_controller_spec.rb

@ -1022,7 +1022,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "has a create new merge request button" do
expect(page).to have_link("Create new merge request")
expect(page).to have_button("Create new merge request")
end
it "displays 'No merge requests' when @merge_requests is empty" do

Loading…
Cancel
Save