Browse Source

Correctable offenses

pull/264/head
Stéphane Meny 3 years ago
parent
commit
d07789178e
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 1
      .rubocop.yml
  2. 1
      spec/controllers/admin/admin_users_controller_spec.rb
  3. 4
      spec/controllers/admin/case_logs_controller_spec.rb
  4. 2
      spec/controllers/admin/dashboard_controller_spec.rb
  5. 1
      spec/controllers/admin/organisations_controller_spec.rb
  6. 1
      spec/controllers/admin/users_controller_spec.rb
  7. 16
      spec/features/form/check_answers_page_spec.rb
  8. 2
      spec/features/test_spec.rb
  9. 5
      spec/features/user_spec.rb
  10. 1
      spec/helpers/conditional_questions_helper_spec.rb
  11. 1
      spec/helpers/question_attribute_helper_spec.rb
  12. 1
      spec/helpers/question_view_helper.rb
  13. 1
      spec/helpers/tab_nav_helper_spec.rb
  14. 1
      spec/helpers/tasklist_helper_spec.rb
  15. 1
      spec/lib/tasks/data_import/organisations_spec.rb
  16. 14
      spec/models/case_log_spec.rb
  17. 3
      spec/models/form/page_spec.rb
  18. 3
      spec/models/form/question_spec.rb
  19. 3
      spec/models/form/section_spec.rb
  20. 7
      spec/models/form/subsection_spec.rb
  21. 13
      spec/models/form_handler_spec.rb
  22. 2
      spec/models/form_spec.rb
  23. 1
      spec/models/organisation_spec.rb
  24. 1
      spec/models/user_spec.rb
  25. 4
      spec/models/validations/local_authority_validations_spec.rb
  26. 6
      spec/models/validations/property_validations_spec.rb
  27. 3
      spec/presenters/error_summary_full_messages_presenter_spec.rb
  28. 4
      spec/requests/auth/passwords_controller_spec.rb
  29. 1
      spec/requests/bulk_upload_controller_spec.rb
  30. 16
      spec/requests/form_controller_spec.rb
  31. 10
      spec/requests/organisations_controller_spec.rb
  32. 4
      spec/services/paas_configuration_service_spec.rb
  33. 4
      spec/support/controller_macros.rb
  34. 21
      spec/views/case_log_index_view_spec.rb
  35. 6
      spec/views/form/page_view_spec.rb

1
.rubocop.yml

@ -1,6 +1,7 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
inherit_gem:
rubocop-govuk:

1
spec/controllers/admin/admin_users_controller_spec.rb

@ -6,6 +6,7 @@ describe Admin::AdminUsersController, type: :controller do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:resource_title) { "Admin Users" }
let(:valid_session) { {} }
login_admin_user
describe "Get admin users" do

4
spec/controllers/admin/case_logs_controller_spec.rb

@ -6,14 +6,17 @@ describe Admin::CaseLogsController, type: :controller do
before do
RequestHelper.stub_http_requests
end
render_views
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:resource_title) { "Logs" }
let(:valid_session) { {} }
login_admin_user
describe "Get case logs" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
before do
get :index, session: valid_session
end
@ -37,6 +40,7 @@ describe Admin::CaseLogsController, type: :controller do
},
}
end
it "creates a new case log" do
expect { post :create, session: valid_session, params: params }.to change(CaseLog, :count).by(1)
end

2
spec/controllers/admin/dashboard_controller_spec.rb

@ -6,6 +6,7 @@ describe Admin::DashboardController, type: :controller do
before do
RequestHelper.stub_http_requests
end
render_views
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:resource_title) { "Dashboard" }
@ -13,6 +14,7 @@ describe Admin::DashboardController, type: :controller do
let!(:case_log_2) { FactoryBot.create(:case_log, :in_progress) }
let!(:completed_case_log) { FactoryBot.create(:case_log, :completed) }
let(:valid_session) { {} }
login_admin_user
describe "Get case logs" do

1
spec/controllers/admin/organisations_controller_spec.rb

@ -7,6 +7,7 @@ describe Admin::OrganisationsController, type: :controller do
let(:resource_title) { "Organisations" }
let(:valid_session) { {} }
let!(:organisation) { FactoryBot.create(:organisation) }
login_admin_user
describe "Organisations" do

1
spec/controllers/admin/users_controller_spec.rb

