Browse Source

CLDC-2056 Add absorbing organisation question

pull/1580/head
Jack S 3 years ago
parent
commit
e56ef83172
  1. 37
      app/controllers/merge_requests_controller.rb
  2. 1
      app/models/merge_request.rb
  3. 36
      app/views/merge_requests/absorbing_organisation.html.erb
  4. 13
      app/views/merge_requests/confirm_telephone_number.html.erb
  5. 7
      app/views/merge_requests/new_org_name.html.erb
  6. 61
      app/views/merge_requests/organisations.html.erb
  7. 2
      config/routes.rb
  8. 5
      db/migrate/20230421124536_add_absorbing_organisation_to_merge_request.rb
  9. 7
      db/schema.rb
  10. 81
      spec/requests/merge_requests_controller_spec.rb

37
app/controllers/merge_requests_controller.rb

@ -1,5 +1,5 @@
class MergeRequestsController < ApplicationController
before_action :find_resource, only: %i[update organisations update_organisations remove_merging_organisation]
before_action :find_resource, only: %i[update organisations update_organisations remove_merging_organisation absorbing_organisation confirm_telephone_number new_org_name]
before_action :authenticate_user!
before_action :authenticate_scope!, except: [:create]
@ -13,12 +13,18 @@ class MergeRequestsController < ApplicationController
render_not_found
end
def absorbing_organisation; end
def confirm_telephone_number; end
def new_org_name; end
def organisations
@answer_options = organisations_answer_options
end
def update
if @merge_request.update(merge_request_params)
if params.dig(:merge_request, :absorbing_organisation_id) == "other"
redirect_to next_page_path
elsif @merge_request.update(merge_request_params)
redirect_to next_page_path
else
render previous_template, status: :unprocessable_entity
@ -53,7 +59,12 @@ private
end
def merge_request_params
merge_params = params.fetch(:merge_request, {}).permit(:requesting_organisation_id, :other_merging_organisations, :status)
merge_params = params.fetch(:merge_request, {}).permit(
:requesting_organisation_id,
:other_merging_organisations,
:status,
:absorbing_organisation_id,
)
if merge_params[:requesting_organisation_id].present? && (current_user.data_coordinator? || current_user.data_provider?)
merge_params[:requesting_organisation_id] = current_user.organisation.id
@ -63,7 +74,10 @@ private
end
def merge_request_organisation_params
{ merge_request: @merge_request, merging_organisation_id: params[:merge_request][:merging_organisation] }
{
merge_request: @merge_request,
merging_organisation_id: params.dig(:merge_request, :merging_organisation),
}
end
def find_resource
@ -71,11 +85,22 @@ private
end
def next_page_path
absorbing_organisation_merge_request_path(@merge_request)
if params.dig(:merge_request, :absorbing_organisation_id) == "other"
# TODO: flow to be implemented in follow up PR
new_org_name_merge_request_path(@merge_request)
elsif params.dig(:merge_request, :absorbing_organisation_id).present?
confirm_telephone_number_merge_request_path(@merge_request)
else
absorbing_organisation_merge_request_path(@merge_request)
end
end
def previous_template
:organisations
if params.dig(:merge_request, :absorbing_organisation_id).present?
:absorbing_organisation
else
:organisations
end
end
def authenticate_scope!

1
app/models/merge_request.rb

@ -1,6 +1,7 @@
class MergeRequest < ApplicationRecord
belongs_to :requesting_organisation, class_name: "Organisation"
has_many :merge_request_organisations
belongs_to :absorbing_organisation, class_name: "Organisation", optional: true
has_many :merging_organisations, through: :merge_request_organisations, source: :merging_organisation
STATUS = {

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

@ -0,0 +1,36 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link(href: :back) %>
<% end %>
<h2 class="govuk-heading-l">Which organisation is absorbing the others?</h2>
<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>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= 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 },
link_errors: true,
) %>
<% end %>
<%= f.govuk_radio_divider %>
<%= f.govuk_radio_button :absorbing_organisation_id, "other", label: { text: "These organisations are merging into a new one" } %>
<% end %>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

13
app/views/merge_requests/confirm_telephone_number.html.erb

@ -0,0 +1,13 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link(href: :back) %>
<% end %>
<h2 class="govuk-heading-l">What is <%= @merge_request.absorbing_organisation.name %>'s telephone number?</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Confirm the telephone number on file, or enter a new one.</p>
</div>
</div>

