Browse Source

Mark scheme location as confirmed

pull/797/head
Kat 3 years ago
parent
commit
565c6dfc61
  1. 3
      app/controllers/schemes_controller.rb
  2. 7
      db/migrate/20220729110846_add_confirmed_location.rb
  3. 1
      db/schema.rb
  4. 18
      spec/requests/schemes_controller_spec.rb

3
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")

7
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

1
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

18
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

Loading…
Cancel
Save