class ActiveModelTest::MachineWithInitializedStateTest
Public Class Methods
new(attrs = {})
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 273 def initialize(attrs = {}) initialize_state_machines do sanitize_for_mass_assignment(attrs).each {|attr, value| send("#{attr}=", value)} if attrs @changed_attributes = {} end end
Public Instance Methods
setup()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 236 def setup @model = new_model @machine = StateMachine::Machine.new(@model, :initial => :parked, :integration => :active_model) @machine.state nil, :idling end
test_should_allow_different_initial_state_when_dynamic()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 262 def test_should_allow_different_initial_state_when_dynamic @machine.initial_state = lambda {:parked} record = @model.new(:state => 'idling') assert_equal 'idling', record.state end
test_should_allow_different_initial_state_when_static()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 257 def test_should_allow_different_initial_state_when_static record = @model.new(:state => 'idling') assert_equal 'idling', record.state end
test_should_allow_nil_initial_state_when_dynamic()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 249 def test_should_allow_nil_initial_state_when_dynamic @machine.state nil @machine.initial_state = lambda {:parked} record = @model.new(:state => nil) assert_nil record.state end
test_should_allow_nil_initial_state_when_static()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 242 def test_should_allow_nil_initial_state_when_static @machine.state nil record = @model.new(:state => nil) assert_nil record.state end
test_should_use_default_state_if_protected()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 268 def test_should_use_default_state_if_protected @model.class_eval do include ActiveModel::MassAssignmentSecurity attr_protected :state def initialize(attrs = {}) initialize_state_machines do sanitize_for_mass_assignment(attrs).each {|attr, value| send("#{attr}=", value)} if attrs @changed_attributes = {} end end end record = @model.new(:state => 'idling') assert_equal 'parked', record.state record = @model.new(nil) assert_equal 'parked', record.state end