Browse Source

Add test, change error message wording

pull/775/head
Kat 3 years ago
parent
commit
e0ef3a8950
  1. 2
      app/models/scheme.rb
  2. 2
      config/locales/en.yml
  3. 11
      spec/requests/schemes_controller_spec.rb

2
app/models/scheme.rb

@ -212,7 +212,7 @@ class Scheme < ApplicationRecord
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group]
if confirmed == true && required_attributes.any? { |attribute| self[attribute].blank? }
errors.add :base, "Please answer all the required questions"
errors.add :base
end
end
end

2
config/locales/en.yml

@ -65,6 +65,8 @@ en:
invalid: "Select if this scheme provides for another client group"
arrangement_type:
invalid: "Select who provides the support services used by this scheme"
base:
invalid: "You must answer all the required questions for this scheme"
location:
attributes:
startdate:

11
spec/requests/schemes_controller_spec.rb

@ -557,13 +557,22 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) }
before do
sign_in user
patch "/schemes/#{scheme_to_update.id}", params:
end
context "when confirming the scheme" do
let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: "V", confirmed: true, page: "check-answers" } } }
it "does not allow the scheme to be confirmed" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.base.invalid"))
end
end
context "when params are missing" do
let(:params) do
{ scheme: {

Loading…
Cancel
Save