7
app/views/merge_requests/new_org_name.html.erb

@ -0,0 +1,7 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link(href: :back) %>
<% end %>
Provide new org name

61
app/views/merge_requests/organisations.html.erb

@ -1,5 +1,4 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link href: merge_request_organisation_path(id: @merge_request.requesting_organisation_id) %>
@ -9,41 +8,43 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Add all organisations to be merged - we have already added your own.</p>
<p class="govuk-body">
Add all organisations to be merged - we have already added your own.
</p>
<%= form_with model: @merge_request, url: organisations_merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<p class="govuk-body">Start typing to search</p>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
field: :merging_organisation,
question: Form::Question.new("", { "answer_options" => @answer_options }, nil),
f:,
} %>
<%= f.govuk_submit "Add organisation", classes: "govuk-button--secondary" %>
<%= govuk_table do |table| %>
<% @merge_request.merging_organisations.each do |merging_organisation| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: merging_organisation.name) %>
<% row.cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<% if @merge_request.requesting_organisation != merging_organisation %>
<%= govuk_link_to("Remove", organisations_remove_merge_request_path(merge_request: { merging_organisation: merging_organisation.id })) %>
<%= form_with model: @merge_request, url: organisations_merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<p class="govuk-body">Start typing to search</p>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
field: :merging_organisation,
question: Form::Question.new("", { "answer_options" => @answer_options }, nil),
f:,
} %>
<%= f.govuk_submit "Add organisation", classes: "govuk-button--secondary" %>
<%= govuk_table do |table| %>
<% @merge_request.merging_organisations.order(:name).each do |merging_organisation| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: merging_organisation.name) %>
<% row.cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<% if @merge_request.requesting_organisation != merging_organisation %>
<%= govuk_link_to("Remove", organisations_remove_merge_request_path(merge_request: { merging_organisation: merging_organisation.id })) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= form_with model: @merge_request, url: merge_request_path(id: @merge_request.id), method: :patch do |f| %>
<%= govuk_details(summary_text: "I cannot find an organisation on the list") do %>
<%= f.govuk_text_area :other_merging_organisations, label: { text: "Other organisations" }, hint: { text: "List other organisations that are part of the merge but not registered on CORE." }, rows: 9 %>
<% end %>
<% if @merge_request.merging_organisations.count > 1 %>
<%= f.govuk_submit "Continue" %>
<%= form_with model: @merge_request, url: merge_request_path(id: @merge_request.id), method: :patch do |f| %>
<%= govuk_details(summary_text: "I cannot find an organisation on the list") do %>
<%= f.govuk_text_area :other_merging_organisations, label: { text: "Other organisations" }, hint: { text: "List other organisations that are part of the merge but not registered on CORE." }, rows: 9 %>
<% end %>
<% if @merge_request.merging_organisations.count > 1 %>
<%= f.govuk_submit "Continue" %>
<% end %>
<% end %>
<% end %>
</div>

2
config/routes.rb

@ -137,6 +137,8 @@ Rails.application.routes.draw do
patch "organisations", to: "merge_requests#update_organisations"
get "organisations/remove", to: "merge_requests#remove_merging_organisation"
get "absorbing-organisation"
get "confirm-telephone-number"
get "new-org-name"
end
end

5
db/migrate/20230421124536_add_absorbing_organisation_to_merge_request.rb

@ -0,0 +1,5 @@
class AddAbsorbingOrganisationToMergeRequest < ActiveRecord::Migration[7.0]
def change
add_column :merge_requests, :absorbing_organisation_id, :integer
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_04_19_153741) do
ActiveRecord::Schema[7.0].define(version: 2023_04_21_124536) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -367,6 +367,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_19_153741) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "status"
t.integer "absorbing_organisation_id"
end
create_table "organisation_relationships", force: :cascade do |t|
@ -575,8 +576,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_19_153741) do
t.integer "ethnicbuy2"
t.integer "proplen_asked"
t.string "old_id"
t.integer "buy2living"
t.integer "prevtenbuy2"
t.integer "pregblank"
t.string "uprn"
t.integer "uprn_known"
@ -585,6 +584,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_19_153741) do
t.string "address_line2"
t.string "town_or_city"
t.string "county"
t.integer "buy2living"
t.integer "prevtenbuy2"
t.integer "nationalbuy2"
t.integer "discounted_sale_value_check"
t.integer "student_not_child_value_check"

81
spec/requests/merge_requests_controller_spec.rb

