~cytrogen/gstack

ref: c620de38e19fe63e8a6e361e11d706b5ed432b93 gstack/test/fixtures/review-eval-enum.rb -rw-r--r-- 759 bytes
c620de38 — Garry Tan fix: setup runs pending migrations so git pull + ./setup works (#774) 6 days ago
                                                                                
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
# Existing file on main: order model with status handling
class Order < ApplicationRecord
  STATUSES = %w[pending processing shipped delivered].freeze

  validates :status, inclusion: { in: STATUSES }

  def display_status
    case status
    when 'pending'    then 'Awaiting processing'
    when 'processing' then 'Being prepared'
    when 'shipped'    then 'On the way'
    when 'delivered'  then 'Delivered'
    end
  end

  def can_cancel?
    %w[pending processing].include?(status)
  end

  def notify_customer
    case status
    when 'pending'    then OrderMailer.confirmation(self).deliver_later
    when 'shipped'    then OrderMailer.shipped(self).deliver_later
    when 'delivered'  then OrderMailer.delivered(self).deliver_later
    end
  end
end