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

41 lines
810 B
Ruby
Raw Normal View History

require 'active_record'
class Validator < ActiveRecord::Base
include AASM
aasm :column => :status do
state :sleeping, :initial => true
state :running
state :failed, :after_enter => :fail
event :run, :after_commit => :change_name! do
transitions :to => :running, :from => :sleeping
end
event :sleep do
2015-06-15 16:53:44 -04:00
after_commit do |name|
change_name_on_sleep name
end
transitions :to => :sleeping, :from => :running
end
2013-10-22 06:30:04 -04:00
event :fail do
transitions :to => :failed, :from => [:sleeping, :running]
end
end
validates_presence_of :name
2013-10-22 06:30:04 -04:00
def change_name!
self.name = "name changed"
save!
end
2015-06-15 16:53:44 -04:00
def change_name_on_sleep name
self.name = name
save!
end
2013-10-22 06:30:04 -04:00
def fail
raise StandardError.new('failed on purpose')
end
end