Browse Source

Add confirmed flag to schemes

pull/756/head
baarkerlounger 3 years ago
parent
commit
2c11032e53
  1. 6
      app/controllers/schemes_controller.rb
  2. 6
      app/views/schemes/check_answers.html.erb
  3. 7
      db/migrate/20220719145718_add_confirmed_to_scheme.rb
  4. 1
      db/schema.rb
  5. 3
      db/seeds.rb
  6. 1
      spec/factories/scheme.rb
  7. 89
      spec/features/schemes_spec.rb

6
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

6
app/views/schemes/check_answers.html.erb

@ -113,4 +113,8 @@
</div>
</div>
<%= 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 %>

7
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

1
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

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

1
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 }

89
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

Loading…
Cancel
Save