Browse Source

thanks rubocop

pull/704/head
JG 3 years ago
parent
commit
68d7614efe
  1. 5
      app/controllers/locations_controller.rb
  2. 6
      db/migrate/20220630114748_add_name_to_locations.rb
  3. 6
      db/migrate/20220630120251_change_location_type_of_unit.rb
  4. 1
      spec/requests/locations_controller_spec.rb

5
app/controllers/locations_controller.rb

@ -14,7 +14,7 @@ class LocationsController < ApplicationController
if @location.save if @location.save
redirect_to scheme_check_answers_path(scheme_id: @scheme.id) if location_params[:add_another_location] == "No" 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" redirect_to location_new_scheme_path if location_params[:add_another_location] == "Yes"
elsif else
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
end end
@ -26,7 +26,6 @@ private
end end
def location_params 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) params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id)
required_params
end end
end end

6
db/migrate/20220630114748_add_name_to_locations.rb

@ -1,6 +1,6 @@
class AddNameToLocations < ActiveRecord::Migration[7.0] class AddNameToLocations < ActiveRecord::Migration[7.0]
def change change_table :locations, :bulk => true do |t|
add_column :locations, :name, :string t.string :name
add_column :locations, :total_units, :integer t.integer :total_units
end end
end end

6
db/migrate/20220630120251_change_location_type_of_unit.rb

@ -1,6 +1,6 @@
class ChangeLocationTypeOfUnit < ActiveRecord::Migration[7.0] class ChangeLocationTypeOfUnit < ActiveRecord::Migration[7.0]
def change change_table :locations, :bulk => true do |t|
remove_column :locations, :type_of_unit t.remove :type_of_unit
add_column :locations, :type_of_unit, :integer t.integer :type_of_unit
end end
end end

1
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 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" } } } 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 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) expect { post "/schemes/#{scheme.id}/location/create", params: }.to change(Location, :count).by(1)
follow_redirect! follow_redirect!

Loading…
Cancel
Save