Browse Source

Add has other client group field to schemes. Display it in the check answers. Fix tests and routing

pull/671/head
Kat 3 years ago committed by JG
parent
commit
5964d2f4bc
  1. 1
      Gemfile.lock
  2. 43
      app/controllers/schemes_controller.rb
  3. 20
      app/models/scheme.rb
  4. 10
      app/views/schemes/check_answers.html.erb
  5. 7
      app/views/schemes/confirm_secondary.html.erb
  6. 2
      app/views/schemes/index.html.erb
  7. 4
      config/routes.rb
  8. 7
      db/migrate/20220623132228_add_has_other_client_group_field.rb
  9. 6
      db/schema.rb
  10. 17
      spec/features/schemes_spec.rb
  11. 8
      spec/requests/organisations_controller_spec.rb
  12. 4
      spec/requests/schemes_controller_spec.rb

1
Gemfile.lock

@ -469,7 +469,6 @@ DEPENDENCIES
rubocop-govuk (= 4.3.0) rubocop-govuk (= 4.3.0)
rubocop-performance rubocop-performance
rubocop-rails rubocop-rails
securerandom
selenium-webdriver selenium-webdriver
sentry-rails sentry-rails
sentry-ruby sentry-ruby

43
app/controllers/schemes_controller.rb

@ -32,7 +32,7 @@ class SchemesController < ApplicationController
def create def create
@scheme = Scheme.new(clean_params) @scheme = Scheme.new(clean_params)
@scheme.save @scheme.save!
@path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) @path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)
render "schemes/primary_client_group" render "schemes/primary_client_group"
@ -41,26 +41,27 @@ class SchemesController < ApplicationController
def primary_client_group def primary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
if params[:check_answers] @path = if params[:check_answers]
@path = scheme_check_your_answers_path(scheme_id: @scheme.id) scheme_check_your_answers_path(scheme_id: @scheme.id)
else else
@path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)
end end
if params[:scheme] if params[:scheme]
required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :secondary_client_group, :primary_client_group) required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :secondary_client_group, :primary_client_group)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
@scheme.update(required_params) @scheme.update!(required_params)
end end
render "schemes/primary_client_group" render "schemes/primary_client_group"
end end
def confirm_secondary_group def confirm_secondary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
@path = params[:check_answers] ? scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true) : scheme_secondary_client_group_path(scheme_id: @scheme.id)
if params[:scheme] if params[:scheme]
required_params = params.require(:scheme).permit(:primary_client_group) if params required_params = params.require(:scheme).permit(:primary_client_group) if params
@scheme.update(required_params) if required_params @scheme.update!(required_params) if required_params
end end
render "schemes/confirm_secondary" render "schemes/confirm_secondary"
@ -69,8 +70,16 @@ class SchemesController < ApplicationController
def secondary_client_group def secondary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
@path = params[:check_answers] ? scheme_check_your_answers_path(scheme_id: @scheme.id) : scheme_support_path(scheme_id: @scheme.id) @path = params[:check_answers] ? scheme_check_your_answers_path(scheme_id: @scheme.id) : scheme_support_path(scheme_id: @scheme.id)
if params[:confirmed] if params[:scheme]
params[:confirmed][:selection] == "Yes" ? render("schemes/secondary_client_group") : render("schemes/support") required_params = params.require(:scheme).permit(:has_other_client_group) if params
@scheme.update!(required_params) if required_params
if @scheme.has_other_client_group == "Yes"
render("schemes/secondary_client_group")
elsif params[:check_answers]
redirect_to(scheme_check_your_answers_path(sheme_id: @scheme.id))
else
redirect_to(scheme_support_path(scheme_id: @scheme.id))
end
else else
render "schemes/secondary_client_group" render "schemes/secondary_client_group"
end end
@ -80,7 +89,7 @@ class SchemesController < ApplicationController
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
if params[:scheme] if params[:scheme]
required_params = params.require(:scheme).permit(:secondary_client_group) required_params = params.require(:scheme).permit(:secondary_client_group)
@scheme.update(required_params) if required_params @scheme.update!(required_params) if required_params
end end
render "schemes/support" render "schemes/support"
@ -88,10 +97,10 @@ class SchemesController < ApplicationController
def details def details
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
if params[:check_answers] @path = if params[:check_answers]
@path = scheme_check_your_answers_path(scheme_id: @scheme.id) scheme_check_your_answers_path(scheme_id: @scheme.id)
else else
@path = scheme_primary_client_group_path(scheme_id: @scheme.id) scheme_primary_client_group_path(scheme_id: @scheme.id)
end end
render "schemes/details" render "schemes/details"
@ -102,7 +111,7 @@ class SchemesController < ApplicationController
if params[:scheme] if params[:scheme]
required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :secondary_client_group, :primary_client_group) required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :secondary_client_group, :primary_client_group)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
@scheme.update(required_params) @scheme.update!(required_params)
end end
render "schemes/check_answers" render "schemes/check_answers"
@ -110,12 +119,14 @@ class SchemesController < ApplicationController
def update def update
@scheme = Scheme.find_by(id: params[:scheme_id]) @scheme = Scheme.find_by(id: params[:scheme_id])
flash[:notice] = ("#{@scheme.service_name} has been created.") flash[:notice] = "#{@scheme.service_name} has been created."
redirect_to schemes_path redirect_to schemes_path
end end
private def edit; end
private
def clean_params def clean_params
required_params = params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed) required_params = params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed)

