Module: UatActions::StaticRecords

Defined in:
app/uat_actions/uat_actions/static_records.rb

Overview

Provides simple consistent records where multiple records are not needed.

Constant Summary collapse

SWIPECARD_CODE =

Swipecard code of the test user. It gets hashed when persisted to the database, so we store it as a constant here to allow us to access it in the integration suite tools.

'__uat_test__'

Class Method Summary collapse

Class Method Details

.budget_divisionObject


48
49
50
# File 'app/uat_actions/uat_actions/static_records.rb', line 48

def self.budget_division
  BudgetDivision.find_or_create_by!(name: 'UAT TESTING')
end

.data_release_study_typeObject


32
33
34
# File 'app/uat_actions/uat_actions/static_records.rb', line 32

def self.data_release_study_type
  DataReleaseStudyType.default || DataReleaseStudyType.find_or_create_by(name: 'UAT')
end

.faculty_sponsorObject


65
66
67
# File 'app/uat_actions/uat_actions/static_records.rb', line 65

def self.faculty_sponsor
  FacultySponsor.find_or_create_by!(name: 'UAT Faculty Sponsor')
end

.programObject


52
53
54
# File 'app/uat_actions/uat_actions/static_records.rb', line 52

def self.program
  Program.find_or_create_by!(name: 'UAT')
end

.projectObject


36
37
38
39
40
41
42
43
44
45
46
# File 'app/uat_actions/uat_actions/static_records.rb', line 36

def self.project
  Project.create_with(
    approved: true,
    state: 'active',
    project_metadata_attributes: {
      project_cost_code: 'FAKE1',
      project_funding_model: 'Internal',
      budget_division: budget_division
    }
  ).find_or_create_by!(name: 'UAT Project')
end

.studyObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/uat_actions/uat_actions/static_records.rb', line 10

def self.study
  Study.create_with(
    state: 'active',
    study_metadata_attributes: {
      data_access_group: 'dag',
      study_type: study_type,
      faculty_sponsor: faculty_sponsor,
      data_release_study_type: data_release_study_type,
      study_description: 'A study generated for UAT',
      contaminated_human_dna: 'No',
      contains_human_dna: 'No',
      commercially_available: 'No',
      program: program
    }
  ).find_or_create_by!(name: 'UAT Study')
end

.study_typeObject


27
28
29
30
# File 'app/uat_actions/uat_actions/static_records.rb', line 27

def self.study_type
  StudyType.create_with(valid_type: true, valid_for_creation: true)
           .find_or_create_by!(name: 'UAT')
end

.userObject


56
57
58
59
60
61
62
63
# File 'app/uat_actions/uat_actions/static_records.rb', line 56

def self.user
  User.create_with(
    email: configatron.admin_email,
    first_name: 'Test',
    last_name: 'User',
    swipecard_code: SWIPECARD_CODE
  ).find_or_create_by(login: '__uat_test__')
end