@ -8,6 +8,7 @@ describe Admin::UsersController, type: :controller do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:resource_title) { "Users" }
let(:valid_session) { {} }
login_admin_user
describe "Get users" do

16
spec/features/form/check_answers_page_spec.rb

@ -5,6 +5,8 @@ require_relative "../../request_helper"
RSpec.describe "Form Check Answers Page" do
include Helpers
let(:user) { FactoryBot.create(:user) }
let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" }
let(:case_log) do
FactoryBot.create(
:case_log,
@ -27,16 +29,14 @@ RSpec.describe "Form Check Answers Page" do
sign_in user
end
let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" }
context "when the user needs to check their answers for a subsection" do
let(:last_question_for_subsection) { "household-number-of-other-members" }
it "can be visited by URL" do
visit("/logs/#{id}/#{subsection}/check-answers")
expect(page).to have_content("#{subsection.tr('-', ' ').humanize} Check your answers")
end
let(:last_question_for_subsection) { "household-number-of-other-members" }
it "redirects to the check answers page when answering the last question and clicking save and continue" do
fill_in_number_question(id, "other_hhmemb", 0, last_question_for_subsection)
expect(page).to have_current_path("/logs/#{id}/#{subsection}/check-answers")
@ -50,7 +50,7 @@ RSpec.describe "Form Check Answers Page" do
end
end
it "should display answers given by the user for the question in the subsection" do
it "displays answers given by the user for the question in the subsection" do
fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age")
choose("case-log-sex1-non-binary-field")
click_button("Save and continue")
@ -61,14 +61,14 @@ RSpec.describe "Form Check Answers Page" do
# Regex explanation: match the string "Answer" but not if it's follow by "the missing questions"
# This way only the links in the table will get picked up
it "should have an answer link for questions missing an answer" do
it "has an answer link for questions missing an answer" do
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age")
end
it "should have a change link for answered questions" do
it "has a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age")
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
@ -76,7 +76,7 @@ RSpec.describe "Form Check Answers Page" do
expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age")
end
it "should have a change link for answered questions" do
it "has a change link for answered questions" do
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 5
assert_selector "a", text: "Change", count: 0

2
spec/features/test_spec.rb

@ -7,6 +7,6 @@ RSpec.describe "Test Features" do
it "Responds to a health check" do
visit("/health")
expect(page).to have_http_status(204)
expect(page).to have_http_status(:no_content)
end
end

5
spec/features/user_spec.rb

