Test Setup Failed
Push — master ( c4da73...8c2db5 )
by Steven
01:54 queued 21s
created

Participant   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 22
rs 10
wmc 3
1
# frozen_string_literal: true
2
3
# Model to represent survey participants
4
class Participant < ApplicationRecord
5
  belongs_to :user, optional: true
6
  validates :email, presence: true, 'valid_email_2/email': true
7
  has_one :journal, inverse_of: :participant, dependent: :destroy
8
  has_many :survey_participants, inverse_of: :participant, dependent: :destroy
9
  has_many :surveys, through: :survey_participants
10
  has_many :study_participants, inverse_of: :participant, dependent: :destroy
11
  has_many :studies, through: :study_participants
12
  validates :journal, presence: true
13
14
  after_initialize :create_journal
15
16
  def to_s
17
    "#{identifier} #{email}".strip
18
  end
19
20
  private 
21
  
22
  def create_journal
23
    self.journal ||= Journal.new(participant: self, name: Time.now.to_s) if new_record?
24
  end
25
end
26