1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/models/validator.rb
2013-10-22 12:30:04 +02:00

29 lines
696 B
Ruby

require 'active_record'
class Validator < ActiveRecord::Base
include AASM
aasm :column => :status do
state :sleeping, :initial => true
state :running, :after_commit => :change_name!
state :failed, :after_enter => :fail, :after_commit => :change_name!
event :run do
transitions :to => :running, :from => :sleeping
end
event :sleep do
transitions :to => :sleeping, :from => :running
end
event :fail do
transitions :to => :failed, :from => [:sleeping, :running]
end
end
validates_presence_of :name
def change_name!
self.name = "name changed"
save!
end
def fail
raise StandardError.new('failed on purpose')
end
end