From a8196edd0bd10e51d97d70e8b9084aff87e29198 Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 13 Jul 2022 16:07:15 +0100 Subject: [PATCH] tests for location validations --- config/locales/en.yml | 2 - spec/requests/locations_controller_spec.rb | 37 ++++++++++++- spec/requests/schemes_controller_spec.rb | 64 +++++++++++----------- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 296c59aa2..2543fc2b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -65,8 +65,6 @@ en: invalid: "Select who provides the support services used by this scheme" location: attributes: - wheelchair_adaptation: - blank: "Select if majority of units in this location built or adapted to wheelchair-user standards" units: blank: "Enter total number of units at this location" type_of_unit: diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index f3778a6d0..0e7684a2e 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -189,11 +189,13 @@ RSpec.describe LocationsController, type: :request do end context "when required param are missing" do - let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } it "displays the new page with an error message" do expect(response).to have_http_status(:unprocessable_entity) 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.type_of_unit.blank")) end end end @@ -295,6 +297,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + 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.type_of_unit.blank")) + end + end end end @@ -507,6 +520,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + 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.type_of_unit.blank")) + end + end end context "when signed in as a support user" do @@ -616,6 +640,17 @@ RSpec.describe LocationsController, type: :request do expect(Location.last.wheelchair_adaptation).to eq("No") end end + + context "when required param are missing" do + let(:params) { { location: { postcode: "", name: "Test", units: "", type_of_unit: "", wheelchair_adaptation: "No", add_another_location: "No" } } } + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + 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.type_of_unit.blank")) + end + end end end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 9a198c96f..3384bd4b2 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -404,7 +404,6 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.intended_stay).to eq(nil) expect(Scheme.last.id_to_display).to match(/S*/) end - end context "when missing required scheme params" do @@ -413,7 +412,7 @@ RSpec.describe SchemesController, type: :request do scheme_type: "", registered_under_care_act: "", support_services_provider: "" } } - end + end it "renders the same page with error message" do post "/schemes", params: params @@ -487,7 +486,7 @@ RSpec.describe SchemesController, type: :request do it "creates a new scheme for user organisation with valid params" do post "/schemes", params: params - expect(Scheme.last.owning_organisation_id).to eq(organisation.id,) + expect(Scheme.last.owning_organisation_id).to eq(organisation.id) expect(Scheme.last.service_name).to eq("testy") expect(Scheme.last.scheme_type).to eq("Foyer") expect(Scheme.last.sensitive).to eq("Yes") @@ -500,10 +499,9 @@ RSpec.describe SchemesController, type: :request do expect(Scheme.last.intended_stay).to eq(nil) expect(Scheme.last.id_to_display).to match(/S*/) end - end - context "missing required scheme params" do + context "when missing required scheme params" do let(:params) do { scheme: { service_name: "", scheme_type: "", @@ -567,19 +565,21 @@ RSpec.describe SchemesController, type: :request do end context "when params are missing" do - let(:params) do { scheme: { - service_name: "", - managing_organisation_id: "", - owning_organisation_id: "", - primary_client_group: "", - secondary_client_group: "", - scheme_type: "", - registered_under_care_act: "", - support_type: "", - intended_stay: "", - support_services_provider: "", - has_other_client_group: "", - page: "details" } } + let(:params) do + { scheme: { + service_name: "", + managing_organisation_id: "", + owning_organisation_id: "", + primary_client_group: "", + secondary_client_group: "", + scheme_type: "", + registered_under_care_act: "", + support_type: "", + intended_stay: "", + support_services_provider: "", + has_other_client_group: "", + page: "details", + } } end it "renders primary client group after successful update" do @@ -856,19 +856,21 @@ RSpec.describe SchemesController, type: :request do end context "when params are missing" do - let(:params) do { scheme: { - service_name: "", - managing_organisation_id: "", - owning_organisation_id: "", - primary_client_group: "", - secondary_client_group: "", - scheme_type: "", - registered_under_care_act: "", - support_type: "", - intended_stay: "", - support_services_provider: "", - has_other_client_group: "", - page: "details" } } + let(:params) do + { scheme: { + service_name: "", + managing_organisation_id: "", + owning_organisation_id: "", + primary_client_group: "", + secondary_client_group: "", + scheme_type: "", + registered_under_care_act: "", + support_type: "", + intended_stay: "", + support_services_provider: "", + has_other_client_group: "", + page: "details", + } } end it "renders primary client group after successful update" do