diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8100d32f49..4491bb23a7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -44,25 +44,6 @@ RSpec/AnyInstance: - 'spec/services/reports/merits_report_creator_spec.rb' - 'spec/services/reports/mis/application_details_report_spec.rb' -# Offense count: 46 -RSpec/LetSetup: - Exclude: - - 'spec/forms/applicants/employed_form_spec.rb' - - 'spec/jobs/email_monitor_job_spec.rb' - - 'spec/jobs/scheduled_mailings_delivery_job_spec.rb' - - 'spec/presenters/applicant_account_presenter_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_additional_property_attributes_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_attributes_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_benefits_attrs_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_dependant_child_attributes_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_entities_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_variable_attributes_spec.rb' - - 'spec/services/ccms/requestors/case_add_requestor_xml_blocks/passported_attributes_spec.rb' - - 'spec/services/reports/merits_report_creator_spec.rb' - - 'spec/workers/bank_holiday_update_worker_spec.rb' - - 'spec/workers/true_layer_banks_update_worker_spec.rb' - # Offense count: 25 RSpec/StubbedMock: Exclude: diff --git a/spec/forms/applicants/employed_form_spec.rb b/spec/forms/applicants/employed_form_spec.rb index a25cd1019c..d91be02959 100644 --- a/spec/forms/applicants/employed_form_spec.rb +++ b/spec/forms/applicants/employed_form_spec.rb @@ -3,9 +3,7 @@ RSpec.describe Applicants::EmployedForm, type: :form do subject(:described_form) { described_class.new(form_params) } - let!(:application) { create(:legal_aid_application, applicant:) } let(:applicant) { create(:applicant, employed: nil) } - let(:params) { { employed: true } } let(:form_params) { params.merge(model: applicant) } diff --git a/spec/jobs/email_monitor_job_spec.rb b/spec/jobs/email_monitor_job_spec.rb index 583b9b726f..21e87750b0 100644 --- a/spec/jobs/email_monitor_job_spec.rb +++ b/spec/jobs/email_monitor_job_spec.rb @@ -2,10 +2,11 @@ RSpec.describe EmailMonitorJob do describe "perform" do - let!(:waiting) { create(:scheduled_mailing, :due) } - let!(:created) { create(:scheduled_mailing, :created) } - let!(:processing) { create(:scheduled_mailing, :processing) } - let!(:sending) { create(:scheduled_mailing, :sending) } + before { create(:scheduled_mailing, :due) } + + let(:created) { create(:scheduled_mailing, :created) } + let(:processing) { create(:scheduled_mailing, :processing) } + let(:sending) { create(:scheduled_mailing, :sending) } it "calls GovukEmails::Monitor for every scheduled mail record with a monitored status" do expect(GovukEmails::Monitor).to receive(:call).with(created.id) diff --git a/spec/jobs/scheduled_mailings_delivery_job_spec.rb b/spec/jobs/scheduled_mailings_delivery_job_spec.rb index fec0977a27..06526fcbf4 100644 --- a/spec/jobs/scheduled_mailings_delivery_job_spec.rb +++ b/spec/jobs/scheduled_mailings_delivery_job_spec.rb @@ -6,8 +6,8 @@ describe "ScheduledMailingsDeliveryJob" do let(:application) { create(:application, :with_everything) } - let!(:mailing_one) { create(:scheduled_mailing, :due, legal_aid_application_id: application.id) } - let!(:mailing_two) { create(:scheduled_mailing, :due_later) } + let(:mailing_one) { create(:scheduled_mailing, :due, legal_aid_application_id: application.id) } + let(:mailing_two) { create(:scheduled_mailing, :due_later) } describe "perform" do context "when calling DeliveryMan" do diff --git a/spec/presenters/applicant_account_presenter_spec.rb b/spec/presenters/applicant_account_presenter_spec.rb index 1c4c2ded62..a5772d4c7c 100644 --- a/spec/presenters/applicant_account_presenter_spec.rb +++ b/spec/presenters/applicant_account_presenter_spec.rb @@ -3,20 +3,19 @@ RSpec.describe ApplicantAccountPresenter do subject(:applicant_account_presenter) { described_class.new(applicant.bank_providers.first) } - let!(:applicant) { create(:applicant) } + let(:applicant) { create(:applicant) } let(:addresses) do [{ address: Faker::Address.building_number, city: Faker::Address.city, zip: Faker::Address.zip }] end - let!(:applicant_bank_provider) { create(:bank_provider, applicant_id: applicant.id) } + let(:applicant_bank_provider) { create(:bank_provider, applicant_id: applicant.id) } let!(:applicant_bank_account_holder) do - create(:bank_account_holder, bank_provider_id: applicant_bank_provider.id, - addresses:) + create(:bank_account_holder, bank_provider_id: applicant_bank_provider.id, addresses:) end - let!(:applicant_bank_account) do + let(:applicant_bank_account) do create(:bank_account, bank_provider_id: applicant_bank_provider.id, currency: "GBP") end diff --git a/spec/services/ccms/requestors/case_add_requestor_spec.rb b/spec/services/ccms/requestors/case_add_requestor_spec.rb index 80eee25bbf..2583da638e 100644 --- a/spec/services/ccms/requestors/case_add_requestor_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_spec.rb @@ -33,10 +33,7 @@ module Requestors end let(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end + let(:chances_of_success) { proceeding.chances_of_success } let(:vehicles) { create_list(:vehicle, 1, estimated_value: 3030, payment_remaining: 881, purchased_on: Date.new(2008, 8, 22), used_regularly: true) } let(:domestic_abuse_summary) { create(:domestic_abuse_summary, :police_notified_true) } @@ -57,18 +54,22 @@ module Requestors let(:opponents) { create_list(:opponent, 1, first_name: "Joffrey", last_name: "Test-Opponent") } let(:submission) { create(:submission, :case_ref_obtained, case_ccms_reference: "300000000001", legal_aid_application:) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } + let(:cfe_result) { cfe_submission.cfe_result } let(:office) { create(:office, ccms_id: "4727432767") } let(:savings_amount) { create(:savings_amount, :all_nil) } let(:requestor) { described_class.new(submission, {}) } - let!(:involved_child1) { create(:involved_child, full_name: "First TestChild", date_of_birth: Date.parse("2019-01-20"), legal_aid_application:) } - let!(:involved_child2) { create(:involved_child, full_name: "Second TestChild", date_of_birth: Date.parse("2020-02-15"), legal_aid_application:) } + let(:involved_child1) { legal_aid_application.reload.involved_children.find_by(first_name: "First", last_name: "TestChild") } + let(:involved_child2) { legal_aid_application.reload.involved_children.find_by(first_name: "Second", last_name: "TestChild") } let(:request_xml) { requestor.__send__(:request_xml) } let(:expected_request_xml) { ccms_data_from_file("case_add_request.xml") } let(:request_created_at) { Time.zone.parse("2020-11-24T11:54:29.000") } before do + create(:cfe_v3_result, submission: cfe_submission) + create(:chances_of_success, :with_optional_text, proceeding:) + create(:involved_child, full_name: "First TestChild", date_of_birth: Date.parse("2019-01-20"), legal_aid_application:) + create(:involved_child, full_name: "Second TestChild", date_of_birth: Date.parse("2020-02-15"), legal_aid_application:) legal_aid_application.reload legal_aid_application.update!(opponents:) allow(Rails.configuration.x.ccms_soa).to receive(:client_username).and_return("FakeUser") diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_additional_property_attributes_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_additional_property_attributes_spec.rb index a1ea43767a..badfe366d3 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_additional_property_attributes_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_additional_property_attributes_spec.rb @@ -29,17 +29,17 @@ module Requestors end let(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end - let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } + before do + create(:chances_of_success, :with_optional_text, proceeding:) + create(:cfe_v3_result, submission: cfe_submission) + end + it "generates the expected block for each of the hard coded attrs" do hard_coded_attrs.each do |attr| entity, attr_name, type, user_defined, value = attr diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_attributes_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_attributes_spec.rb index 958c857f50..30159c9800 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_attributes_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_attributes_spec.rb @@ -31,14 +31,10 @@ module Requestors end let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end let(:opponent) { legal_aid_application.opponent } let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let(:success_prospect) { :likely } @@ -46,6 +42,11 @@ module Requestors let(:applicant) { legal_aid_application.applicant } let(:default_cost) { legal_aid_application.lead_proceeding.substantive_cost_limitation } + before do + create(:chances_of_success, :with_optional_text, proceeding:) + create(:cfe_v3_result, submission: cfe_submission) + end + # uncomment this example to create a file of the payload for manual inspection # it 'create example payload file' do # filename = Rails.root.join('tmp/generated_non_means_tested_ccms_payload.xml') diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_benefits_attrs_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_benefits_attrs_spec.rb index 62497f868b..c5d376eb5b 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_benefits_attrs_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_benefits_attrs_spec.rb @@ -29,17 +29,18 @@ module Requestors office:) end let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let(:applicant) { legal_aid_application.applicant } + before do + create(:chances_of_success, :with_optional_text, proceeding:) + create(:cfe_v3_result, submission: cfe_submission) + end + describe "boolean attributes" do # these are all currently coded as FALSE until such time as we can determine which benefits are received it "generates the attribute blocks as false" do diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_dependant_child_attributes_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_dependant_child_attributes_spec.rb index ee46c03e76..8a19b63688 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_dependant_child_attributes_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_dependant_child_attributes_spec.rb @@ -20,11 +20,15 @@ module Requestors let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let(:dependants) { legal_aid_application.dependants.all } + before do + create(:chances_of_success, :with_optional_text, proceeding:) + create(:cfe_v3_result, submission: cfe_submission) + end + describe "non-passported" do let(:legal_aid_application) do create(:legal_aid_application, @@ -37,10 +41,7 @@ module Requestors provider:, office:) end - let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end + let(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } context "with dependant children" do let!(:younger_child) { create(:dependant, :under15, legal_aid_application:, number: 1, has_income: false, assets_value: 1_000) } diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_entities_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_entities_spec.rb index 61b145b9f3..64d43fa2f6 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_entities_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_entities_spec.rb @@ -30,18 +30,16 @@ module Requestors end let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA001" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding:) - end let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let(:success_prospect) { :likely } before do + create(:chances_of_success, :with_optional_text, proceeding:) + create(:cfe_v3_result, submission: cfe_submission) legal_aid_application.reload end @@ -193,7 +191,8 @@ module Requestors let(:applicant) { legal_aid_application.applicant } let(:bank_provider) { create(:bank_provider, applicant:) } let(:bank_account) { create(:bank_account, bank_provider:) } - let!(:bank_transactions) { create_list(:bank_transaction, 2, :friends_or_family, bank_account:) } + + before { create_list(:bank_transaction, 2, :friends_or_family, bank_account:) } it "generate the entity" do expect(xml).to have_means_entity "CLIENT_FINANCIAL_SUPPORT" diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_variable_attributes_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_variable_attributes_spec.rb index 0ec382350a..250b0abaa9 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_variable_attributes_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/non_passported_variable_attributes_spec.rb @@ -37,13 +37,16 @@ module Requestors let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } + let(:cfe_result) { cfe_submission.cfe_result } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let(:applicant) { legal_aid_application.applicant } let(:percentage_home) { rand(1...99.0).round(2) } - before { legal_aid_application.reload } + before do + create(:cfe_v3_result, submission: cfe_submission) + legal_aid_application.reload + end describe "family prospects" do context "when they are 50% or better" do @@ -487,7 +490,7 @@ module Requestors let(:benefits) { create(:transaction_type, :credit, name: "benefits") } let(:bank_account) { create(:bank_account, bank_provider:) } let(:bank_provider) { create(:bank_provider, applicant:) } - let!(:benefits_bank_transaction) { create(:bank_transaction, :credit, transaction_type: benefits, bank_account:) } + let(:benefits_bank_transaction) { create(:bank_transaction, :credit, transaction_type: benefits, bank_account:) } let(:applicant) { create(:applicant, :with_address) } let(:legal_aid_application) do create(:legal_aid_application, @@ -567,7 +570,10 @@ module Requestors subject(:block) { XmlExtractor.call(xml, :global_means, attribute) } describe "are received by the applicant" do - let!(:cfe_result) { create(:cfe_v3_result, :with_maintenance_received, submission: cfe_submission) } + before do + cfe_submission.result.destroy! + create(:cfe_v3_result, :with_maintenance_received, submission: cfe_submission) + end describe "GB_INPUT_C_8WP3_303A" do let(:attribute) { "GB_INPUT_C_8WP3_303A" } @@ -656,13 +662,14 @@ module Requestors describe "GB_INPUT_C_13WP3_3A" do context "when the applicant pays a mortgage" do - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } - let(:rent_or_mortgage_payment) { create(:transaction_type, :debit, name: "rent_or_mortgage") } - before do + cfe_submission.result.destroy! + create(:cfe_v3_result, submission: cfe_submission) create(:legal_aid_application_transaction_type, legal_aid_application:, transaction_type: rent_or_mortgage_payment) end + let(:rent_or_mortgage_payment) { create(:transaction_type, :debit, name: "rent_or_mortgage") } + it "does generate the block" do block = XmlExtractor.call(xml, :global_means, "GB_INPUT_C_13WP3_3A") expect(block).to have_currency_response 125.00 @@ -682,7 +689,10 @@ module Requestors describe "PUI_CLIENT_INCOME_CONT" do context "when the applicant has to make an income contribution" do - let!(:cfe_result) { create(:cfe_v3_result, :with_income_contribution_required, submission: cfe_submission) } + before do + cfe_submission.result.destroy! + create(:cfe_v3_result, :with_income_contribution_required, submission: cfe_submission) + end it "returns the expected values" do block = XmlExtractor.call(xml, :global_means, "PUI_CLIENT_INCOME_CONT") @@ -702,7 +712,10 @@ module Requestors describe "OUT_INCOME_CONT" do context "when the applicant has to make an income contribution" do - let!(:cfe_result) { create(:cfe_v3_result, :with_income_contribution_required, submission: cfe_submission) } + before do + cfe_submission.result.destroy! + create(:cfe_v3_result, :with_income_contribution_required, submission: cfe_submission) + end it "returns the expected values" do block = XmlExtractor.call(xml, :global_means, "OUT_INCOME_CONT") @@ -863,7 +876,7 @@ module Requestors subject(:block) { XmlExtractor.call(xml, :global_means, attribute) } let(:true_false) { [true, false] } - let!(:percentage_home) { example[:input] } + let(:percentage_home) { example[:input] } it "returns #{test[:result]} when percentage_home is set to #{test[:input]}" do if test[:omit_block] diff --git a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/passported_attributes_spec.rb b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/passported_attributes_spec.rb index 243bcbad47..d12413c6f4 100644 --- a/spec/services/ccms/requestors/case_add_requestor_xml_blocks/passported_attributes_spec.rb +++ b/spec/services/ccms/requestors/case_add_requestor_xml_blocks/passported_attributes_spec.rb @@ -34,16 +34,13 @@ module Requestors let(:ccms_reference) { "300000054005" } let(:submission) { create(:submission, :case_ref_obtained, legal_aid_application:, case_ccms_reference: ccms_reference) } let(:cfe_submission) { create(:cfe_submission, legal_aid_application:) } - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } let(:requestor) { described_class.new(submission, {}) } let(:xml) { requestor.formatted_xml } let!(:success_prospect) { :likely } - let!(:chances_of_success) do - create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding:) - end - before do + create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding:) + create(:cfe_v3_result, submission: cfe_submission) allow_any_instance_of(Proceeding).to receive(:proceeding_case_id).and_return(55_000_001) end @@ -116,7 +113,7 @@ module Requestors describe "CLIENT_ELIGIBILITY and PUI_CLIENT_ELIGIBILITY" do context "when the cfe result is eligible" do - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } + let(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } it "returns In Scope" do block = XmlExtractor.call(xml, :global_means, "CLIENT_ELIGIBILITY") @@ -127,7 +124,10 @@ module Requestors end context "when the cfe result is not_eligible" do - let!(:cfe_result) { create(:cfe_v3_result, :not_eligible, submission: cfe_submission) } + before do + cfe_submission.result.destroy! + create(:cfe_v3_result, :not_eligible, submission: cfe_submission) + end it "returns Out Of Scope" do block = XmlExtractor.call(xml, :global_means, "CLIENT_ELIGIBILITY") @@ -138,7 +138,7 @@ module Requestors end context "when the cfe result is contribution_required" do - let!(:cfe_result) { create(:cfe_v3_result, :with_capital_contribution_required, submission: cfe_submission) } + let(:cfe_result) { create(:cfe_v3_result, :with_capital_contribution_required, submission: cfe_submission) } it "returns In Scope" do block = XmlExtractor.call(xml, :global_means, "CLIENT_ELIGIBILITY") @@ -149,7 +149,8 @@ module Requestors end context "when the cfe result has an invalid response" do - let!(:cfe_result) do + before do + cfe_submission.result.destroy! create(:cfe_v3_result, :with_unknown_result, submission: cfe_submission) @@ -172,7 +173,7 @@ module Requestors let(:attributes) { %w[PUI_CLIENT_CAP_CONT CAP_CONT OUT_CAP_CONT] } context "when the cfe result is eligble" do - let!(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } + let(:cfe_result) { create(:cfe_v3_result, submission: cfe_submission) } it "returns zero" do attributes.each do |attribute| @@ -183,7 +184,7 @@ module Requestors end context "when the cfe result is not eligible" do - let!(:cfe_result) { create(:cfe_v3_result, :not_eligible, submission: cfe_submission) } + let(:cfe_result) { create(:cfe_v3_result, :not_eligible, submission: cfe_submission) } it "returns zero" do attributes.each do |attribute| @@ -196,7 +197,10 @@ module Requestors end context "when the cfe result is contribution_required" do - let!(:cfe_result) { create(:cfe_v3_result, :with_capital_contribution_required, submission: cfe_submission) } + before do + cfe_submission.result.destroy! + create(:cfe_v3_result, :with_capital_contribution_required, submission: cfe_submission) + end it "returns the capital contribution" do attributes.each do |attribute| @@ -816,7 +820,7 @@ module Requestors provider:, office:) end - let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } + let(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } it "returns SUBDP" do %i[global_means global_merits].each do |entity| @@ -853,9 +857,9 @@ module Requestors provider:, office:) end - let!(:da004) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding: da004) + let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } + let(:chances_of_success) do + create(:chances_of_success, :with_optional_text, proceeding:) end it "returns hard coded statement" do @@ -1429,9 +1433,9 @@ module Requestors provider:, office:) end - let(:proceeding_da004) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } - let!(:chances_of_success) do - create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding: proceeding_da004) + let(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } + let(:chances_of_success) do + create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding:) end it "returns false" do @@ -1463,9 +1467,9 @@ module Requestors provider:, office:) end - let!(:proceeding_da004) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } - let!(:chances_of_success) do - create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding: proceeding_da004) + let!(:proceeding) { legal_aid_application.proceedings.detect { |p| p.ccms_code == "DA004" } } + let(:chances_of_success) do + create(:chances_of_success, success_prospect:, success_prospect_details: "details", proceeding:) end it "returns Both" do diff --git a/spec/services/reports/merits_report_creator_spec.rb b/spec/services/reports/merits_report_creator_spec.rb index 0a19f2f2ba..b18823c3da 100644 --- a/spec/services/reports/merits_report_creator_spec.rb +++ b/spec/services/reports/merits_report_creator_spec.rb @@ -18,13 +18,13 @@ ccms_submission:) end let(:da001) { legal_aid_application.proceedings.find_by(ccms_code: "DA001") } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding: da001) - end let(:ccms_submission) { create(:ccms_submission, :case_ref_obtained) } let(:smtl) { create(:legal_framework_merits_task_list, :da001, legal_aid_application:) } - before { allow(LegalFramework::MeritsTasksService).to receive(:call).with(legal_aid_application).and_return(smtl) } + before do + create(:chances_of_success, :with_optional_text, proceeding: da001) + allow(LegalFramework::MeritsTasksService).to receive(:call).with(legal_aid_application).and_return(smtl) + end describe ".call" do it "attaches merits_report.pdf to the application" do @@ -76,13 +76,10 @@ end let(:da001) { legal_aid_application.proceedings.find_by(ccms_code: "DA001") } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding: da001) - end - let(:ccms_submission) { create(:ccms_submission) } before do + create(:chances_of_success, :with_optional_text, proceeding: da001) allow_any_instance_of(CCMS::Submission).to receive(:process!).with(any_args).and_return(true) end @@ -103,11 +100,9 @@ let(:ccms_submission) { create(:ccms_submission) } let(:da001) { legal_aid_application.proceedings.find_by(ccms_code: "DA001") } - let!(:chances_of_success) do - create(:chances_of_success, :with_optional_text, proceeding: da001) - end before do + create(:chances_of_success, :with_optional_text, proceeding: da001) allow(legal_aid_application).to receive(:case_ccms_reference).and_return(nil) allow(legal_aid_application).to receive(:create_ccms_submission).and_return(ccms_submission) end diff --git a/spec/workers/bank_holiday_update_worker_spec.rb b/spec/workers/bank_holiday_update_worker_spec.rb index 8c1939b4b9..7745aa19e8 100644 --- a/spec/workers/bank_holiday_update_worker_spec.rb +++ b/spec/workers/bank_holiday_update_worker_spec.rb @@ -5,22 +5,25 @@ let(:bank_holiday_update_worker) { described_class.new } let(:stale_date) { Time.current.utc - described_class::UPDATE_INTERVAL - 2.hours } - let!(:bank_holiday) { create(:bank_holiday) } - it "returns true" do - expect(update_worker).to be true - end + context "when it is current" do + before { create(:bank_holiday) } - it "does not change the bank holiday" do - expect { update_worker }.not_to change(bank_holiday, :reload) - end + it "returns true" do + expect(update_worker).to be true + end + + it "does not change the bank holiday" do + expect { update_worker }.not_to change(BankHoliday.first, :reload) + end - it "does not create a new bank holiday" do - expect { update_worker }.not_to change(BankHoliday, :count) + it "does not create a new bank holiday" do + expect { update_worker }.not_to change(BankHoliday, :count) + end end context "when outdated" do - let!(:bank_holiday) { create(:bank_holiday, updated_at: stale_date) } + before { create(:bank_holiday, updated_at: stale_date) } it "creates a new bank holiday instance" do expect { update_worker }.to change(BankHoliday, :count).by(1) @@ -41,7 +44,7 @@ end context "when data retrieval fails" do - let!(:bank_holiday) { create(:bank_holiday, updated_at: stale_date) } + before { create(:bank_holiday, updated_at: stale_date) } it "raises error" do allow(BankHolidayRetriever).to receive(:dates).and_raise(BankHolidayRetriever::UnsuccessfulRetrievalError) diff --git a/spec/workers/true_layer_banks_update_worker_spec.rb b/spec/workers/true_layer_banks_update_worker_spec.rb index 85fbe0e940..1b496d1c80 100644 --- a/spec/workers/true_layer_banks_update_worker_spec.rb +++ b/spec/workers/true_layer_banks_update_worker_spec.rb @@ -20,7 +20,7 @@ end context "when outdated" do - let!(:true_layer_bank) { create(:true_layer_bank, updated_at: stale_date) } + let(:true_layer_bank) { create(:true_layer_bank, updated_at: stale_date) } it "creates a new bank holiday instance" do expect { update_worker }.to change(TrueLayerBank, :count).by(1) @@ -41,7 +41,7 @@ end context "when data retrieval fails" do - let!(:true_layer_bank) { create(:true_layer_bank, updated_at: stale_date) } + let(:true_layer_bank) { create(:true_layer_bank, updated_at: stale_date) } it "raises error" do allow(TrueLayer::BanksRetriever).to receive(:banks).and_raise(TrueLayer::BanksRetriever::UnsuccessfulRetrievalError)