From 2d60f81887340596a79b5ee4c538ac0f22352764 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 22 Mar 2023 11:35:12 +0000 Subject: [PATCH] feat: only confirm locations if complete (old) AND save button clicked (new) --- app/controllers/locations_controller.rb | 11 ++++++++++- app/models/location.rb | 5 ----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 5b39fa875..9b1d32113 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -134,10 +134,19 @@ class LocationsController < ApplicationController def check_answers; end def confirm - flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" + confirm_location + if @location.confirmed + flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" + end redirect_to scheme_locations_path(@scheme) end + def confirm_location + if [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?) + @location.update!(confirmed: true) + end + end + def show; end def new_deactivation diff --git a/app/models/location.rb b/app/models/location.rb index 6050a05cf..92ed5e47b 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -7,7 +7,6 @@ class Location < ApplicationRecord validates :mobility_type, on: :mobility_type, presence: { message: I18n.t("validations.location.mobility_standards") } validates :startdate, on: :startdate, presence: { message: I18n.t("validations.location.startdate_invalid") } validate :validate_startdate, on: :startdate, if: proc { |model| model.startdate.presence } - validate :validate_confirmed belongs_to :scheme has_many :lettings_logs, class_name: "LettingsLog" has_many :location_deactivation_periods, class_name: "LocationDeactivationPeriod" @@ -127,10 +126,6 @@ class Location < ApplicationRecord end end - def validate_confirmed - self.confirmed = [postcode, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?) - end - def linked_local_authorities la = LocalAuthority.find_by(code: location_code) return LocalAuthority.none unless la