Repository URL to install this package:
|
Version:
7.3.3 ▾
|
# frozen_string_literal: true
require_relative 'database_helper'
require_relative 'fluent_helper'
module Faculty
# Spec helper module for creating module records for spec testing
module FluentModuleHelper
# Class for tracking state of a fluent module specification
class FluentModuleRecord < FluentHelper
def initialize(**params)
super()
maybe_insert dbt.sits.department, code: params[:department_code] if params.key? :department_code
@module = insert(dbt.sits.module_occurrence, params)
end
def with_period(**params)
maybe_add_period(**period_defaults, **params)
insert dbt.sits.module_period, params, **period_defaults
self
end
private
def maybe_add_period(**params)
check_fields = { academic_year: params[:academic_year], period_code: params[:period_code] }
extra_fields = { period_key: "#{params[:academic_year]}-#{params[:period_code]}",
period_dates: Sequel::Postgres::PGRange.from_range(Date.new(2022)..Date.new(2022, 2)) }
insert(dbt.sits.period, check_fields.merge(extra_fields)) unless dbt.sits.period.include?(**check_fields)
end
def period_defaults
{ module_occurrence_id: @module[:module_occurrence_id], academic_year: @module[:start_academic_year],
mav_key: @module[:mav_key], period_code: 'T1' }
end
end
def sits_module(...)
FluentModuleRecord.new(...)
end
end
end