diff --git a/Gemfile.lock b/Gemfile.lock index b71a87ded..d7648b37c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -469,7 +469,6 @@ DEPENDENCIES rubocop-govuk (= 4.3.0) rubocop-performance rubocop-rails - securerandom selenium-webdriver sentry-rails sentry-ruby diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 1d556a4e0..38d83b427 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -32,7 +32,7 @@ class SchemesController < ApplicationController def create @scheme = Scheme.new(clean_params) - @scheme.save + @scheme.save! @path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) render "schemes/primary_client_group" @@ -41,26 +41,27 @@ class SchemesController < ApplicationController def primary_client_group @scheme = Scheme.find_by(id: params[:scheme_id]) - if params[:check_answers] - @path = scheme_check_your_answers_path(scheme_id: @scheme.id) - else - @path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) - end + @path = if params[:check_answers] + scheme_check_your_answers_path(scheme_id: @scheme.id) + else + scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) + end 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[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] - @scheme.update(required_params) + @scheme.update!(required_params) end render "schemes/primary_client_group" end - def confirm_secondary_group + def confirm_secondary_client_group @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] 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 render "schemes/confirm_secondary" @@ -69,8 +70,16 @@ class SchemesController < ApplicationController def secondary_client_group @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) - if params[:confirmed] - params[:confirmed][:selection] == "Yes" ? render("schemes/secondary_client_group") : render("schemes/support") + if params[:scheme] + 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 render "schemes/secondary_client_group" end @@ -80,7 +89,7 @@ class SchemesController < ApplicationController @scheme = Scheme.find_by(id: params[:scheme_id]) if params[:scheme] required_params = params.require(:scheme).permit(:secondary_client_group) - @scheme.update(required_params) if required_params + @scheme.update!(required_params) if required_params end render "schemes/support" @@ -88,11 +97,11 @@ class SchemesController < ApplicationController def details @scheme = Scheme.find_by(id: params[:scheme_id]) - if params[:check_answers] - @path = scheme_check_your_answers_path(scheme_id: @scheme.id) - else - @path = scheme_primary_client_group_path(scheme_id: @scheme.id) - end + @path = if params[:check_answers] + scheme_check_your_answers_path(scheme_id: @scheme.id) + else + scheme_primary_client_group_path(scheme_id: @scheme.id) + end render "schemes/details" end @@ -102,7 +111,7 @@ class SchemesController < ApplicationController 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[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] - @scheme.update(required_params) + @scheme.update!(required_params) end render "schemes/check_answers" @@ -110,12 +119,14 @@ class SchemesController < ApplicationController def update @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 end - private + def edit; end + +private def clean_params required_params = params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 8da1f3ca4..e2500bbe9 100644 --- a/app/models/scheme.rb +++ b/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, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(search_by_code(param)).distinct } - SENSITIVE= { + SENSITIVE = { No: 0, Yes: 1, }.freeze @@ -74,12 +74,18 @@ class Scheme < ApplicationRecord INTENDED_STAY = { "Medium stay": "M", "Permanent": "P", - "Short Stay": "S", + "Short stay": "S", "Very short stay": "V", "Missing": "X", }.freeze + HAS_OTHER_CLIENT_GROUP = { + "Yes": "yes", + "No": "no", + }.freeze + enum intended_stay: INTENDED_STAY, _suffix: true + enum has_other_client_group: HAS_OTHER_CLIENT_GROUP, _suffix: true def check_details_attributes [ @@ -99,6 +105,12 @@ class Scheme < ApplicationRecord ] 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 [ { name: "Secondary client group", value: secondary_client_group }, @@ -128,9 +140,9 @@ class Scheme < ApplicationRecord ] end - private +private 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 diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 998b59819..20f29d0b9 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -33,6 +33,16 @@ ) %> <% 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| %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> diff --git a/app/views/schemes/confirm_secondary.html.erb b/app/views/schemes/confirm_secondary.html.erb index 7f7da7d35..38bdc0eb8 100644 --- a/app/views/schemes/confirm_secondary.html.erb +++ b/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 } %> -<%= 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| %>