Skip to content

Instantly share code, notes, and snippets.

@stith
Created March 4, 2010 09:52
Show Gist options
  • Save stith/321594 to your computer and use it in GitHub Desktop.
Save stith/321594 to your computer and use it in GitHub Desktop.
Ruby test cases for testification
#!/usr/bin/env ruby
# Testing the aasm gem to see how to get one aasm_event to decide
# which state to transition into
require 'rubygems'
require 'aasm'
class TestObject
include AASM
aasm_initial_state :active
aasm_state :active, :enter => :make_active
aasm_state :sold, :enter => :make_sold
aasm_state :unsold, :enter => :make_unsold
aasm_event :finish do
transitions :to => :sold, :from => [:active], :guard => Proc.new {|a| a.reserve < a.price}
transitions :to => :unsold, :from => [:active]
end
attr_accessor :price, :reserve, :name
def initialize(name, price,reserve)
@name = name
@price = price
@reserve = reserve
end
private
def make_active
puts "#{name} is now active!"
end
def make_sold
puts "#{name} is now sold!"
end
def make_unsold
puts "#{name} is now unsold!"
end
end
sells = TestObject.new('sell',100,50)
sells.finish
nosell = TestObject.new('nosell',50,100)
nosell.finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment