-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathplans.rb
More file actions
106 lines (98 loc) · 3.24 KB
/
Copy pathplans.rb
File metadata and controls
106 lines (98 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true
# == Schema Information
#
# Table name: plans
#
# id :integer not null, primary key
# complete :boolean default(FALSE)
# description :text
# ethical_issues :boolean
# ethical_issues_description :text
# ethical_issues_report :string
# feedback_requested :boolean default(FALSE)
# funding_status :integer
# identifier :string
# title :string
# visibility :integer default(3), not null
# created_at :datetime
# updated_at :datetime
# template_id :integer
# org_id :integer
# funder_id :integer
# grant_id :integer
# api_client_id :integer
# research_domain_id :bigint
#
# Indexes
#
# index_plans_on_template_id (template_id)
# index_plans_on_funder_id (funder_id)
# index_plans_on_grant_id (grant_id)
# index_plans_on_api_client_id (api_client_id)
#
# Foreign Keys
#
# fk_rails_... (template_id => templates.id)
# fk_rails_... (org_id => orgs.id)
# fk_rails_... (api_client_id => api_clients.id)
# fk_rails_... (research_domain_id => research_domains.id)
#
FactoryBot.define do
factory :plan do
title { Faker::Company.bs }
visibility { Plan.visibilities[:privately_visible] }
template
org
identifier { SecureRandom.hex }
description { Faker::Lorem.paragraph }
feedback_requested { false }
complete { false }
start_date { Time.now }
end_date { start_date + 2.years }
ethical_issues { [true, false].sample }
ethical_issues_description { Faker::Lorem.paragraph }
ethical_issues_report { Faker::Internet.url }
funding_status { Plan.funding_statuses.keys.sample }
transient do
phases { 0 }
answers { 0 }
guidance_groups { 0 }
end
trait :creator do
after(:create) do |plan|
plan.roles << create(:role, :creator, user: create(:user, org: create(:org)), plan: plan)
end
end
trait :commenter do
after(:create) do |plan|
plan.roles << create(:role, :commenter, user: create(:user, org: create(:org)), plan: plan)
end
end
trait :organisationally_visible do
after(:create) do |plan|
plan.update(visibility: Plan.visibilities[:organisationally_visible])
end
end
trait :publicly_visible do
after(:create) do |plan|
plan.update(visibility: Plan.visibilities[:publicly_visible])
end
end
trait :is_test do
after(:create) do |plan|
plan.update(visibility: Plan.visibilities[:is_test])
end
end
trait :privately_visible do
after(:create) do |plan|
plan.update(visibility: Plan.visibilities[:privately_visible])
end
end
after(:create) do |plan, evaluator|
create_list(:answer, evaluator.answers, plan: plan)
end
after(:create) do |plan, evaluator|
plan.guidance_groups << create_list(:guidance_group, evaluator.guidance_groups)
end
end
end