Browse Source

Add validatio to mobility type

pull/763/head
Kat 3 years ago
parent
commit
c4c3f3e648
  1. 2
      app/models/location.rb
  2. 2
      config/locales/en.yml
  3. 17
      spec/requests/locations_controller_spec.rb

2
app/models/location.rb

@ -1,6 +1,6 @@
class Location < ApplicationRecord class Location < ApplicationRecord
validate :validate_postcode validate :validate_postcode
validates :units, :type_of_unit, presence: true validates :units, :type_of_unit, :mobility_type, presence: true
belongs_to :scheme belongs_to :scheme
before_save :infer_la!, if: :postcode_changed? before_save :infer_la!, if: :postcode_changed?

2
config/locales/en.yml

@ -76,6 +76,8 @@ en:
blank: "Enter total number of units at this location" blank: "Enter total number of units at this location"
type_of_unit: type_of_unit:
blank: "Select the most common type of unit at this location" blank: "Select the most common type of unit at this location"
mobility_type:
blank: "Select the mobility standards for the majority of units in this location"
validations: validations:
organisation: organisation:

17
spec/requests/locations_controller_spec.rb

@ -116,7 +116,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -125,7 +125,7 @@ RSpec.describe LocationsController, type: :request do
context "when trying to add location to a scheme that belongs to another organisation" do context "when trying to add location to a scheme that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
post "/schemes/#{another_scheme.id}/locations", params: params post "/schemes/#{another_scheme.id}/locations", params: params
@ -153,7 +153,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
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}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -197,6 +197,7 @@ RSpec.describe LocationsController, type: :request do
expect(page).to have_content(I18n.t("validations.postcode")) expect(page).to have_content(I18n.t("validations.postcode"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.units.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.type_of_unit.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.location.attributes.mobility_type.blank"))
end end
end end
@ -248,7 +249,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme) }
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -271,7 +272,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -289,7 +290,7 @@ RSpec.describe LocationsController, type: :request do
end end
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", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "Yes", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
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}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -306,7 +307,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
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}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -323,7 +324,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is not selected" do context "when do you want to add another location is not selected" do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }
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}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)

Loading…
Cancel
Save