@ -6,6 +6,7 @@ RSpec.describe "User Features" do
let(:reset_password_template_id) { DeviseNotifyMailer::RESET_PASSWORD_TEMPLATE_ID }
let(:notify_client) { double(Notifications::Client) }
let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" }
before do
allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client)
allow_any_instance_of(DeviseNotifyMailer).to receive(:host).and_return("test.com")
@ -171,7 +172,7 @@ RSpec.describe "User Features" do
end
context "Your Account " do
before(:each) do
before do
visit("/logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: "pAssword1")
@ -207,7 +208,7 @@ RSpec.describe "User Features" do
end
context "Adding a new user" do
before(:each) do
before do
visit("/logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: "pAssword1")

1
spec/helpers/conditional_questions_helper_spec.rb

@ -15,6 +15,7 @@ RSpec.describe ConditionalQuestionsHelper do
describe "find conditional question" do
let(:question) { page.questions.find { |q| q.id == "armedforces" } }
let(:answer_value) { "A current or former regular in the UK Armed Forces (excluding National Service)" }
it "returns the conditional question for a given answer option" do
expect(find_conditional_question(page, question, answer_value))
end

1
spec/helpers/question_attribute_helper_spec.rb

@ -46,6 +46,7 @@ RSpec.describe QuestionAttributeHelper do
"data-info": question.conditional_for.to_json,
}
end
it "correctly merges html attributes" do
expect(stimulus_html_attributes(question)).to eq(expected_attribs)
end

1
spec/helpers/question_view_helper.rb

@ -25,6 +25,7 @@ RSpec.describe QuestionViewHelper do
context "a conditional question" do
let(:conditional) { true }
it "returns nil" do
expect(subject).to be_nil
end

1
spec/helpers/tab_nav_helper_spec.rb

@ -21,6 +21,7 @@ RSpec.describe TabNavHelper do
describe "#tab_items" do
context "user is a data_coordinator" do
let(:user) { FactoryBot.build(:user, :data_coordinator, organisation: organisation) }
it "returns details and user tabs" do
result = tab_items(user).map { |i| i[:name] }
expect(result.count).to eq(2)

1
spec/helpers/tasklist_helper_spec.rb

@ -5,6 +5,7 @@ RSpec.describe TasklistHelper do
before do
RequestHelper.stub_http_requests
end
let(:empty_case_log) { FactoryBot.create(:case_log) }
let(:case_log) { FactoryBot.create(:case_log, :in_progress) }

1
spec/lib/tasks/data_import/organisations_spec.rb

@ -3,6 +3,7 @@ require "rake"
describe "rake data_import:organisations", type: :task do
subject(:task) { Rake::Task["data_import:organisations"] }
let(:fixture_path) { "spec/fixtures/softwire_imports/organisations" }
before do

14
spec/models/case_log_spec.rb

@ -4,6 +4,7 @@ require_relative "../request_helper"
RSpec.describe Form, type: :model do
let(:owning_organisation) { FactoryBot.create(:organisation) }
let(:managing_organisation) { owning_organisation }
before do
RequestHelper.stub_http_requests
end
@ -12,11 +13,12 @@ RSpec.describe Form, type: :model do
let(:case_log) { FactoryBot.build(:case_log) }
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1)) }
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1)) }
it "has returns the correct form based on the start date" do
expect(case_log.form_name).to eq("2021_2022")
expect(case_log_2.form_name).to eq("2021_2022")
expect(case_log_year_2.form_name).to eq("2023_2024")
expect(case_log.form).to be_a(Form)
expect(case_log.form).to be_a(described_class)
end
end
@ -119,6 +121,7 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "other reason for leaving last settled home validation" do
it "must be provided if main reason for leaving last settled home was given as other" do
expect {
@ -871,7 +874,7 @@ RSpec.describe Form, type: :model do
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
}.not_to raise_error
expect {
CaseLog.create!(housingneeds_b: "Yes",
@ -879,7 +882,7 @@ RSpec.describe Form, type: :model do
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
}.not_to raise_error
expect {
CaseLog.create!(housingneeds_c: "Yes",
@ -887,7 +890,7 @@ RSpec.describe Form, type: :model do
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
}.not_to raise_error
expect {
CaseLog.create!(housingneeds_g: "Yes",
@ -1201,12 +1204,13 @@ RSpec.describe Form, type: :model do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") }
it "clears the answer" do
expect { case_log.update!(preg_occ: nil) }.to change { case_log.cbl }.from("Yes").to(nil)
expect { case_log.update!(preg_occ: nil) }.to change(case_log, :cbl).from("Yes").to(nil)
end
end
context "two pages with the same question key, only one's dependency is met" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") }
it "does not clear the answer" do
expect(case_log.cbl).to eq("Yes")
end

3
spec/models/form/page_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Page, type: :model do
subject { described_class.new(page_id, page_definition, subsection) }
let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form }
let(:section_id) { "rent_and_charges" }
@ -11,7 +13,6 @@ RSpec.describe Form::Page, type: :model do
let(:subsection) { Form::Subsection.new(subsection_id, subsection_definition, section) }
let(:page_id) { "net_income" }
let(:page_definition) { subsection_definition["pages"][page_id] }
subject { Form::Page.new(page_id, page_definition, subsection) }
it "has an id" do
expect(subject.id).to eq(page_id)

3
spec/models/form/question_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Question, type: :model do
subject { described_class.new(question_id, question_definition, page) }
let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form }
let(:section_id) { "rent_and_charges" }
@ -14,7 +16,6 @@ RSpec.describe Form::Question, type: :model do
let(:page) { Form::Page.new(page_id, page_definition, subsection) }
let(:question_id) { "earnings" }
let(:question_definition) { page_definition["questions"][question_id] }
subject { Form::Question.new(question_id, question_definition, page) }
it "has an id" do
expect(subject.id).to eq(question_id)

3
spec/models/form/section_spec.rb

@ -1,11 +1,12 @@
require "rails_helper"
RSpec.describe Form::Section, type: :model do
subject { described_class.new(section_id, section_definition, form) }
let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form }
let(:section_id) { "household" }
let(:section_definition) { form.form_definition["sections"][section_id] }
subject { Form::Section.new(section_id, section_definition, form) }
it "has an id" do
expect(subject.id).to eq(section_id)

7
spec/models/form/subsection_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Subsection, type: :model do
subject { described_class.new(subsection_id, subsection_definition, section) }
let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form }
let(:section_id) { "household" }
@ -8,7 +10,6 @@ RSpec.describe Form::Subsection, type: :model do
let(:section) { Form::Section.new(section_id, section_definition, form) }
let(:subsection_id) { "household_characteristics" }
let(:subsection_definition) { section_definition["subsections"][subsection_id] }
subject { Form::Subsection.new(subsection_id, subsection_definition, section) }
it "has an id" do
expect(subject.id).to eq(subsection_id)
@ -37,7 +38,7 @@ RSpec.describe Form::Subsection, type: :model do
it "has a completed status for completed subsection" do
subsection_definition = section_definition["subsections"]["household_needs"]
subject = Form::Subsection.new("household_needs", subsection_definition, section)
subject = described_class.new("household_needs", subsection_definition, section)
case_log.armedforces = "No"
case_log.illness = "No"
case_log.housingneeds_a = "Yes"
@ -59,7 +60,7 @@ RSpec.describe Form::Subsection, type: :model do
it "has question helpers for the number of answered questions" do
subsection_definition = section_definition["subsections"]["household_needs"]
subject = Form::Subsection.new("household_needs", subsection_definition, section)
subject = described_class.new("household_needs", subsection_definition, section)
expected_questions = %w[armedforces illness accessibility_requirements la condition_effects]
case_log.armedforces = "No"
case_log.illness = "No"

