Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence uneccessary warning with default state with value #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/state_machine/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/unit/machine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down