1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
# Load library
require 'rubygems'
module BaseTest
class IntegrationTest < Test::Unit::TestCase
def test_should_have_an_integration_name
assert_equal :base, StateMachine::Integrations::Base.integration_name
end
def test_should_not_be_available
assert !StateMachine::Integrations::Base.available?
end
def test_should_not_have_any_matching_ancestors
assert_equal [], StateMachine::Integrations::Base.matching_ancestors
end
def test_should_not_match_any_classes
assert !StateMachine::Integrations::Base.matches?(Class.new)
end
def test_should_not_have_a_locale_path
assert_nil StateMachine::Integrations::Base.locale_path
end
end
class IncludedTest < Test::Unit::TestCase
def setup
@integration = Module.new
StateMachine::Integrations.const_set('Custom', @integration)
@integration.class_eval do
include StateMachine::Integrations::Base
end
end
def test_should_not_have_any_defaults
assert_nil @integration.defaults
end
def test_should_not_have_any_versions
assert_equal [], @integration.versions
end
def test_should_track_version
version1 = @integration.version '1.0' do
def self.active?
true
end
end
version2 = @integration.version '2.0' do
def self.active?
false
end
end
assert_equal [version1, version2], @integration.versions
end
def test_should_allow_active_versions_to_override_default_behavior
@integration.class_eval do
def version1_included?
false
end
def version2_included?
false
end
end
@integration.version '1.0' do
def self.active?
true
end
def version1_included?
true
end
end
@integration.version '2.0' do
def self.active?
false
end
def version2_included?
true
end
end
@machine = StateMachine::Machine.new(Class.new, :integration => :custom)
assert @machine.version1_included?
assert !@machine.version2_included?
end
def teardown
StateMachine::Integrations.send(:remove_const, 'Custom')
super
end
end
end
|