Sha256: 8e7d769bd826d60893b030a4e5d7bab7ca5fd0fbee25f2d30db7af295363b825

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

Given /^I have no nodes$/ do
  Node.delete_all
end

Given /^the following nodes exist:$/ do |nodes_table|
  # table is a Cucumber::Ast::Table
  nodes_table.hashes.each do |hash|
    node = Node.new(:name => hash[:name])
    if !(hash[:parent] == "")
      parent = Node.find(:first, :conditions => { :name => hash[:parent]})
      parent.children << node
      parent.save!
      node.save!
    else
      Node.create( :name => hash[:name])
    end
  end
end

Given /^I create a tree$/ do
    12.times{ Factory.create(:node) }
    
    Node.where(:name  => "Node_1").first.children << Node.where(:name => "Node_7").first
    Node.where(:name  => "Node_7").first.insert_before(Node.where(:name => "Node_2").first)
    Node.where(:name  => "Node_1").first.children << Node.where(:name => "Node_8").first
    Node.where(:name  => "Node_2").first.children << Node.where(:name => "Node_3").first
    Node.where(:name  => "Node_3").first.insert_after(Node.where(:name => "Node_6").first)
    Node.where(:name  => "Node_8").first.children << Node.where(:name => "Node_9").first
    Node.where(:name  => "Node_9").first.children << Node.where(:name => "Node_11").first
    Node.where(:name  => "Node_3").first.children << Node.where(:name => "Node_5").first
    Node.where(:name  => "Node_9").first.insert_after(Node.where(:name => "Node_12").first)
    Node.where(:name  => "Node_5").first.insert_before(Node.where(:name => "Node_4").first)
    Node.where(:name  => "Node_11").first.insert_before(Node.where(:name => "Node_10").first)
end


When /^I request the children depth first$/ do
  @root = Node.find(:first, :conditions => { :name => "Node_1" })
  @root.should_not be(nil)
  @children = @root.depth_first.map{|node| [node.name]}
end

Then /^I should get the children in the following order$/ do |expected_children_order|
  # table is a Cucumber::Ast::Table
  expected_children_order.diff!(@children)
end

Then /^I should have (\d+) Nodes$/ do |count|
  Node.count.should be(count.to_i)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid_tree-0.2.0 features/step_definitions/mongoid_tree_steps.rb
mongoid_tree-0.1.0 features/step_definitions/mongoid_tree_steps.rb