From d18957ebb7b7c6a168aa13db2cbff214911ceac5 Mon Sep 17 00:00:00 2001 From: Pawel Pierzchala Date: Mon, 16 Dec 2013 12:59:20 +0100 Subject: [PATCH] Silence uneccessary warning with default state with value --- lib/state_machine/machine.rb | 2 +- test/unit/machine_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/state_machine/machine.rb b/lib/state_machine/machine.rb index 6aa6eae0..3dbe0575 100644 --- a/lib/state_machine/machine.rb +++ b/lib/state_machine/machine.rb @@ -568,7 +568,6 @@ def initialize(owner_class, *args, &block) @initialize_state = options[:initialize] @action_hook_defined = false self.owner_class = owner_class - self.initial_state = options[:initial] unless sibling_machines.any? # Merge with sibling machine configurations add_sibling_machine_configs @@ -580,6 +579,7 @@ def initialize(owner_class, *args, &block) # Evaluate DSL instance_eval(&block) if block_given? + self.initial_state = options[:initial] unless sibling_machines.any? end # Creates a copy of this machine in addition to copies of each associated diff --git a/test/unit/machine_test.rb b/test/unit/machine_test.rb index 066fc1d5..0a7897cb 100644 --- a/test/unit/machine_test.rb +++ b/test/unit/machine_test.rb @@ -328,6 +328,30 @@ def test_should_be_included_in_known_states end end +class MachineWithInitialStateWithValueAndOwnerDefault < Test::Unit::TestCase + def setup + @original_stderr, $stderr = $stderr, StringIO.new + + state_machine_with_defaults = Class.new(StateMachine::Machine) do + def owner_class_attribute_default + 0 + end + end + @klass = Class.new + @machine = state_machine_with_defaults.new(@klass, :initial => :parked) do + state :parked, :value => 0 + end + end + + def test_should_not_warn_about_wrong_default + assert_equal '', $stderr.string + end + + def teardown + $stderr = @original_stderr + end +end + class MachineWithDynamicInitialStateTest < Test::Unit::TestCase def setup @klass = Class.new do