From 565c6dfc6111738128124ffabc3be4c2e9faba81 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 29 Jul 2022 12:16:48 +0100 Subject: [PATCH] Mark scheme location as confirmed --- app/controllers/schemes_controller.rb | 3 +++ .../20220729110846_add_confirmed_location.rb | 7 +++++++ db/schema.rb | 1 + spec/requests/schemes_controller_spec.rb | 18 +++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220729110846_add_confirmed_location.rb diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index c10784c2d..8c7b80833 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -55,6 +55,9 @@ class SchemesController < ApplicationController validation_errors scheme_params if @scheme.errors.empty? && @scheme.update(scheme_params) + if scheme_params[:confirmed] == "true" + @scheme.locations.each {|location| location.update!(confirmed:true)} + end if check_answers if confirm_secondary_page? page redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") diff --git a/db/migrate/20220729110846_add_confirmed_location.rb b/db/migrate/20220729110846_add_confirmed_location.rb new file mode 100644 index 000000000..3656a999e --- /dev/null +++ b/db/migrate/20220729110846_add_confirmed_location.rb @@ -0,0 +1,7 @@ +class AddConfirmedLocation < ActiveRecord::Migration[7.0] + def change + change_table :locations, bulk: true do |t| + t.column :confirmed, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8ead19234..417f03725 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -250,6 +250,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_02_125711) do t.string "mobility_type" t.datetime "startdate", precision: nil t.string "location_admin_district" + t.boolean "confirmed" t.index ["old_id"], name: "index_locations_on_old_id", unique: true t.index ["scheme_id"], name: "index_locations_on_scheme_id" end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index ce6805f35..876100727 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -884,7 +884,8 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support" do let(:user) { FactoryBot.create(:user, :support) } - let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } + let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update )} before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -939,6 +940,21 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") end end + + context "when saving a scheme" do + let(:params) { { scheme: { page: "check-answers", confirmed: "true" } } } + + it "marks the scheme as confirmed" do + expect(scheme_to_update.reload.confirmed?).to eq(true) + end + + it "marks all the scheme locations as confirmed" do + expect(scheme_to_update.locations.count > 0).to eq(true) + scheme_to_update.locations.each do |location| + expect(location.confirmed?).to eq(true) + end + end + end end context "when updating primary client group" do