Skip to content

Commit

Permalink
Rubocop: Address let! usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbruce committed Nov 8, 2023
1 parent a251407 commit 6422707
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 118 deletions.
19 changes: 0 additions & 19 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions spec/forms/applicants/employed_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
9 changes: 5 additions & 4 deletions spec/jobs/email_monitor_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/scheduled_mailings_delivery_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions spec/presenters/applicant_account_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions spec/services/ccms/requestors/case_add_requestor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ 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 }
let(:timestamp) { Time.current.strftime("%Y-%m-%d_%H.%M") }
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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]
Expand Down
Loading

0 comments on commit 6422707

Please sign in to comment.