20
app/models/scheme.rb

@ -10,7 +10,7 @@ class Scheme < ApplicationRecord
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(search_by_code(param)).distinct } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(search_by_code(param)).distinct }
SENSITIVE= { SENSITIVE = {
No: 0, No: 0,
Yes: 1, Yes: 1,
}.freeze }.freeze
@ -74,12 +74,18 @@ class Scheme < ApplicationRecord
INTENDED_STAY = { INTENDED_STAY = {
"Medium stay": "M", "Medium stay": "M",
"Permanent": "P", "Permanent": "P",
"Short Stay": "S", "Short stay": "S",
"Very short stay": "V", "Very short stay": "V",
"Missing": "X", "Missing": "X",
}.freeze }.freeze
HAS_OTHER_CLIENT_GROUP = {
"Yes": "yes",
"No": "no",
}.freeze
enum intended_stay: INTENDED_STAY, _suffix: true enum intended_stay: INTENDED_STAY, _suffix: true
enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true
def check_details_attributes def check_details_attributes
[ [
@ -99,6 +105,12 @@ class Scheme < ApplicationRecord
] ]
end end
def check_secondary_client_confirmation_attributes
[
{ name: "Scheme provides for another client group", value: has_other_client_group },
]
end
def check_secondary_client_attributes def check_secondary_client_attributes
[ [
{ name: "Secondary client group", value: secondary_client_group }, { name: "Secondary client group", value: secondary_client_group },
@ -128,9 +140,9 @@ class Scheme < ApplicationRecord
] ]
end end
private private
def create_code def create_code
self.code = Scheme.last.nil? ? "S1" : "S#{Scheme.last.code[1..-1].to_i + 1}" self.code = Scheme.last.nil? ? "S1" : "S#{Scheme.last.code[1..].to_i + 1}"
end end
end end

10
app/views/schemes/check_answers.html.erb

@ -33,6 +33,16 @@
) %> ) %>
<% end %> <% end %>
<% end %> <% end %>
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %>
<% row.action(
text: "Change",
href: scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true),
) %>
<% end %>
<% end %>
<% @scheme.check_secondary_client_attributes.each do |attr| %> <% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %> <% row.key { attr[:name].to_s } %>

7
app/views/schemes/confirm_secondary.html.erb

@ -9,17 +9,16 @@
<%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %>
<%= form_for(:confirmed, method: :patch, url: scheme_secondary_client_group_path(scheme_id: @scheme.id)) do |f| %> <%= form_for(@scheme, method: :patch, url: @path) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<% selection = ["Yes", "No"].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <% selection = [OpenStruct.new(id: "Yes", name: "Yes"), OpenStruct.new(id: "No", name: "No")] %>
<%= f.govuk_collection_radio_buttons :selection, <%= f.govuk_collection_radio_buttons :has_other_client_group,
selection, selection,
:id, :id,
:name, :name,
{ checked: "Yes" },
legend: nil legend: nil
%> %>

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

@ -9,7 +9,7 @@
<%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %>
<%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search by scheme name or code", value: @searched) %>
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m"> <hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m">

4
config/routes.rb

@ -38,8 +38,8 @@ Rails.application.routes.draw do
resources :schemes do resources :schemes do
patch "primary-client-group", to: "schemes#primary_client_group" patch "primary-client-group", to: "schemes#primary_client_group"
get "primary-client-group", to: "schemes#primary_client_group" get "primary-client-group", to: "schemes#primary_client_group"
patch "confirm-secondary-client-group", to: "schemes#confirm_secondary_group" patch "confirm-secondary-client-group", to: "schemes#confirm_secondary_client_group"
get "confirm-secondary-client-group", to: "schemes#confirm_secondary_group" get "confirm-secondary-client-group", to: "schemes#confirm_secondary_client_group"
patch "secondary-client-group", to: "schemes#secondary_client_group" patch "secondary-client-group", to: "schemes#secondary_client_group"
get "secondary-client-group", to: "schemes#secondary_client_group" get "secondary-client-group", to: "schemes#secondary_client_group"
patch "support", to: "schemes#support" patch "support", to: "schemes#support"

