From b0777e4490b6aadcb6c5f9b74cc59bd8ca7d4e97 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 23 Feb 2024 08:30:18 +0100 Subject: [PATCH] Remove consent fields from QualificationRequests These are being replaced by the consent requests table so we can remove these fields. --- app/models/consent_request.rb | 27 +++++ app/models/qualification_request.rb | 69 +++--------- config/analytics.yml | 3 - ...ove_consent_from_qualification_requests.rb | 12 ++ db/schema.rb | 5 +- spec/factories/consent_requests.rb | 27 +++++ spec/factories/qualification_requests.rb | 63 +++-------- spec/models/consent_request_spec.rb | 27 +++++ spec/models/qualification_request_spec.rb | 106 +++--------------- 9 files changed, 144 insertions(+), 195 deletions(-) create mode 100644 db/migrate/20240223071958_remove_consent_from_qualification_requests.rb diff --git a/app/models/consent_request.rb b/app/models/consent_request.rb index 32ff570021..bc2fd40dcf 100644 --- a/app/models/consent_request.rb +++ b/app/models/consent_request.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# class ConsentRequest < ApplicationRecord ATTACHABLE_DOCUMENT_TYPES = %w[signed_consent unsigned_consent].freeze diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index fc32ba8ca5..3bc858577a 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -35,9 +32,6 @@ # fk_rails_... (qualification_id => qualifications.id) # class QualificationRequest < ApplicationRecord - ATTACHABLE_DOCUMENT_TYPES = %w[signed_consent unsigned_consent].freeze - - include Documentable include Requestable belongs_to :qualification @@ -50,21 +44,6 @@ class QualificationRequest < ApplicationRecord }, _prefix: true - scope :consent_method_signed, - -> do - consent_method_signed_ecctis.or(consent_method_signed_institution) - end - - scope :consent_requested, -> { where.not(consent_requested_at: nil) } - scope :consent_received, -> { where.not(consent_received_at: nil) } - scope :consent_respondable, - -> do - consent_requested - .where(consent_received_at: nil) - .joins(assessment: :application_form) - .merge(ApplicationForm.assessable) - end - scope :order_by_role, -> { joins(:qualification).order("qualifications.start_date": :desc) } scope :order_by_user, @@ -77,20 +56,4 @@ def expires_after def consent_method_signed? consent_method_signed_ecctis? || consent_method_signed_institution? end - - def consent_requested! - update!(consent_requested_at: Time.zone.now) - end - - def consent_requested? - consent_requested_at != nil - end - - def consent_received! - update!(consent_received_at: Time.zone.now) - end - - def consent_received? - consent_received_at != nil - end end diff --git a/config/analytics.yml b/config/analytics.yml index b61e96c43e..7a3a3d7115 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -223,8 +223,6 @@ :qualification_requests: - assessment_id - consent_method - - consent_received_at - - consent_requested_at - created_at - expired_at - id @@ -235,7 +233,6 @@ - review_note - review_passed - reviewed_at - - unsigned_consent_document_downloaded - updated_at - verified_at - verify_note diff --git a/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb b/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb new file mode 100644 index 0000000000..c5167167ac --- /dev/null +++ b/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb @@ -0,0 +1,12 @@ +class RemoveConsentFromQualificationRequests < ActiveRecord::Migration[7.1] + def change + change_table :qualification_requests, bulk: true do |t| + t.remove :consent_received_at, type: :datetime + t.remove :consent_requested_at, type: :datetime + t.remove :unsigned_consent_document_downloaded, + type: :boolean, + default: false, + null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c8538ae8c..9eb15d7fc1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_23_065851) do +ActiveRecord::Schema[7.1].define(version: 2024_02_23_071958) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -307,9 +307,6 @@ t.boolean "verify_passed" t.text "verify_note", default: "", null: false t.datetime "verified_at" - t.boolean "unsigned_consent_document_downloaded", default: false, null: false - t.datetime "consent_received_at" - t.datetime "consent_requested_at" t.string "consent_method", default: "unknown", null: false t.index ["assessment_id"], name: "index_qualification_requests_on_assessment_id" t.index ["qualification_id"], name: "index_qualification_requests_on_qualification_id" diff --git a/spec/factories/consent_requests.rb b/spec/factories/consent_requests.rb index c41b6017fe..be30784cfb 100644 --- a/spec/factories/consent_requests.rb +++ b/spec/factories/consent_requests.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# FactoryBot.define do factory :consent_request do association :assessment diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 067f2b5d2b..a2202af505 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -39,34 +36,8 @@ association :assessment association :qualification, :completed - trait :consent_required do + trait :consent_method_signed do consent_method { %i[signed_ecctis signed_institution].sample } - - after(:create) do |qualification_request, _evaluator| - create( - :upload, - document: qualification_request.unsigned_consent_document, - ) - end - end - - trait :consent_requested do - consent_required - consent_requested_at do - Faker::Time.between(from: 1.month.ago, to: Time.zone.now) - end - end - - trait :consent_received do - consent_requested - consent_received_at do - Faker::Time.between(from: 1.month.ago, to: Time.zone.now) - end - end - - trait :consent_expired do - consent_requested - expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :requested do diff --git a/spec/models/consent_request_spec.rb b/spec/models/consent_request_spec.rb index ee3a0abdb5..cae5cab76e 100644 --- a/spec/models/consent_request_spec.rb +++ b/spec/models/consent_request_spec.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# require "rails_helper" RSpec.describe ConsentRequest, type: :model do diff --git a/spec/models/qualification_request_spec.rb b/spec/models/qualification_request_spec.rb index e99ae97e22..fc4de5ed04 100644 --- a/spec/models/qualification_request_spec.rb +++ b/spec/models/qualification_request_spec.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -39,8 +36,6 @@ RSpec.describe QualificationRequest, type: :model do subject(:qualification_request) { create(:qualification_request) } - it_behaves_like "a documentable" - it_behaves_like "a requestable" do subject { create(:qualification_request, :receivable) } end @@ -60,9 +55,6 @@ end describe "validations" do - it { is_expected.to_not validate_presence_of(:consent_requested_at) } - it { is_expected.to_not validate_presence_of(:consent_received_at) } - context "when received" do subject { build(:qualification_request, :received) } @@ -70,72 +62,8 @@ end end - describe "#expires_from" do - subject(:expires_from) { qualification_request.expires_from } - - context "when consent has been requested" do - let(:qualification_request) do - create( - :qualification_request, - consent_requested_at: Date.new(2020, 1, 1), - ) - end - - it { is_expected.to eq(Date.new(2020, 1, 1)) } - end - - context "when verification has been requested" do - let(:qualification_request) do - create( - :qualification_request, - consent_requested_at: Date.new(2020, 1, 1), - requested_at: Date.new(2021, 1, 1), - ) - end - - it { is_expected.to eq(Date.new(2021, 1, 1)) } - end - end - describe "#expires_after" do subject(:expires_after) { qualification_request.expires_after } - - context "when consent has been requested" do - let(:qualification_request) do - create(:qualification_request, :consent_requested) - end - - it { is_expected.to eq(6.weeks) } - end - - context "when verification has been requested" do - let(:qualification_request) { create(:qualification_request, :requested) } - - it { is_expected.to eq(6.weeks) } - end - end - - describe "#consent_requested!" do - let(:call) { subject.consent_requested! } - - it "sets the consent requested at date" do - freeze_time do - expect { call }.to change(subject, :consent_requested_at).from(nil).to( - Time.zone.now, - ) - end - end - end - - describe "#consent_received!" do - let(:call) { subject.consent_received! } - - it "sets the consent received at date" do - freeze_time do - expect { call }.to change(subject, :consent_received_at).from(nil).to( - Time.zone.now, - ) - end - end + it { is_expected.to eq(6.weeks) } end end