Skip to content

Commit

Permalink
Remove consent fields from QualificationRequests
Browse files Browse the repository at this point in the history
These are being replaced by the consent requests table so we can remove
these fields.
  • Loading branch information
thomasleese committed Feb 23, 2024
1 parent 2d27e42 commit b0777e4
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 195 deletions.
27 changes: 27 additions & 0 deletions app/models/consent_request.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
69 changes: 16 additions & 53 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
3 changes: 0 additions & 3 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@
:qualification_requests:
- assessment_id
- consent_method
- consent_received_at
- consent_requested_at
- created_at
- expired_at
- id
Expand All @@ -235,7 +233,6 @@
- review_note
- review_passed
- reviewed_at
- unsigned_consent_document_downloaded
- updated_at
- verified_at
- verify_note
Expand Down
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions spec/factories/consent_requests.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 17 additions & 46 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions spec/models/consent_request_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit b0777e4

Please sign in to comment.