From f7db1669ff91779056e78664271fcf2cd2abb949 Mon Sep 17 00:00:00 2001 From: ivanELEC Date: Mon, 9 Sep 2024 15:19:32 +0100 Subject: [PATCH 1/2] fix task and add test --- lib/tasks/fixes.rake | 4 ++-- .../tasks/fix_mismatched_references_spec.rb | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 spec/lib/tasks/fix_mismatched_references_spec.rb diff --git a/lib/tasks/fixes.rake b/lib/tasks/fixes.rake index 3d11252bb..fa7ba1a41 100644 --- a/lib/tasks/fixes.rake +++ b/lib/tasks/fixes.rake @@ -39,8 +39,8 @@ namespace :fixes do ] records.each do |record| - id = record['submission_id'] - new_reference = record['laa_reference'] + id = record[:submission_id] + new_reference = record[:laa_reference] fix_laa_reference(id, new_reference) end end diff --git a/spec/lib/tasks/fix_mismatched_references_spec.rb b/spec/lib/tasks/fix_mismatched_references_spec.rb new file mode 100644 index 000000000..599bb7d14 --- /dev/null +++ b/spec/lib/tasks/fix_mismatched_references_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +describe 'fixes:mismatched_references:fix', type: :task do + let(:unmatched_application) { create(:prior_authority_application, id: '8db79c28-35fd-42ae-aef8-156fbe28631a', state: 'sent_back', laa_reference: 'LAA-ABCDEF') } + let(:records) do + [{submission_id: unmatched_application.id, laa_reference: 'LAA-Xcoqqz'}] + end + + before do + Rails.application.load_tasks if Rake::Task.tasks.empty? + end + + after do + Rake::Task['fixes:mismatched_references:fix'].reenable + end + + it 'prints out the correct information' do + # rubocop:disable Layout/LineLength + expected_output = "Fixed LAA Reference for Submission: #{unmatched_application.id}. Old Reference: #{unmatched_application.laa_reference}, New Reference: #{records.first[:laa_reference]}\n" + # rubocop:enable Layout/LineLength + expect { Rake::Task['fixes:mismatched_references:fix'].execute }.to output(expected_output).to_stdout + end +end From 4fa57d1531c3a3d52f2533551579a0708ab1ca82 Mon Sep 17 00:00:00 2001 From: ivanELEC Date: Mon, 9 Sep 2024 15:29:56 +0100 Subject: [PATCH 2/2] fix linting issues --- spec/lib/tasks/fix_mismatched_references_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/lib/tasks/fix_mismatched_references_spec.rb b/spec/lib/tasks/fix_mismatched_references_spec.rb index 599bb7d14..4050ed824 100644 --- a/spec/lib/tasks/fix_mismatched_references_spec.rb +++ b/spec/lib/tasks/fix_mismatched_references_spec.rb @@ -1,9 +1,12 @@ require 'rails_helper' describe 'fixes:mismatched_references:fix', type: :task do - let(:unmatched_application) { create(:prior_authority_application, id: '8db79c28-35fd-42ae-aef8-156fbe28631a', state: 'sent_back', laa_reference: 'LAA-ABCDEF') } + let(:unmatched_application) do + create(:prior_authority_application, id: '8db79c28-35fd-42ae-aef8-156fbe28631a', state: 'sent_back', + laa_reference: 'LAA-ABCDEF') + end let(:records) do - [{submission_id: unmatched_application.id, laa_reference: 'LAA-Xcoqqz'}] + [{ submission_id: unmatched_application.id, laa_reference: 'LAA-Xcoqqz' }] end before do