Browse Source

CLDC-2060 Add new organisation address question (#1602)

* Add new organisation address fields to merge requests

* Add new organisation address page

* Add new organisation telephone number placeholder page

* close the div
pull/1608/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
b6ff1b9d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/controllers/merge_requests_controller.rb
  2. 30
      app/views/merge_requests/new_organisation_address.html.erb
  3. 5
      app/views/merge_requests/new_organisation_telephone_number.html.erb
  4. 1
      config/routes.rb
  5. 9
      db/migrate/20230504111352_add_new_organisation_address.rb
  6. 5
      db/schema.rb
  7. 80
      spec/requests/merge_requests_controller_spec.rb

7
app/controllers/merge_requests_controller.rb

@ -8,6 +8,7 @@ class MergeRequestsController < ApplicationController
confirm_telephone_number confirm_telephone_number
new_organisation_name new_organisation_name
new_organisation_address new_organisation_address
new_organisation_telephone_number
merge_date merge_date
] ]
before_action :authenticate_user! before_action :authenticate_user!
@ -17,6 +18,7 @@ class MergeRequestsController < ApplicationController
def confirm_telephone_number; end def confirm_telephone_number; end
def new_organisation_name; end def new_organisation_name; end
def new_organisation_address; end def new_organisation_address; end
def new_organisation_telephone_number; end
def merge_date; end def merge_date; end
def create def create
@ -79,6 +81,8 @@ private
merge_date_merge_request_path(@merge_request) merge_date_merge_request_path(@merge_request)
when "new_organisation_name" when "new_organisation_name"
new_organisation_address_merge_request_path(@merge_request) new_organisation_address_merge_request_path(@merge_request)
when "new_organisation_address"
new_organisation_telephone_number_merge_request_path(@merge_request)
end end
end end
@ -108,6 +112,9 @@ private
:telephone_number_correct, :telephone_number_correct,
:new_telephone_number, :new_telephone_number,
:new_organisation_name, :new_organisation_name,
:new_organisation_address_line1,
:new_organisation_address_line2,
:new_organisation_postcode,
) )
if merge_params[:requesting_organisation_id].present? && (current_user.data_coordinator? || current_user.data_provider?) if merge_params[:requesting_organisation_id].present? && (current_user.data_coordinator? || current_user.data_provider?)

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

@ -1,5 +1,33 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<% title = "New organisation address" %> <% title = "New organisation address" %>
<% content_for :title, title %> <% content_for :title, title %>
<%= govuk_back_link href: new_organisation_name_merge_request_path(id: @merge_request) %> <%= govuk_back_link href: new_organisation_name_merge_request_path(@merge_request) %>
<% end %>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<h2 class="govuk-heading-l">What is <%= @merge_request.new_organisation_name.possessive %> address?</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= f.govuk_text_field :new_organisation_address_line1,
label: { text: "Address line 1", size: "m" },
autocomplete: "address-line1" %>
<%= f.govuk_text_field :new_organisation_address_line2,
label: { text: "Address line 2", size: "m" },
autocomplete: "address-line2" %>
<%= f.govuk_text_field :new_organisation_postcode,
label: { text: "Postcode", size: "m" },
autocomplete: "postal-code",
width: 10 %>
<%= f.hidden_field :page, value: "new_organisation_address" %>
<div class="govuk-button-group">
<%= f.govuk_submit %>
<%= govuk_link_to("Skip for now", new_organisation_telephone_number_merge_request_path(@merge_request)) %>
</div>
</div>
</div>
<% end %> <% end %>

5
app/views/merge_requests/new_organisation_telephone_number.html.erb

@ -0,0 +1,5 @@
<% content_for :before_content do %>
<% title = "New organisation telephone number" %>
<% content_for :title, title %>
<%= govuk_back_link href: new_organisation_address_merge_request_path(@merge_request) %>
<% end %>

1
config/routes.rb

@ -140,6 +140,7 @@ Rails.application.routes.draw do
get "confirm-telephone-number" get "confirm-telephone-number"
get "new-organisation-name" get "new-organisation-name"
get "new-organisation-address" get "new-organisation-address"
get "new-organisation-telephone-number"
get "merge-date" get "merge-date"
end end
end end

9
db/migrate/20230504111352_add_new_organisation_address.rb

@ -0,0 +1,9 @@
class AddNewOrganisationAddress < ActiveRecord::Migration[7.0]
def change
change_table :merge_requests, bulk: true do |t|
t.column :new_organisation_address_line1, :string
t.column :new_organisation_address_line2, :string
t.column :new_organisation_postcode, :string
end
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_05_02_135049) do ActiveRecord::Schema[7.0].define(version: 2023_05_04_111352) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -372,6 +372,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_02_135049) do
t.boolean "telephone_number_correct" t.boolean "telephone_number_correct"
t.string "new_telephone_number" t.string "new_telephone_number"
t.string "new_organisation_name" t.string "new_organisation_name"
t.string "new_organisation_address_line1"
t.string "new_organisation_address_line2"
t.string "new_organisation_postcode"
end end
create_table "organisation_relationships", force: :cascade do |t| create_table "organisation_relationships", force: :cascade do |t|

80
spec/requests/merge_requests_controller_spec.rb

@ -553,6 +553,86 @@ RSpec.describe MergeRequestsController, type: :request do
end end
end end
end end
describe "#new_organsation_address" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, new_organisation_name: "New name", new_absorbing_organisation: true) }
context "when viewing the new organisation name page" do
before do
get "/merge-request/#{merge_request.id}/new-organisation-address", headers:
end
it "displays the correct question" do
expect(page).to have_content("What is New name’s address?")
end
it "has the correct back button" do
expect(page).to have_link("Back", href: new_organisation_name_merge_request_path(merge_request))
end
it "has a skip link" do
expect(page).to have_link("Skip for now", href: new_organisation_telephone_number_merge_request_path(merge_request))
end
end
context "when updating the new organisation address" do
let(:params) do
{ merge_request: {
new_organisation_address_line1: "first address line",
new_organisation_address_line2: "second address line",
new_organisation_postcode: "new postcode",
page: "new_organisation_address",
} }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "redirects to new organisation telephone path" do
request
expect(response).to redirect_to(new_organisation_telephone_number_merge_request_path(merge_request))
end
it "updates new organisation address line 1 to correct addess line" do
expect { request }.to change {
merge_request.reload.new_organisation_address_line1
}.from(nil).to("first address line")
end
it "updates new organisation address line 2 to correct addess line" do
expect { request }.to change {
merge_request.reload.new_organisation_address_line2
}.from(nil).to("second address line")
end
it "updates new organisation postcode to correct addess line" do
expect { request }.to change {
merge_request.reload.new_organisation_postcode
}.from(nil).to("new postcode")
end
end
context "when address is not provided" do
let(:params) do
{ merge_request: {
new_organisation_address_line1: nil,
new_organisation_address_line2: nil,
new_organisation_postcode: nil,
page: "new_organisation_address",
} }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "does not throw an error" do
request
expect(response).to redirect_to(new_organisation_telephone_number_merge_request_path(merge_request))
end
end
end
end end
end end

Loading…
Cancel
Save