class SequelTest::MachineWithDynamicInitialStateTest
Public Instance Methods
setup()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 210 def setup @model = new_model do attr_accessor :value end @machine = StateMachine::Machine.new(@model, :initial => lambda {|object| :parked}) @machine.state :parked end
test_should_not_have_any_changed_columns()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 237 def test_should_not_have_any_changed_columns record = @model.new assert record.changed_columns.empty? end
test_should_not_set_initial_state_after_already_initialized()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 266 def test_should_not_set_initial_state_after_already_initialized record = @model.new(:value => 1) assert_equal 'parked', record.state record.state = 'idling' record.set({}) assert_equal 'idling', record.state end
test_should_set_attributes_prior_to_after_initialize_hook()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 242 def test_should_set_attributes_prior_to_after_initialize_hook state = nil @model.class_eval do define_method(:after_initialize) do state = self.state end end @model.new assert_equal 'parked', state end
test_should_set_initial_state_after_setting_attributes()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 253 def test_should_set_initial_state_after_setting_attributes @model.class_eval do attr_accessor :state_during_setter define_method(:value=) do |value| self.state_during_setter = state || 'nil' end end record = @model.new(:value => 1) assert_equal 'nil', record.state_during_setter end
test_should_set_initial_state_on_created_object()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 218 def test_should_set_initial_state_on_created_object record = @model.new assert_equal 'parked', record.state end
test_should_still_allow_initialize_blocks()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 228 def test_should_still_allow_initialize_blocks block_args = nil record = @model.new do |*args| block_args = args end assert_equal [record], block_args end
test_should_still_set_attributes()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 223 def test_should_still_set_attributes record = @model.new(:value => 1) assert_equal 1, record.value end
test_should_use_stored_values_when_loading_from_database()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 275 def test_should_use_stored_values_when_loading_from_database @machine.state :idling record = @model[@model.create(:state => 'idling').id] assert_equal 'idling', record.state end
test_should_use_stored_values_when_loading_from_database_with_nil_state()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 282 def test_should_use_stored_values_when_loading_from_database_with_nil_state @machine.state nil record = @model[@model.create(:state => nil).id] assert_nil record.state end