Skip to content

Commit

Permalink
switch over to using enums for status
Browse files Browse the repository at this point in the history
  • Loading branch information
SirNeuman committed Feb 13, 2025
1 parent 9997c0c commit 3a18c4c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/models/demo_mode/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
module DemoMode
class Session < ActiveRecord::Base
attribute :variant, default: :default
attribute :status, default: 'processing'

if ActiveRecord.gem_version >= Gem::Version.new('7.2')
enum :status, { processing: 'processing', successful: 'successful', failed: 'failed' }, default: 'processing'
else
attribute :status, default: :processing
enum status: { processing: 'processing', successful: 'successful', failed: 'failed' }
end

validates :persona_name, :variant, presence: true
validates :persona, presence: { message: :required }, on: :create, if: :persona_name?
validates :status, inclusion: { in: %w(processing successful failed) }

belongs_to :signinable, polymorphic: true, optional: true

before_create :set_password!
Expand Down Expand Up @@ -41,10 +48,6 @@ def save_and_generate_account_later!(**options)
end
end

def processing?
status == 'processing'
end

private

def set_password!
Expand Down

0 comments on commit 3a18c4c

Please sign in to comment.