13
spec/models/form_handler_spec.rb

@ -2,9 +2,10 @@ require "rails_helper"
RSpec.describe FormHandler do
let(:test_form_name) { "2021_2022" }
describe "Get all forms" do
it "should be able to load all the forms" do
form_handler = FormHandler.instance
it "is able to load all the forms" do
form_handler = described_class.instance
all_forms = form_handler.forms
expect(all_forms.count).to be >= 1
expect(all_forms[test_form_name]).to be_a(Form)
@ -12,16 +13,16 @@ RSpec.describe FormHandler do
end
describe "Get specific form" do
it "should be able to load a specific form" do
form_handler = FormHandler.instance
it "is able to load a specific form" do
form_handler = described_class.instance
form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form)
expect(form.pages.count).to eq(29)
end
end
it "should only load the form once at boot time" do
form_handler = FormHandler.instance
it "onlies load the form once at boot time" do
form_handler = described_class.instance
expect(Form).not_to receive(:new).with(:any, test_form_name)
expect(form_handler.get_form(test_form_name)).to be_a(Form)
end

2
spec/models/form_spec.rb

@ -8,6 +8,7 @@ RSpec.describe Form, type: :model do
describe ".next_page" do
let(:previous_page) { form.get_page("person_1_age") }
it "returns the next page given the previous" do
expect(form.next_page(previous_page, case_log)).to eq("person_1_gender")
end
@ -35,6 +36,7 @@ RSpec.describe Form, type: :model do
describe "invalidated_page_questions" do
context "dependencies not met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question declaration] }
it "returns an array of question keys whose pages conditions are not met" do
expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid)
end

1
spec/models/organisation_spec.rb

@ -5,6 +5,7 @@ RSpec.describe Organisation, type: :model do
before do
RequestHelper.stub_http_requests
end
describe "#new" do
let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }

1
spec/models/user_spec.rb

@ -5,6 +5,7 @@ RSpec.describe User, type: :model do
before do
RequestHelper.stub_http_requests
end
describe "#new" do
let(:user) { FactoryBot.create(:user) }
let(:other_organisation) { FactoryBot.create(:organisation) }

4
spec/models/validations/local_authority_validations_spec.rb

