Permalink
Browse files

namespaces for tests to avoid constant collisions

  • Loading branch information...
1 parent 8fbae1b commit b85b2ea508c611d8a541295784929eb8aeea2c4b @mwlang committed Feb 12, 2010
Showing with 179 additions and 174 deletions.
  1. +1 −1 VERSION
  2. +52 −49 test/test_export.rb
  3. +126 −124 test/test_sequel_tree.rb
View
2 VERSION
@@ -1 +1 @@
-0.0.5
+0.0.6
View
101 test/test_export.rb
@@ -1,58 +1,61 @@
require 'helper'
require 'sequel_plus'
-DB = Sequel.sqlite
-
-DB.create_table :nodes do
- primary_key :id
- String :name
- Integer :parent_id
- Integer :position
-end
-
-NODES = [
- {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
- {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
- {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
- {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
- {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
- {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
- {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
- {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
- {:id => 9, :name => "five", :parent_id => nil, :position => 5},
- {:id => 10, :name => "four", :parent_id => nil, :position => 4},
- {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
- {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
-]
-
-DB.create_table :lorems do
- primary_key :id
- String :name
- Integer :ipsum_id
- Integer :neque
-end
-
-LOREMS = [
- {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
- {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
- {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
- {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
-]
-
-NODES.each{|node| DB[:nodes].insert(node)}
-LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
-
-describe Sequel::Export do
+module ExportTest
- it "should instantiate" do
- DB[:nodes].all.size.should == 12
+ DB = Sequel.sqlite
+
+ DB.create_table :nodes do
+ primary_key :id
+ String :name
+ Integer :parent_id
+ Integer :position
end
- it "should export everything" do
- DB[:nodes].export.should == "id\tname\tparent_id\tposition\n1\tone\t\t1\n2\ttwo\t\t2\n3\tthree\t\t3\n4\ttwo.one\t2\t1\n5\ttwo.two\t2\t2\n6\ttwo.two.one\t5\t1\n7\tone.two\t1\t2\n8\tone.one\t1\t1\n9\tfive\t\t5\n10\tfour\t\t4\n11\tfive.one\t9\t1\n12\ttwo.three\t2\t3"
+ NODES = [
+ {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
+ {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
+ {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
+ {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
+ {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
+ {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
+ {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
+ {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
+ {:id => 9, :name => "five", :parent_id => nil, :position => 5},
+ {:id => 10, :name => "four", :parent_id => nil, :position => 4},
+ {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
+ {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
+ ]
+
+ DB.create_table :lorems do
+ primary_key :id
+ String :name
+ Integer :ipsum_id
+ Integer :neque
end
+
+ LOREMS = [
+ {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
+ {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
+ {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
+ {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
+ ]
+
+ NODES.each{|node| DB[:nodes].insert(node)}
+ LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
+
+ describe Sequel::Export do
+
+ it "should instantiate" do
+ DB[:nodes].all.size.should == 12
+ end
+
+ it "should export everything" do
+ DB[:nodes].export.should == "id\tname\tparent_id\tposition\n1\tone\t\t1\n2\ttwo\t\t2\n3\tthree\t\t3\n4\ttwo.one\t2\t1\n5\ttwo.two\t2\t2\n6\ttwo.two.one\t5\t1\n7\tone.two\t1\t2\n8\tone.one\t1\t1\n9\tfive\t\t5\n10\tfour\t\t4\n11\tfive.one\t9\t1\n12\ttwo.three\t2\t3"
+ end
- it "should export selected" do
- DB[:nodes].filter(:id < 3).select(:id, :name).export.should == "id\tname\n1\tone\n2\ttwo"
+ it "should export selected" do
+ DB[:nodes].filter(:id < 3).select(:id, :name).export.should == "id\tname\n1\tone\n2\ttwo"
+ end
end
-end
+end
View
250 test/test_sequel_tree.rb
@@ -1,157 +1,159 @@
require 'helper'
-DB = Sequel.sqlite
+module SequelTreeTest
+ DB = Sequel.sqlite
-DB.create_table :nodes do
- primary_key :id
- String :name
- Integer :parent_id
- Integer :position
-end
+ DB.create_table :nodes do
+ primary_key :id
+ String :name
+ Integer :parent_id
+ Integer :position
+ end
-NODES = [
- {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
- {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
- {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
- {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
- {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
- {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
- {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
- {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
- {:id => 9, :name => "five", :parent_id => nil, :position => 5},
- {:id => 10, :name => "four", :parent_id => nil, :position => 4},
- {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
- {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
-]
+ NODES = [
+ {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
+ {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
+ {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
+ {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
+ {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
+ {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
+ {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
+ {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
+ {:id => 9, :name => "five", :parent_id => nil, :position => 5},
+ {:id => 10, :name => "four", :parent_id => nil, :position => 4},
+ {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
+ {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
+ ]
-DB.create_table :lorems do
- primary_key :id
- String :name
- Integer :ipsum_id
- Integer :neque
-end
+ DB.create_table :lorems do
+ primary_key :id
+ String :name
+ Integer :ipsum_id
+ Integer :neque
+ end
-LOREMS = [
- {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
- {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
- {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
- {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
-]
+ LOREMS = [
+ {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
+ {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
+ {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
+ {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
+ ]
-NODES.each{|node| DB[:nodes].insert(node)}
-LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
+ NODES.each{|node| DB[:nodes].insert(node)}
+ LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
-class Node < Sequel::Model
- plugin :tree
-end
+ class Node < Sequel::Model
+ plugin :tree
+ end
-class NaturalNode < Sequel::Model(:nodes)
- plugin :tree
-end
+ class NaturalNode < Sequel::Model(:nodes)
+ plugin :tree
+ end
-class OrderedNode < Sequel::Model(:nodes)
- plugin :tree, :order => :position
-end
+ class OrderedNode < Sequel::Model(:nodes)
+ plugin :tree, :order => :position
+ end
-class Lorem < Sequel::Model
- plugin :tree, :key => :ipsum_id, :order => :neque
-end
+ class Lorem < Sequel::Model
+ plugin :tree, :key => :ipsum_id, :order => :neque
+ end
-describe Sequel::Plugins::Tree do
+ describe Sequel::Plugins::Tree do
- it "should instantiate" do
- Node.all.size.should == 12
- end
+ it "should instantiate" do
+ Node.all.size.should == 12
+ end
- it "should find top level nodes" do
- Node.roots.count.should == 5
- end
+ it "should find top level nodes" do
+ Node.roots.count.should == 5
+ end
- it "should find all descendants of a node" do
- two = Node.find(:id => 2)
- two.name.should == "two"
- two.descendants.map{|m| m[:id]}.should == [4, 5, 12]
- end
+ it "should find all descendants of a node" do
+ two = Node.find(:id => 2)
+ two.name.should == "two"
+ two.descendants.map{|m| m[:id]}.should == [4, 5, 12]
+ end
- it "should find all ancestors of a node" do
- twotwoone = Node.find(:id => 6)
- twotwoone.name.should == "two.two.one"
- twotwoone.ancestors.map{|m| m[:id]}.should == [5, 2]
- end
+ it "should find all ancestors of a node" do
+ twotwoone = Node.find(:id => 6)
+ twotwoone.name.should == "two.two.one"
+ twotwoone.ancestors.map{|m| m[:id]}.should == [5, 2]
+ end
- it "should find all siblings of a node, excepting self" do
- twoone = Node.find(:id => 4)
- twoone.name.should == "two.one"
- twoone.siblings.map{|m| m[:id]}.should == [5, 12]
- end
+ it "should find all siblings of a node, excepting self" do
+ twoone = Node.find(:id => 4)
+ twoone.name.should == "two.one"
+ twoone.siblings.map{|m| m[:id]}.should == [5, 12]
+ end
- it "should find all siblings of a node, including self" do
- twoone = Node.find(:id => 4)
- twoone.name.should == "two.one"
- twoone.self_and_siblings.map{|m| m[:id]}.should == [4, 5, 12]
- end
+ it "should find all siblings of a node, including self" do
+ twoone = Node.find(:id => 4)
+ twoone.name.should == "two.one"
+ twoone.self_and_siblings.map{|m| m[:id]}.should == [4, 5, 12]
+ end
- it "should find siblings for root nodes" do
- three = Node.find(:id => 3)
- three.name.should == "three"
- three.self_and_siblings.map{|m| m[:id]}.should == [1, 2, 3, 9, 10]
- end
+ it "should find siblings for root nodes" do
+ three = Node.find(:id => 3)
+ three.name.should == "three"
+ three.self_and_siblings.map{|m| m[:id]}.should == [1, 2, 3, 9, 10]
+ end
- it "should find correct root for a node" do
- twotwoone = Node.find(:id => 6)
- twotwoone.name.should == "two.two.one"
- twotwoone.root[:id].should == 2
+ it "should find correct root for a node" do
+ twotwoone = Node.find(:id => 6)
+ twotwoone.name.should == "two.two.one"
+ twotwoone.root[:id].should == 2
- three = Node.find(:id => 3)
- three.name.should == "three"
- three.root[:id].should == 3
+ three = Node.find(:id => 3)
+ three.name.should == "three"
+ three.root[:id].should == 3
- fiveone = Node.find(:id => 11)
- fiveone.name.should == "five.one"
- fiveone.root[:id].should == 9
- end
-
- describe "Nodes in natural database order" do
- it "iterate top-level nodes in natural database order" do
- NaturalNode.roots.count.should == 5
- NaturalNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 5, 4]
+ fiveone = Node.find(:id => 11)
+ fiveone.name.should == "five.one"
+ fiveone.root[:id].should == 9
end
+
+ describe "Nodes in natural database order" do
+ it "iterate top-level nodes in natural database order" do
+ NaturalNode.roots.count.should == 5
+ NaturalNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 5, 4]
+ end
- it "should have children" do
- one = NaturalNode.find(:id => 1)
- one.name.should == "one"
- one.children.count.should == 2
- end
+ it "should have children" do
+ one = NaturalNode.find(:id => 1)
+ one.name.should == "one"
+ one.children.count.should == 2
+ end
- it "children should be natural database order" do
- one = NaturalNode.find(:id => 1)
- one.name.should == "one"
- one.children.map{|m| m[:position]}.should == [2, 1]
+ it "children should be natural database order" do
+ one = NaturalNode.find(:id => 1)
+ one.name.should == "one"
+ one.children.map{|m| m[:position]}.should == [2, 1]
+ end
end
- end
- describe "Nodes in specified order" do
- it "iterate top-level nodes in order by position" do
- OrderedNode.roots.count.should == 5
- OrderedNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 4, 5]
- end
+ describe "Nodes in specified order" do
+ it "iterate top-level nodes in order by position" do
+ OrderedNode.roots.count.should == 5
+ OrderedNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 4, 5]
+ end
- it "children should be in specified order" do
- one = OrderedNode.find(:id => 1)
- one.name.should == "one"
- one.children.map{|m| m[:position]}.should == [1, 2]
+ it "children should be in specified order" do
+ one = OrderedNode.find(:id => 1)
+ one.name.should == "one"
+ one.children.map{|m| m[:position]}.should == [1, 2]
+ end
end
- end
- describe "Lorems in specified order" do
- it "iterate top-level nodes in order by position" do
- Lorem.roots.count.should == 2
- Lorem.roots.inject([]){|ids, p| ids << p.neque}.should == [3, 4]
- end
+ describe "Lorems in specified order" do
+ it "iterate top-level nodes in order by position" do
+ Lorem.roots.count.should == 2
+ Lorem.roots.inject([]){|ids, p| ids << p.neque}.should == [3, 4]
+ end
- it "children should be specified order" do
- one = Lorem.find(:id => 2)
- one.children.map{|m| m[:neque]}.should == [1, 2]
+ it "children should be specified order" do
+ one = Lorem.find(:id => 2)
+ one.children.map{|m| m[:neque]}.should == [1, 2]
+ end
end
end
-end
+end

0 comments on commit b85b2ea

Please sign in to comment.