diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/checkpoint.rb | 2 | ||||
-rw-r--r-- | app/models/run.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/app/models/checkpoint.rb b/app/models/checkpoint.rb index c014b2e..9cdb774 100644 --- a/app/models/checkpoint.rb +++ b/app/models/checkpoint.rb @@ -1,4 +1,6 @@ class Checkpoint < ApplicationRecord + enum kind: {comment: 0, checkin: 1, checkout: 2} + belongs_to :run belongs_to :user diff --git a/app/models/run.rb b/app/models/run.rb index 7c9209e..023202b 100644 --- a/app/models/run.rb +++ b/app/models/run.rb @@ -3,5 +3,11 @@ class Run < ApplicationRecord belongs_to :user has_many :checkpoints, dependent: :destroy - validates_presence_of :title + validates :title, presence: true + + def checked_in? + last_checkpoint = checkpoints.where.not(kind: :comment).last + # If there are no non-comment checkpoints, then the run was never checked in. + last_checkpoint.nil? ? false : last_checkpoint.checkin? + end end |