Skip to content
Permalink
Browse files

added test to verify that the SQL generated is correct

  • Loading branch information...
dhoss committed Nov 2, 2014
1 parent 6ca1cbe commit da2acb482116773e12aeb0a3e68cd53b26135484
Showing with 18 additions and 1 deletion.
  1. +18 −1 spec/treeify_spec.rb
@@ -8,13 +8,30 @@

it "is set up correctly" do
expect(Node.table_name).to eq("nodes")
expect(Node.cols).to eq([:name])
end

it "has the correct data in the database" do
expect(Node.roots.count).to eq(3)
expect(Node.roots.first.descendents.count).to eq(50)
end

it "retrieves all the columns defined in the configuration" do
expected_sql = "WITH RECURSIVE cte (id, path) AS (
SELECT id,
array[id] AS path
FROM nodes
WHERE id = 1
UNION ALL
SELECT nodes.id,
cte.path || nodes.id
FROM nodes
JOIN cte ON nodes.parent_id = cte.id
)"
expect(Node.tree_sql(Node.first)).to eq(expected_sql)
end

end

describe "Down the tree" do

0 comments on commit da2acb4

Please sign in to comment.
You can’t perform that action at this time.