Browse Source

tests for missing params

pull/730/head
JG 3 years ago
parent
commit
6feca03444
  1. 2
      app/models/location.rb
  2. 5
      app/views/locations/edit.html.erb
  3. 39
      spec/requests/schemes_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, :wheelchair_adaptation, presence: true validates :units, :type_of_unit, presence: true
belongs_to :scheme belongs_to :scheme
before_save :infer_la!, if: :postcode_changed? before_save :infer_la!, if: :postcode_changed?

5
app/views/locations/edit.html.erb

@ -41,12 +41,17 @@
wheelchair_user_selection, wheelchair_user_selection,
:id, :id,
:name, :name,
<<<<<<< HEAD
hint: { text: I18n.t("hints.location.wheelchair_adaptation") }, hint: { text: I18n.t("hints.location.wheelchair_adaptation") },
legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %> legend: { text: I18n.t("questions.location.wheelchair_adaptation"), size: "m" } %>
<%= f.govuk_date_field :startdate, <%= f.govuk_date_field :startdate,
legend: { text: I18n.t("questions.location.startdate"), size: "m" }, legend: { text: I18n.t("questions.location.startdate"), size: "m" },
width: 20 %> width: 20 %>
=======
hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" },
legend: { text: "Are the majority of units in this location built or adapted to wheelchair-user standards? (optional)", size: "m" } %>
>>>>>>> 006a9517 (tests for missing params)
<%= govuk_section_break(visible: true, size: "m") %> <%= govuk_section_break(visible: true, size: "m") %>

39
spec/requests/schemes_controller_spec.rb

@ -371,6 +371,25 @@ RSpec.describe SchemesController, type: :request do
expect(Scheme.last.intended_stay).to eq(nil) expect(Scheme.last.intended_stay).to eq(nil)
expect(Scheme.last.id_to_display).to match(/S*/) expect(Scheme.last.id_to_display).to match(/S*/)
end end
context "missing required scheme params" do
let(:params) do
{ scheme: { service_name: "",
scheme_type: "",
registered_under_care_act: "",
support_services_provider: "" } }
end
it "renders the same page with error message" do
post "/schemes", params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content("Create a new supported housing scheme")
expect(page).to have_content("Select the scheme’s type")
expect(page).to have_content("Select if this scheme is registered under the Care Standards Act 2000")
expect(page).to have_content("Select who provides the support services used by this scheme")
expect(page).to have_content("Enter the scheme’s name")
end
end
end end
context "when signed in as a support user" do context "when signed in as a support user" do
@ -414,6 +433,26 @@ RSpec.describe SchemesController, type: :request do
expect(Scheme.last.id_to_display).to match(/S*/) expect(Scheme.last.id_to_display).to match(/S*/)
end end
context "missing required scheme params" do
let(:params) do
{ scheme: { service_name: "",
scheme_type: "",
registered_under_care_act: "",
support_services_provider: "" } }
end
it "renders the same page with error message" do
post "/schemes", params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content("Create a new supported housing scheme")
expect(page).to have_content("Select the scheme’s type")
expect(page).to have_content("Select if this scheme is registered under the Care Standards Act 2000")
expect(page).to have_content("Select who provides the support services used by this scheme")
expect(page).to have_content("Enter the existing organisation’s name")
expect(page).to have_content("Enter the scheme’s name")
end
end
context "when required organisation id param is missing" do context "when required organisation id param is missing" do
let(:params) { { "scheme" => { "service_name" => "qweqwer", "sensitive" => "Yes", "owning_organisation_id" => "", "scheme_type" => "Foyer", "registered_under_care_act" => "Yes – part registered as a care home" } } } let(:params) { { "scheme" => { "service_name" => "qweqwer", "sensitive" => "Yes", "owning_organisation_id" => "", "scheme_type" => "Foyer", "registered_under_care_act" => "Yes – part registered as a care home" } } }

Loading…
Cancel
Save