2012-11-06 05:31:13 -05:00
|
|
|
require 'spec_helper'
|
2011-10-15 11:32:28 -04:00
|
|
|
|
|
|
|
describe "state machines" do
|
|
|
|
|
|
|
|
def number_of_objects(clazz)
|
|
|
|
ObjectSpace.each_object(clazz) {}
|
|
|
|
end
|
2012-11-06 05:31:13 -05:00
|
|
|
|
2011-10-15 11:32:28 -04:00
|
|
|
def machines
|
|
|
|
AASM::StateMachine.instance_variable_get("@machines")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be created without memory leak" do
|
|
|
|
machines_count = machines.size
|
|
|
|
state_count = number_of_objects(AASM::SupportingClasses::State)
|
|
|
|
event_count = number_of_objects(AASM::SupportingClasses::Event)
|
2012-11-06 05:47:41 -05:00
|
|
|
puts "event_count = #{event_count}"
|
2011-10-15 11:32:28 -04:00
|
|
|
transition_count = number_of_objects(AASM::SupportingClasses::StateTransition)
|
|
|
|
|
2011-10-15 11:45:24 -04:00
|
|
|
load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb')
|
2011-10-15 11:32:28 -04:00
|
|
|
machines.size.should == machines_count + 1 # + Process
|
|
|
|
number_of_objects(Models::Process).should == 0
|
|
|
|
number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process
|
2012-11-06 05:47:41 -05:00
|
|
|
puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}"
|
2011-10-15 11:32:28 -04:00
|
|
|
number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process
|
|
|
|
number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process
|
|
|
|
|
|
|
|
Models.send(:remove_const, "Process") if Models.const_defined?("Process")
|
2011-10-15 11:45:24 -04:00
|
|
|
load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb')
|
2011-10-15 11:32:28 -04:00
|
|
|
machines.size.should == machines_count + 1 # + Process
|
|
|
|
number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process
|
2012-11-06 05:47:41 -05:00
|
|
|
# ObjectSpace.each_object(AASM::SupportingClasses::Event) {|o| puts o.inspect}
|
|
|
|
puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}"
|
2011-10-15 11:32:28 -04:00
|
|
|
number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process
|
|
|
|
number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|