From 2c11032e5386ed6e37e84d1a59d0d840da974b57 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 19 Jul 2022 17:34:41 +0100 Subject: [PATCH] Add confirmed flag to schemes --- app/controllers/schemes_controller.rb | 6 +- app/views/schemes/check_answers.html.erb | 6 +- .../20220719145718_add_confirmed_to_scheme.rb | 7 ++ db/schema.rb | 1 + db/seeds.rb | 3 + spec/factories/scheme.rb | 1 + spec/features/schemes_spec.rb | 89 ++++++++++++++++++- 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20220719145718_add_confirmed_to_scheme.rb diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 44c5ab869..c3bafa318 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -47,7 +47,6 @@ class SchemesController < ApplicationController page = params[:scheme][:page] validation_errors scheme_params - if @scheme.errors.empty? && @scheme.update(scheme_params) if check_answers if confirm_secondary_page? page @@ -150,6 +149,8 @@ private end when "edit-name" scheme_path(@scheme) + when "check-answers" + schemes_path(scheme_id: @scheme.id) end end @@ -166,7 +167,8 @@ private :secondary_client_group, :support_type, :arrangement_type, - :intended_stay) + :intended_stay, + :confirmed) full_params = required_params[:arrangement_type] == "D" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 74009a84e..82369ea63 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -113,4 +113,8 @@ -<%= govuk_button_link_to "Create scheme", schemes_path(scheme_id: @scheme.id), html: { method: :get } %> +<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %> + <%= f.hidden_field :page, value: "check-answers" %> + <%= f.hidden_field :confirmed, value: "true" %> + <%= f.govuk_submit "Create scheme" %> +<% end %> diff --git a/db/migrate/20220719145718_add_confirmed_to_scheme.rb b/db/migrate/20220719145718_add_confirmed_to_scheme.rb new file mode 100644 index 000000000..f0372554e --- /dev/null +++ b/db/migrate/20220719145718_add_confirmed_to_scheme.rb @@ -0,0 +1,7 @@ +class AddConfirmedToScheme < ActiveRecord::Migration[7.0] + def change + change_table :schemes, bulk: true do |t| + t.column :confirmed, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c05d38920..978fc7af6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -320,6 +320,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_20_111635) do t.string "old_id" t.integer "old_visible_id" t.integer "total_units" + t.boolean "confirmed" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 3a084e436..264b25d69 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -80,6 +80,7 @@ unless Rails.env.test? primary_client_group: "O", secondary_client_group: "H", owning_organisation: org, + confirmed: true, created_at: Time.zone.now, ) @@ -93,6 +94,7 @@ unless Rails.env.test? primary_client_group: "D", secondary_client_group: "E", owning_organisation: org, + confirmed: true, created_at: Time.zone.now, ) @@ -106,6 +108,7 @@ unless Rails.env.test? primary_client_group: "G", secondary_client_group: "R", owning_organisation: dummy_org, + confirmed: true, created_at: Time.zone.now, ) diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb index 4e35d0b8e..ab3342fea 100644 --- a/spec/factories/scheme.rb +++ b/spec/factories/scheme.rb @@ -10,6 +10,7 @@ FactoryBot.define do primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } owning_organisation { FactoryBot.create(:organisation) } + confirmed { true } created_at { Time.zone.now } trait :export do sensitive { 1 } diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 763edd66e..51f9bdcf0 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -508,7 +508,7 @@ RSpec.describe "Schemes scheme Features" do before do create_and_save_a_scheme fill_in_and_save_location - click_link "Create scheme" + click_button "Create scheme" end it "adds scheme to the list of schemes" do @@ -516,7 +516,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.service_name expect(page).to have_content scheme.owning_organisation.name - expect(page).to have_content "#{scheme.owning_organisation.name} has been created." + expect(page).to have_content "#{scheme.service_name} has been created." end end @@ -692,6 +692,91 @@ RSpec.describe "Schemes scheme Features" do end end end + + context "when I search for a specific location" do + before do + click_link("Locations") + end + + it "there is a search bar with a message and search button for locations" do + expect(page).to have_field("search") + expect(page).to have_content("Search by location name or postcode") + expect(page).to have_button("Search") + end + + context "when I fill in search information and press the search button" do + let(:postcode_to_search) { "NW38RR" } + let(:location_name_to_search) { "search name location" } + let(:location_to_search) { FactoryBot.create(:location, postcode: postcode_to_search, name: location_name_to_search, scheme:) } + + before do + fill_in("search", with: location_to_search.name) + click_button("Search") + end + + it "displays scheme matching the location name" do + expect(page).to have_content(location_name_to_search) + end + + context "when I want to clear results" do + it "there is link to clear the search results" do + expect(page).to have_link("Clear search") + end + + it "displays all schemes after I clear the search results" do + click_link("Clear search") + Location.all.each do |location| + expect(page).to have_content(location.name) + end + end + end + end + end + + context "when the user clicks add location" do + before do + click_link("Locations") + click_link("Add a location") + end + + it "shows the new location form" do + expect(page).to have_content("Add a location to this scheme") + end + + context "when the user completes the new location form" do + let(:location_name) { "Area 42" } + + before do + fill_in "Postcode", with: "NW1L 5DP" + fill_in "Location name (optional)", with: location_name + fill_in "Total number of units at this location", with: 1 + choose "Bungalow" + choose "location-wheelchair-adaptation-no-field" + choose "location-add-another-location-no-field" + click_button "Save and continue" + end + + it "shows the check answers page location tab" do + expect(page.current_url.split("/").last).to eq("check-answers#locations") + expect(page).to have_content(location_name) + end + + it "has the correct action button text" do + expect(page).to have_button("Save") + expect(page).not_to have_button("Create scheme") + end + + context "when you click to view the scheme details" do + before do + click_link("Scheme") + end + + it "does not let you change details other than the name" do + assert_selector "a", text: "Change", count: 1 + end + end + end + end end end end