@ -12,7 +12,7 @@ RSpec.describe CaseLog do
describe "#new" do
it "raises an error when previous_postcode is present and invalid" do
expect {
CaseLog.create!(
described_class.create!(
previous_postcode: "invalid_postcode",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
@ -49,7 +49,7 @@ RSpec.describe Validations::LocalAuthorityValidations do
it "does add an error when the postcode is invalid" do
record.previous_postcode = "invalid"
subject.validate_previous_accommodation_postcode(record)
expect(record.errors).to_not be_empty
expect(record.errors).not_to be_empty
expect(record.errors["previous_postcode"]).to include(match I18n.t("validations.postcode"))
end
end

6
spec/models/validations/property_validations_spec.rb

@ -12,7 +12,7 @@ RSpec.describe CaseLog do
describe "#new" do
it "raises an error when offered is present and invalid" do
expect {
CaseLog.create!(
described_class.create!(
offered: "random",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
@ -50,11 +50,11 @@ RSpec.describe Validations::PropertyValidations do
it "does add an error when offered is invalid" do
record.offered = "invalid"
subject.validate_property_number_of_times_relet(record)
expect(record.errors).to_not be_empty
expect(record.errors).not_to be_empty
expect(record.errors["offered"]).to include(match(expected_error))
record.offered = 21
subject.validate_property_number_of_times_relet(record)
expect(record.errors).to_not be_empty
expect(record.errors).not_to be_empty
expect(record.errors["offered"]).to include(match(expected_error))
end
end

3
spec/presenters/error_summary_full_messages_presenter_spec.rb

@ -1,9 +1,10 @@
require "rails_helper"
RSpec.describe ErrorSummaryFullMessagesPresenter do
subject { described_class.new(error_messages) }
let(:error_messages) { { reset_password_token: %w[expired] } }
let(:formatted_error_messages) { [[:reset_password_token, "Reset password token expired"]] }
subject { described_class.new(error_messages) }
it "formats messages to include the attribute name" do
expect(subject.formatted_error_messages).to eq(formatted_error_messages)

4
spec/requests/auth/passwords_controller_spec.rb

@ -25,7 +25,7 @@ RSpec.describe Auth::PasswordsController, type: :request do
context "when a password reset is requested with an email that doesn't exist in the system" do
before do
allow_any_instance_of(Auth::PasswordsController).to receive(:is_navigational_format?).and_return(false)
allow_any_instance_of(described_class).to receive(:is_navigational_format?).and_return(false)
end
let(:email) { "madeup_email@test.com" }
@ -38,7 +38,7 @@ RSpec.describe Auth::PasswordsController, type: :request do
end
end
context "#Update - reset password" do
describe "#Update - reset password" do
let(:user) { FactoryBot.create(:user) }
let(:token) { user.send(:set_reset_password_token) }
let(:updated_password) { "updated_password_280" }

1
spec/requests/bulk_upload_controller_spec.rb

@ -4,6 +4,7 @@ RSpec.describe BulkUploadController, type: :request do
let(:url) { "/logs/bulk-upload" }
let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation }
before do
allow(Organisation).to receive(:find).with(107_242).and_return(organisation)
end

16
spec/requests/form_controller_spec.rb

@ -135,9 +135,15 @@ RSpec.describe FormController, type: :request do
context "valid answers" do
let(:answer) { 20 }
it "re-renders the same page with errors if validation fails" do
expect(response).to have_http_status(:redirect)
let(:params) do
{
id: case_log.id,
case_log: {
page: page_id,
age1: answer,
age2: 2000,
},
}
end
let(:params) do
@ -151,6 +157,10 @@ RSpec.describe FormController, type: :request do
}
end
it "re-renders the same page with errors if validation fails" do
expect(response).to have_http_status(:redirect)
end
it "only updates answers that apply to the page being submitted" do
case_log.reload
expect(case_log.age1).to eq(answer)

10
spec/requests/organisations_controller_spec.rb

@ -139,7 +139,7 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "#edit" do
describe "#edit" do
context "organisation that the user belongs to" do
before do
sign_in user
@ -165,7 +165,7 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "#update" do
describe "#update" do
context "organisation that the user belongs to" do
before do
sign_in user
@ -250,12 +250,12 @@ RSpec.describe OrganisationsController, type: :request do
get "/organisations/#{organisation.id}/users", headers: headers, params: {}
end
it "should return unauthorized 401" do
it "returns unauthorized 401" do
expect(response).to have_http_status(:unauthorized)
end
end
context "#edit" do
describe "#edit" do
before do
sign_in user
get "/organisations/#{organisation.id}/edit", headers: headers, params: {}
@ -266,7 +266,7 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "#update" do
describe "#update" do
before do
sign_in user
patch "/organisations/#{organisation.id}", headers: headers, params: params

4
spec/services/paas_configuration_service_spec.rb

@ -3,6 +3,7 @@ require "rails_helper"
RSpec.describe "PaasConfigurationService" do
context "when the paas configuration is unavailable" do
subject { PaasConfigurationService.new(logger) }
let(:logger) { double("logger") }
before { allow(logger).to receive(:warn) }
@ -22,6 +23,7 @@ RSpec.describe "PaasConfigurationService" do
context "when the paas configuration is present with S3 buckets" do
subject { PaasConfigurationService.new(double("logger")) }
let(:vcap_services) do
<<-JSON
{"aws-s3-bucket": [{"instance_name": "bucket_1"},{"instance_name": "bucket_2"}]}
@ -43,7 +45,7 @@ RSpec.describe "PaasConfigurationService" do
it "does retrieve the S3 bucket configurations" do
s3_buckets = subject.s3_buckets
expect(s3_buckets).to_not be_empty
expect(s3_buckets).not_to be_empty
expect(s3_buckets.count).to be(2)
expect(s3_buckets).to have_key(:bucket_1)
expect(s3_buckets).to have_key(:bucket_2)

4
spec/support/controller_macros.rb

@ -1,6 +1,6 @@
module ControllerMacros
def login_user
before(:each) do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryBot.create(:user)
sign_in user
@ -8,7 +8,7 @@ module ControllerMacros
end
def login_admin_user
before(:each) do
before do
@request.env["devise.mapping"] = Devise.mappings[:admin_user]
admin_user = FactoryBot.create(:admin_user)
sign_in admin_user

21
spec/views/case_log_index_view_spec.rb

@ -9,11 +9,14 @@ RSpec.describe "case_logs/index" do
let(:in_progress_log) { FactoryBot.create(:case_log, :in_progress) }
let(:completed_log) { FactoryBot.create(:case_log, :completed) }
context "given an in progress log list" do
it "renders a table for in progress logs only" do
context "with an in progress log list" do
before do
assign(:in_progress_case_logs, [in_progress_log])
assign(:completed_case_logs, [])
render
end
it "renders a table for in progress logs only" do
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you need to complete/)
expect(rendered).not_to match(/Logs you’ve submitted/)
@ -22,11 +25,14 @@ RSpec.describe "case_logs/index" do
end
end
context "given a completed log list" do
it "renders a table for in progress logs only" do
context "with a completed log list" do
before do
assign(:in_progress_case_logs, [])
assign(:completed_case_logs, [completed_log])
render
end
it "renders a table for in progress logs only" do
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you’ve submitted/)
expect(rendered).not_to match(/Logs you need to complete/)
@ -35,11 +41,14 @@ RSpec.describe "case_logs/index" do
end
end
context "given a completed log list and an in_progress log list" do
it "renders two tables, one for each status" do
context "with a completed log list and an in_progress log list" do
before do
assign(:in_progress_case_logs, [in_progress_log])
assign(:completed_case_logs, [completed_log])
render
end
it "renders two tables, one for each status" do
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you’ve submitted/)
expect(rendered).to match(/Logs you need to complete/)

6
spec/views/form/page_view_spec.rb

@ -80,6 +80,7 @@ RSpec.describe "form/page" do
context "with radio type" do
let(:question_attributes) { { type: "radio", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for radio questions" do
expect(rendered).to match(expected_guidance)
end
@ -87,6 +88,7 @@ RSpec.describe "form/page" do
context "with text type" do
let(:question_attributes) { { type: "text", answer_options: nil } }
it "renders the guidance partial for text questions" do
expect(rendered).to match(expected_guidance)
end
@ -94,6 +96,7 @@ RSpec.describe "form/page" do
context "with numeric type" do
let(:question_attributes) { { type: "numeric", answer_options: nil } }
it "renders the guidance partial for numeric questions" do
expect(rendered).to match(expected_guidance)
end
@ -101,6 +104,7 @@ RSpec.describe "form/page" do
context "with select type" do
let(:question_attributes) { { type: "select", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for select questions" do
expect(rendered).to match(expected_guidance)
end
@ -108,6 +112,7 @@ RSpec.describe "form/page" do
context "with checkbox type" do
let(:question_attributes) { { type: "checkbox", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for checkbox questions" do
expect(rendered).to match(expected_guidance)
end
@ -115,6 +120,7 @@ RSpec.describe "form/page" do
context "with date type" do
let(:question_attributes) { { type: "date", answer_options: nil } }
it "renders the guidance partial for date questions" do
expect(rendered).to match(expected_guidance)
end

Loading…
Cancel
Save