Permalink
Browse files

starts trees off at first node by default

  • Loading branch information...
1 parent bf3e3e3 commit 83ad8b5b9be7b4cf488f77a72ff8db9f2608b15b @Najaf Najaf committed Mar 1, 2013
Showing with 9 additions and 2 deletions.
  1. +4 −2 lib/dumb-answers/tree.rb
  2. +5 −0 spec/tree_spec.rb
@@ -17,12 +17,14 @@ def get(name)
trees[name]
end
- def begin(name, options)
+ def begin(name, options = {})
continue(name, options.merge(history: []))
end
def continue(name, options)
- State.new(get(name), options[:from] || options[:current]).tap do |s|
+ nodes = get(name)
+ start_id = options[:from] || options[:current] || nodes.values.first.id
+ State.new(nodes, start_id).tap do |s|
s.history = options[:history]
end
end
View
@@ -21,6 +21,11 @@
Tree.begin('state-test', from: 'q1').history.must_equal []
end
+ it 'starts the tree at the first node by default' do
+ Tree.begin('state-test').current.id.must_equal 'q1'
+ end
+
+
it 'returns a state object with set current node' do
Tree.begin('state-test', from: 'q2').current.id.must_equal 'q2'
end

0 comments on commit 83ad8b5

Please sign in to comment.