Skip to content
Permalink
Browse files

added more first level tests, added pending tests for sub children an…

…d siblings
  • Loading branch information...
dhoss committed Jun 13, 2014
1 parent 34de49c commit edd85ee2b5736fa8d594417fb140f15e7d419f3b
Showing with 51 additions and 6 deletions.
  1. +6 −0 lib/treeify.rb
  2. +2 −2 spec/spec_helper.rb
  3. +43 −4 spec/treeify_spec.rb
@@ -7,6 +7,12 @@ module Treeify
extend ActiveSupport::Concern

included do
has_many :children,
class_name: self,
foreign_key: "parent_id"
belongs_to :parent,
class_name: self,
foreign_key: "parent_id"
class_attribute :cols
scope :roots, -> { where(parent_id: nil) }
scope :tree_for, ->(instance) { where("#{table_name}.id IN (#{tree_sql_for(instance)})").order("#{table_name}.id") }
@@ -18,7 +18,7 @@
class Node < ActiveRecord::Base
include Treeify
config({:cols => [:name]})

validates_uniqueness_of :name
validates_uniqueness_of :parent_id, :scope=> :id
end
@@ -41,7 +41,7 @@ def down
end

RSpec.configure do |config|

I18n.enforce_available_locales = false
config.before(:suite) do
NodeSetup.up
# Create three root nodes with 50 descendants
@@ -30,14 +30,53 @@
end

describe "Modifying the tree" do
subject(:new_root) { Node.create(name: "new root node") }
it "adds a new child" do
expect(new_root.name).to eq("new root node")
root = Node.roots.first
root.children << Node.create(name: "new child node")
child = root.children.where(name: "new child node").take
expect(child.name).to eq("new child node")
end

it "updates a child"
it "has the correct parent" do
root = Node.roots.first
child = Node.where(name: "new child node").take
expect(child.parent.id).to eq(root.id)
end

it "updates a child" do
root = Node.roots.first
child = Node.where(name: "new child node").take
child.name = "fart nuggets"
child.save
expect(child.name).to eq("fart nuggets")
end


it "deletes a child" do
root = Node.roots.first
child = Node.where(name: "new child node").take
Node.delete(child)
expect(Node.where(name: "new child node").take).to eq(nil)
end

it "adds children to child nodes"

it "has the correct tree after subchildren are added"

it "deletes subchildren"

it "re-parents children"

it "has the correct tree after children are re-parented"

it "retrieves siblings"

it "adds siblings"

it "updates siblings"

it "deletes siblings"

it "deletes a child"

end
end

0 comments on commit edd85ee

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