diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index ab99fe326..df2744fb0 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -14,7 +14,7 @@ class LocationsController < ApplicationController if @location.save redirect_to scheme_check_answers_path(scheme_id: @scheme.id) if location_params[:add_another_location] == "No" redirect_to location_new_scheme_path if location_params[:add_another_location] == "Yes" - elsif + else render :new, status: :unprocessable_entity end end @@ -26,7 +26,6 @@ private end def location_params - required_params = params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) - required_params + params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) end end diff --git a/app/models/location.rb b/app/models/location.rb index 6db97b4e3..92b8457e6 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -11,13 +11,13 @@ class Location < ApplicationRecord enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS TYPE_OF_UNIT = { - "Self-contained flat or bedsit": 1, - "Self-contained flat or bedsit with common facilities": 2, - "Shared flat": 3, - "Shared house or hostel": 4, - "Bungalow": 5, - "Self-contained house": 6, - }.freeze + "Self-contained flat or bedsit": 1, + "Self-contained flat or bedsit with common facilities": 2, + "Shared flat": 3, + "Shared house or hostel": 4, + "Bungalow": 5, + "Self-contained house": 6, + }.freeze enum type_of_unit: TYPE_OF_UNIT diff --git a/db/migrate/20220630114748_add_name_to_locations.rb b/db/migrate/20220630114748_add_name_to_locations.rb index f2ba9ffe5..a450fb8a6 100644 --- a/db/migrate/20220630114748_add_name_to_locations.rb +++ b/db/migrate/20220630114748_add_name_to_locations.rb @@ -1,6 +1,6 @@ class AddNameToLocations < ActiveRecord::Migration[7.0] - def change - add_column :locations, :name, :string - add_column :locations, :total_units, :integer + change_table :locations, :bulk => true do |t| + t.string :name + t.integer :total_units end end diff --git a/db/migrate/20220630120251_change_location_type_of_unit.rb b/db/migrate/20220630120251_change_location_type_of_unit.rb index 644b3871a..daba51278 100644 --- a/db/migrate/20220630120251_change_location_type_of_unit.rb +++ b/db/migrate/20220630120251_change_location_type_of_unit.rb @@ -1,6 +1,6 @@ class ChangeLocationTypeOfUnit < ActiveRecord::Migration[7.0] - def change - remove_column :locations, :type_of_unit - add_column :locations, :type_of_unit, :integer + change_table :locations, :bulk => true do |t| + t.remove :type_of_unit + t.integer :type_of_unit end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 509e1d9cd..8d4fba10c 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -105,6 +105,7 @@ RSpec.describe LocationsController, type: :request do context "when do you want to add another location is selected as yes" do let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes" } } } + it "creates a new location for scheme with valid params and redirects to correct page" do expect { post "/schemes/#{scheme.id}/location/create", params: }.to change(Location, :count).by(1) follow_redirect!