Sha256: 539da2148d0e839c8f2ef7c1b4646b92f29ad41b22054686182eff816f7e93ff
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class StateEnumTest < Test::Unit::TestCase def setup @klass = Class.new do def self.has_enumerated enum_attr, enum_opts class_eval do define_method enum_attr do @enum_attr end define_method :"#{enum_attr}=" do |value| @enum_attr = value end end end end @klass.send :include, EnumStateMachine::StateEnum end def test_should_allow_state_enum_on_any_class assert @klass.respond_to?(:has_state_enum) end def test_should_allow_power_enum_in_any_class @klass.class_eval do has_state_enum :state, :vehicle_state state_machine :state, initial: :new do state :new state :used event :buy do transition new: :used end end end assert @klass.respond_to?(:has_enumerated) object = @klass.new object.state = :new assert_equal "new", object.state object.buy! assert_equal "used", object.state end end
Version data entries
4 entries across 4 versions & 1 rubygems