class MongoMapperTest::MachineWithFailedBeforeCallbacksTest

Public Instance Methods

setup() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 816
def setup
  @callbacks = []
  
  @model = new_model
  @machine = StateMachine::Machine.new(@model)
  @machine.state :parked, :idling
  @machine.event :ignite
  @machine.before_transition {@callbacks << :before_1; false}
  @machine.before_transition {@callbacks << :before_2}
  @machine.after_transition {@callbacks << :after}
  @machine.around_transition {|block| @callbacks << :around_before; block.call; @callbacks << :around_after}
  
  @record = @model.new(:state => 'parked')
  @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
  @result = @transition.perform
end
test_should_be_successful() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 834
def test_should_be_successful
  assert @result
end
test_should_change_current_state() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 838
def test_should_change_current_state
  assert_equal 'idling', @record.state
end
test_should_not_be_successful() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 850
def test_should_not_be_successful
  assert !@result
end
test_should_not_change_current_state() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 854
def test_should_not_change_current_state
  assert_equal 'parked', @record.state
end
test_should_not_run_action() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 858
def test_should_not_run_action
  assert @record.new_record?
end
test_should_not_run_further_callbacks() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 862
def test_should_not_run_further_callbacks
  assert_equal [:before_1], @callbacks
end
test_should_run_action() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 842
def test_should_run_action
  assert !@record.new_record?
end
test_should_run_further_callbacks() click to toggle source
# File test/unit/integrations/mongo_mapper_test.rb, line 846
def test_should_run_further_callbacks
  assert_equal [:before_1, :before_2, :around_before, :around_after, :after], @callbacks
end