diff --git a/.rubocop.yml b/.rubocop.yml index 98ffdff78..a291787aa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ require: - rubocop-performance - rubocop-rails + - rubocop-rspec inherit_gem: rubocop-govuk: diff --git a/spec/controllers/admin/admin_users_controller_spec.rb b/spec/controllers/admin/admin_users_controller_spec.rb index 6be860042..abe805c5a 100644 --- a/spec/controllers/admin/admin_users_controller_spec.rb +++ b/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 diff --git a/spec/controllers/admin/case_logs_controller_spec.rb b/spec/controllers/admin/case_logs_controller_spec.rb index 13684951c..7a27443a1 100644 --- a/spec/controllers/admin/case_logs_controller_spec.rb +++ b/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 diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 8bf8652d2..8d6712e7b 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/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 diff --git a/spec/controllers/admin/organisations_controller_spec.rb b/spec/controllers/admin/organisations_controller_spec.rb index 2afa99b44..f13be1259 100644 --- a/spec/controllers/admin/organisations_controller_spec.rb +++ b/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 diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index bad96a9e6..ba15645bd 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/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 diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 6dff43960..1e5bb333f 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/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 diff --git a/spec/features/test_spec.rb b/spec/features/test_spec.rb index 556d72a52..ef54fa631 100644 --- a/spec/features/test_spec.rb +++ b/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 diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 085a41e5b..cdbb30f2d 100644 --- a/spec/features/user_spec.rb +++ b/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") diff --git a/spec/helpers/conditional_questions_helper_spec.rb b/spec/helpers/conditional_questions_helper_spec.rb index b3df41a43..be1032fc3 100644 --- a/spec/helpers/conditional_questions_helper_spec.rb +++ b/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 diff --git a/spec/helpers/question_attribute_helper_spec.rb b/spec/helpers/question_attribute_helper_spec.rb index db3d60b84..45269ac40 100644 --- a/spec/helpers/question_attribute_helper_spec.rb +++ b/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 diff --git a/spec/helpers/question_view_helper.rb b/spec/helpers/question_view_helper.rb index f34062a0d..9a560b5c8 100644 --- a/spec/helpers/question_view_helper.rb +++ b/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 diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index ad68dd1a1..8d2d0fe45 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/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) diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 684097768..728b19c3a 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/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) } diff --git a/spec/lib/tasks/data_import/organisations_spec.rb b/spec/lib/tasks/data_import/organisations_spec.rb index a7c359dae..34a1a6b4c 100644 --- a/spec/lib/tasks/data_import/organisations_spec.rb +++ b/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 diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index bd5ad8c23..4e929451a 100644 --- a/spec/models/case_log_spec.rb +++ b/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 diff --git a/spec/models/form/page_spec.rb b/spec/models/form/page_spec.rb index ea0cb2860..03081e9d0 100644 --- a/spec/models/form/page_spec.rb +++ b/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) diff --git a/spec/models/form/question_spec.rb b/spec/models/form/question_spec.rb index 2be973ddb..423e678e1 100644 --- a/spec/models/form/question_spec.rb +++ b/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) diff --git a/spec/models/form/section_spec.rb b/spec/models/form/section_spec.rb index da63c68e2..db249a253 100644 --- a/spec/models/form/section_spec.rb +++ b/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) diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index cd7ebc9f3..471070e73 100644 --- a/spec/models/form/subsection_spec.rb +++ b/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" diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 5d2d6843b..5a1df80fb 100644 --- a/spec/models/form_handler_spec.rb +++ b/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 diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 3c28daf89..25a04036d 100644 --- a/spec/models/form_spec.rb +++ b/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 diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 99a7cab96..a7e76d3a2 100644 --- a/spec/models/organisation_spec.rb +++ b/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 } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1c65f597e..f24280a5c 100644 --- a/spec/models/user_spec.rb +++ b/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) } diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index d6e6d0328..d5cb1b59b 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/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 diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 4b85bfb74..d84dfecb0 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/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 diff --git a/spec/presenters/error_summary_full_messages_presenter_spec.rb b/spec/presenters/error_summary_full_messages_presenter_spec.rb index 4d88e9c5c..ab352e743 100644 --- a/spec/presenters/error_summary_full_messages_presenter_spec.rb +++ b/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) diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 615455d83..72144e879 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/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" } diff --git a/spec/requests/bulk_upload_controller_spec.rb b/spec/requests/bulk_upload_controller_spec.rb index 608571cbd..f7ef0ae43 100644 --- a/spec/requests/bulk_upload_controller_spec.rb +++ b/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 diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 40293a321..8aac8b440 100644 --- a/spec/requests/form_controller_spec.rb +++ b/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) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index c15845c9b..a8547d520 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/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 diff --git a/spec/services/paas_configuration_service_spec.rb b/spec/services/paas_configuration_service_spec.rb index d67b1ad45..471ef6729 100644 --- a/spec/services/paas_configuration_service_spec.rb +++ b/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) diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index 813af85f1..2e21831dd 100644 --- a/spec/support/controller_macros.rb +++ b/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 diff --git a/spec/views/case_log_index_view_spec.rb b/spec/views/case_log_index_view_spec.rb index 63f7dd29b..ba12c059d 100644 --- a/spec/views/case_log_index_view_spec.rb +++ b/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(/