~cytrogen/gstack

ref: 318ffdbdf01e9c6ad78ab41852803d955e9dc092 gstack/test/fixtures/review-eval-enum.rb -rw-r--r-- 759 bytes
318ffdbd — Garry Tan fix: js statement wrapping + click auto-routes option to selectOption (v0.4.5) (#117) a month 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