@ -2,32 +2,29 @@ require "rails_helper"
RSpec.describe MergeRequestsController, type: :request do
let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") }
let(:other_organisation) { create(:organisation, name: "Other Test Org") }
let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let(:support_user) { FactoryBot.create(:user, :support, organisation:) }
let(:user) { create(:user, :data_coordinator) }
let(:support_user) { create(:user, :support, organisation:) }
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation) }
let(:other_merge_request) { MergeRequest.create!(requesting_organisation: other_organisation) }
context "when user is signed in with a data coordinator user" do
before do
sign_in user
end
before { sign_in user }
describe "#organisations" do
let(:params) { { merge_request: { requesting_organisation_id: "9", status: "unsubmitted" } } }
context "when creating a new merge request" do
before do
organisation.update!(name: "Test Org")
post "/merge-request", headers:, params:
end
it "creates merge request with requesting organisation" do
follow_redirect!
expect(page).to have_content("Which organisations are merging?")
expect(page).to have_content("Test Org")
expect(page).to have_content(organisation.name)
expect(page).not_to have_link("Remove")
end
@ -46,13 +43,12 @@ RSpec.describe MergeRequestsController, type: :request do
context "when viewing existing merge request" do
before do
organisation.update!(name: "Test Org")
get "/merge-request/#{merge_request.id}/organisations", headers:, params:
end
it "shows merge request with requesting organisation" do
expect(page).to have_content("Which organisations are merging?")
expect(page).to have_content("Test Org")
expect(page).to have_content(organisation.name)
end
end
@ -116,7 +112,7 @@ RSpec.describe MergeRequestsController, type: :request do
end
context "when the user selects an organisation that is a part of another merge" do
let(:another_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") }
let(:another_organisation) { create(:organisation, name: "Other Test Org") }
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } }
before do
@ -134,7 +130,7 @@ RSpec.describe MergeRequestsController, type: :request do
end
context "when the user selects an organisation that is a part of another unsubmitted merge" do
let(:another_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") }
let(:another_organisation) { create(:organisation, name: "Other Test Org") }
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } }
before do
@ -151,7 +147,7 @@ RSpec.describe MergeRequestsController, type: :request do
end
context "when the user selects an organisation that is a part of current merge" do
let(:another_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") }
let(:another_organisation) { create(:organisation, name: "Other Test Org") }
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } }
before do
@ -237,18 +233,64 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
describe "#other_merging_organisations" do
let(:params) { { merge_request: { other_merging_organisations: "A list of other merging organisations" } } }
describe "#update" do
before { sign_in user }
describe "#other_merging_organisations" do
let(:other_merging_organisations) { "A list of other merging organisations" }
let(:params) { { merge_request: { other_merging_organisations: } } }
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
context "when adding other merging organisations" do
before do
MergeRequestOrganisation.create!(merge_request_id: merge_request.id, merging_organisation_id: other_organisation.id)
end
it "updates the merge request" do
expect { request }.to change { merge_request.reload.other_merging_organisations }.from(nil).to(other_merging_organisations)
end
it "redirects telephone number path" do
request
expect(response).to redirect_to(absorbing_organisation_merge_request_path(merge_request))
end
end
end
context "when absorbing_organisation_id set to other" do
let(:params) do
{ merge_request: { absorbing_organisation_id: "other" } }
end
context "when adding other merging organisations" do
before do
MergeRequestOrganisation.create!(merge_request_id: merge_request.id, merging_organisation_id: other_organisation.id)
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "redirects to new org path" do
expect(response).to redirect_to(new_org_name_merge_request_path(merge_request))
end
end
context "when absorbing_organisation_id set to id" do
let(:params) do
{ merge_request: { absorbing_organisation_id: other_organisation.id } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "redirects telephone number path" do
request
expect(response).to redirect_to(confirm_telephone_number_merge_request_path(merge_request))
end
it "updates the merge request" do
merge_request.reload
expect(merge_request.other_merging_organisations).to eq("A list of other merging organisations")
expect { request }.to change { merge_request.reload.absorbing_organisation_id }.from(nil).to(other_organisation.id)
end
end
end
@ -264,7 +306,6 @@ RSpec.describe MergeRequestsController, type: :request do
let(:params) { { merge_request: { requesting_organisation_id: other_organisation.id, status: "unsubmitted" } } }
before do
organisation.update!(name: "Test Org")
post "/merge-request", headers:, params:
end

Loading…
Cancel
Save