7
db/migrate/20220623132228_add_has_other_client_group_field.rb

@ -0,0 +1,7 @@
class AddHasOtherClientGroupField < ActiveRecord::Migration[7.0]
def change
change_table :schemes, bulk: true do |t|
t.column :has_other_client_group, :string
end
end
end

6
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: 2022_06_17_102313) do ActiveRecord::Schema[7.0].define(version: 2022_06_23_132228) 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"
@ -310,7 +310,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_17_102313) do
t.integer "registered_under_care_act" t.integer "registered_under_care_act"
t.integer "support_type" t.integer "support_type"
t.string "intended_stay" t.string "intended_stay"
<<<<<<< HEAD
t.datetime "end_date" t.datetime "end_date"
=======
t.string "has_other_client_group"
>>>>>>> f6b27a1a (Add has other client group field to schemes. Display it in the check answers. Fix tests and routing)
t.index ["organisation_id"], name: "index_schemes_on_organisation_id" t.index ["organisation_id"], name: "index_schemes_on_organisation_id"
end end

17
spec/features/schemes_spec.rb

@ -224,6 +224,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "displays the link to create a new scheme" do it "displays the link to create a new scheme" do
expect(page).to have_current_path("/schemes")
expect(page).to have_link("Create a new supported housing scheme") expect(page).to have_link("Create a new supported housing scheme")
end end
@ -235,6 +236,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "lets me fill in the scheme details" do it "lets me fill in the scheme details" do
expect(page).to have_current_path("/schemes/new")
expect(page).to have_content "Scheme name" expect(page).to have_content "Scheme name"
expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "This scheme contains confidential information"
expect(page).to have_content "Which organisation manages this scheme" expect(page).to have_content "Which organisation manages this scheme"
@ -245,8 +247,8 @@ RSpec.describe "Schemes scheme Features" do
context "when I fill in scheme details and I press save I see primary client group section" do context "when I fill in scheme details and I press save I see primary client group section" do
before do before do
fill_in 'Scheme name', with: 'FooBar' fill_in "Scheme name", with: "FooBar"
check 'This scheme contains confidential information' check "This scheme contains confidential information"
choose "Direct access hostel" choose "Direct access hostel"
choose "Yes – registered care home providing nursing care" choose "Yes – registered care home providing nursing care"
fill_in "Total number of units", with: 1 fill_in "Total number of units", with: 1
@ -261,6 +263,7 @@ RSpec.describe "Schemes scheme Features" do
context "when I select primary client group details" do context "when I select primary client group details" do
before do before do
choose "Homeless families with support needs" choose "Homeless families with support needs"
click_button "Save and continue"
end end
it "lets me confirm if I want to select secondary group details" do it "lets me confirm if I want to select secondary group details" do
@ -270,19 +273,21 @@ RSpec.describe "Schemes scheme Features" do
context "when I confirm the secondary group" do context "when I confirm the secondary group" do
before do before do
choose "Yes" choose "Yes"
click_button "Save and continue"
end end
it "lets me select secondary client group detail" do it "lets me select secondary client group" do
expect(page).to have_content "Does this scheme provide for another client group?" expect(page).to have_content "What is the other client group?"
end end
context "when I select the secondary group" do context "when I select the secondary group" do
before do before do
choose "Homeless families with support needs" choose "Homeless families with support needs"
click_button "Save and continue"
end end
it "lets me select secondary client group detail" do it "lets me select level of support" do
expect(page).to have_content "Does this scheme provide for another client group?" expect(page).to have_content "What support does this scheme provide?"
end end
end end
end end

8
spec/requests/organisations_controller_spec.rb

@ -72,8 +72,8 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321", organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let(:search_param) { "CODE321" } let(:search_param) { searched_scheme.code }
before do before do
FactoryBot.create(:location, scheme: searched_scheme) FactoryBot.create(:location, scheme: searched_scheme)
@ -141,8 +141,8 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321", organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let(:search_param) { "CODE321" } let(:search_param) { searched_scheme.code }
before do before do
FactoryBot.create(:location, scheme: searched_scheme) FactoryBot.create(:location, scheme: searched_scheme)

4
spec/requests/schemes_controller_spec.rb

@ -136,8 +136,8 @@ RSpec.describe SchemesController, type: :request do
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321") } let!(:searched_scheme) { FactoryBot.create(:scheme) }
let(:search_param) { "CODE321" } let(:search_param) { searched_scheme.code }
before do before do
FactoryBot.create(:location, scheme: searched_scheme) FactoryBot.create(:location, scheme: searched_scheme)

Loading…
Cancel
Save