From 901a90bddecf5cf20fe37357f5eadae49922ba45 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 7 Dec 2022 09:46:38 +0000 Subject: [PATCH] test: fix failing tests --- app/controllers/locations_controller.rb | 3 +-- app/models/location.rb | 2 +- app/views/locations/local_authority.html.erb | 4 ++-- spec/features/schemes_spec.rb | 20 ++++++++++---------- spec/models/location_spec.rb | 6 +++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 205d78009..1cef5dadb 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -144,8 +144,7 @@ class LocationsController < ApplicationController def check_answers; end def confirm - @location.confirmed! - flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" + flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" redirect_to scheme_locations_path(@scheme) end diff --git a/app/models/location.rb b/app/models/location.rb index a8c51c537..0bad9441b 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -430,7 +430,7 @@ class Location < ApplicationRecord end def validate_confirmed - self.confirmed = [postcode, name, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?) + self.confirmed = [postcode, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?) end def confirmed! diff --git a/app/views/locations/local_authority.html.erb b/app/views/locations/local_authority.html.erb index 767beb3c7..69b36b5be 100644 --- a/app/views/locations/local_authority.html.erb +++ b/app/views/locations/local_authority.html.erb @@ -29,10 +29,10 @@
<% if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority" %> <%= f.govuk_submit "Save changes" %> - <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> + <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> - <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> + <%= govuk_link_to "Skip for now", scheme_location_name_path(@scheme, @location), secondary: true %> <% end %>
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index caa72b73e..b9721111c 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -304,7 +304,7 @@ RSpec.describe "Schemes scheme Features" do end it "has the correct action button text" do - expect(page).to have_button("Add this location") + expect(page).to have_button("Save and return to locations") end it "allows you to edit the newly added location" do @@ -313,7 +313,7 @@ RSpec.describe "Schemes scheme Features" do context "when you click save" do before do - click_button "Add this location" + click_button "Save and return to locations" end it "displays a updated banner" do @@ -329,7 +329,7 @@ RSpec.describe "Schemes scheme Features" do context "when you click to view the scheme details" do before do - click_button "Add this location" + click_button "Save and return to locations" click_link("Scheme") end @@ -492,7 +492,7 @@ RSpec.describe "Schemes scheme Features" do it "lets me check my answers after adding a second location" do fill_in_and_save_location - click_button "Add this location" + click_button "Save and return to locations" fill_in_and_save_second_location expect(page).to have_content "Check your answers" end @@ -503,7 +503,7 @@ RSpec.describe "Schemes scheme Features" do create_and_save_a_scheme click_button "Create scheme" fill_in_and_save_location - click_button "Add this location" + click_button "Save and return to locations" click_link "Locations" end @@ -520,7 +520,7 @@ RSpec.describe "Schemes scheme Features" do it "displays information about another location" do fill_in_and_save_second_location - click_button "Add this location" + click_button "Save and return to locations" expect(page).to have_content "Locations" expect(page).to have_content "#{scheme.locations.count} total location" end @@ -538,7 +538,7 @@ RSpec.describe "Schemes scheme Features" do create_and_save_a_scheme click_button "Create scheme" fill_in_and_save_second_location - click_button "Add this location" + click_button "Save and return to locations" end it "displays changed location" do @@ -947,7 +947,7 @@ RSpec.describe "Schemes scheme Features" do end it "has the correct action button text" do - expect(page).to have_button("Add this location") + expect(page).to have_button("Save and return to locations") end it "allows you to edit the newly added location" do @@ -956,7 +956,7 @@ RSpec.describe "Schemes scheme Features" do context "when you click save" do before do - click_button "Add this location" + click_button "Save and return to locations" end it "displays a updated banner" do @@ -972,7 +972,7 @@ RSpec.describe "Schemes scheme Features" do context "when you click to view the scheme details" do before do - click_button "Add this location" + click_button "Save and return to locations" click_link("Scheme") end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index c6167e612..d3f69415b 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -120,7 +120,7 @@ RSpec.describe Location, type: :model do before do FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today) FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day) - FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, confirmed: false) + FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil) end @@ -152,8 +152,8 @@ RSpec.describe Location, type: :model do end context "when filtering by active locations" do - it "returns only locations that started today or earlier and have been confirmed" do - expect(described_class.active.count).to eq(1) + it "returns only locations that started today or earlier and are complete (and so confirmed)" do + expect(described_class.active.count).to eq(2) end end end