sequel_plus 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # sequel_plus
2
2
 
3
- This library starts the collection of plugins and possibly extension I assemble for the Ruby Sequel
4
- ORM.
3
+ This library starts the collection of plugins and extensions I have assembled for the Ruby Sequel library.
4
+ The library is in very early infancy stage, so there's not much presently, but what's here is fully covered
5
+ in specs and tested and used in production-level deployments already.
6
+
5
7
 
6
- Currently, it only contains a plugin for Trees to mimic the Rails acts_as_tree plugin.
8
+ Currently, sequel_plus contains:
9
+ * plugin for Trees to mimic the Rails acts_as_tree plugin.
10
+ * extension for exporting data using Dataset#export.
7
11
 
8
12
  NOTE: Authors of other plugins and extensions for Sequel are welcome to contact me for inclusion
9
13
  of your plugin and extension to this project.
@@ -12,21 +16,39 @@ Released under MIT license.
12
16
 
13
17
  # For the Impatient
14
18
 
19
+ ## Install
20
+
15
21
  This gem is released to gemcutter. Rubyforge is not utilized.
16
22
 
17
23
  gem install sequel_plus
18
24
 
19
- And then, in your project:
25
+ ## Use Tree Plugin
20
26
 
21
27
  require 'sequel'
22
28
 
23
29
  class Node < Sequel::Model
24
30
  plugin :tree
25
31
  end
32
+
33
+ ## Use Exporter
34
+
35
+ require 'sequel'
36
+ require 'sequel_plus'
37
+
38
+ DB = Sequel.sqlite
39
+
40
+ # Every row, every column, tab delimited, unquoted...
41
+ File.open("nodes.txt", "w"){|file| DB[:nodes].export(file)}
42
+
43
+ # Every row, every column, comma delimited double-quotes
44
+ File.open("nodes.txt", "w"){|file| DB[:nodes].export(file, :delimiter => ',', :quote_char => '"')}
26
45
 
46
+ # Specific rows and columns
47
+ File.open("nodes.txt", "w"){|file| DB[:nodes].filter(:id < 5).select(:id, :name).export(file)}
48
+
27
49
  # Note on Patches/Pull Requests
28
50
 
29
- * First release!
51
+ * This release adds an export facility to the Sequel::Dataset
30
52
 
31
53
  # Copyright
32
54
 
data/Rakefile CHANGED
@@ -15,6 +15,7 @@ begin
15
15
  "README.md",
16
16
  "Rakefile",
17
17
  "lib/*",
18
+ "lib/**/*",
18
19
  "test/*"
19
20
  ]
20
21
 
@@ -0,0 +1,61 @@
1
+ # The export extension adds Sequel::Dataset#export and the
2
+ # Sequel::Export class for creating plain-text data exports
3
+
4
+ module Sequel
5
+ class Dataset
6
+ # outputs the records in the dataset as plain-text table.
7
+ def export(fd = $stdout, options = {})
8
+ opts[:delimiter] = options[:delimiter] || "\t"
9
+ opts[:quote_char] = options[:quote_char] || '"'
10
+ opts[:headers] = options[:headers] != false
11
+ Sequel::Export::Writer.new(fd, self, opts).output
12
+ end
13
+ end
14
+
15
+ module Export
16
+
17
+ class Writer
18
+ def initialize(fd, dataset, options)
19
+ @file = fd
20
+ @dataset = dataset
21
+ @options = options
22
+ end
23
+
24
+ class ::Date; def to_export(q); ; end; end
25
+ class ::DateTime; def to_export(q); "#{q}#{iso8601}#{q}"; end; end
26
+ class ::Time; def to_export(q); "#{q}#{iso8601}#{q}"; end; end
27
+ class ::Float; def to_export(q); to_f.to_s; end; end
28
+ class ::BigDecimal; def to_export(q); to_f.to_s; end; end
29
+ class ::Bignum; def to_export(q); to_i.to_s; end; end
30
+ class ::Fixnum; def to_export(q); to_i.to_s; end; end
31
+ class ::Object; def to_export(q); "#{q}#{to_s}#{q}"; end; end
32
+
33
+ def output
34
+ quot = @options[:quote_char]
35
+ @columns ||= @dataset.first.keys.sort_by{|x|x.to_s}
36
+
37
+ if @options[:headers] == true
38
+ @file.puts @columns.map{|col| "#{quot}#{col}#{quot}"}.join(@options[:delimiter])
39
+ end
40
+
41
+ @dataset.each do |row|
42
+ data = @columns.map do |col|
43
+ case row[col]
44
+ when Date, DateTime, Time then "#{quot}#{row[col].iso8601}#{quot}"
45
+ when Float, BigDecimal then row[col].to_f
46
+ when BigDecimal, Bignum, Fixnum then row[col].to_i
47
+ else "#{quot}#{row[col].to_s}#{quot}"
48
+ end
49
+ end
50
+ @file.puts data.join(@options[:delimiter])
51
+ end
52
+ end
53
+
54
+ def build_row(row)
55
+ quot = @options[:quote_char]
56
+ @columns.map{|col| row[col].to_export(quot)}.join(@options[:delimiter])
57
+ end
58
+ end # Writer
59
+ end # Export
60
+ end # Sequel
61
+
data/lib/sequel_plus.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'sequel_tree'
2
- require 'extensions/export'
2
+ require File.join(File.dirname(__FILE__), 'extensions', 'export')
data/lib/sequel_tree.rb CHANGED
@@ -61,7 +61,7 @@ module Sequel
61
61
  # subchild1.ancestors # => [child1, root]
62
62
  def descendants
63
63
  nodes = self.children
64
- self.children.each{|c| nodes + c.descendants}
64
+ nodes.each{|child| nodes + child.descendants}
65
65
  nodes
66
66
  end
67
67
 
data/test/test_export.rb CHANGED
@@ -1,58 +1,164 @@
1
1
  require 'helper'
2
2
  require 'sequel_plus'
3
3
 
4
- DB = Sequel.sqlite
5
-
6
- DB.create_table :nodes do
7
- primary_key :id
8
- String :name
9
- Integer :parent_id
10
- Integer :position
11
- end
12
-
13
- NODES = [
14
- {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
15
- {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
16
- {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
17
- {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
18
- {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
19
- {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
20
- {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
21
- {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
22
- {:id => 9, :name => "five", :parent_id => nil, :position => 5},
23
- {:id => 10, :name => "four", :parent_id => nil, :position => 4},
24
- {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
25
- {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
26
- ]
27
-
28
- DB.create_table :lorems do
29
- primary_key :id
30
- String :name
31
- Integer :ipsum_id
32
- Integer :neque
33
- end
34
-
35
- LOREMS = [
36
- {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
37
- {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
38
- {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
39
- {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
40
- ]
41
-
42
- NODES.each{|node| DB[:nodes].insert(node)}
43
- LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
44
-
45
- describe Sequel::Export do
4
+ module ExportTest
46
5
 
47
- it "should instantiate" do
48
- DB[:nodes].all.size.should == 12
6
+ DB = Sequel.sqlite
7
+
8
+ DB.create_table :nodes do
9
+ primary_key :id
10
+ String :name
11
+ Integer :parent_id
12
+ Integer :position
49
13
  end
50
14
 
51
- it "should export everything" do
52
- 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"
15
+ NODES = [
16
+ {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
17
+ {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
18
+ {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
19
+ {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
20
+ {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
21
+ {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
22
+ {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
23
+ {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
24
+ {:id => 9, :name => "five", :parent_id => nil, :position => 5},
25
+ {:id => 10, :name => "four", :parent_id => nil, :position => 4},
26
+ {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
27
+ {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
28
+ ]
29
+
30
+ DB.create_table :lorems do
31
+ primary_key :id
32
+ String :name
33
+ Integer :ipsum_id
34
+ Integer :neque
53
35
  end
36
+
37
+ LOREMS = [
38
+ {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
39
+ {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
40
+ {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
41
+ {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
42
+ ]
43
+
44
+ NODES.each{|node| DB[:nodes].insert(node)}
45
+ LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
46
+
47
+ describe Sequel::Export do
54
48
 
55
- it "should export selected" do
56
- DB[:nodes].filter(:id < 3).select(:id, :name).export.should == "id\tname\n1\tone\n2\ttwo"
49
+ it "should instantiate" do
50
+ DB[:nodes].all.size.should == 12
51
+ end
52
+
53
+ it "should export everything" do
54
+ mem_stream = StringIO.new("", "w+")
55
+ DB[:nodes].export(mem_stream)
56
+ mem_stream.pos = 0
57
+ mem_stream.read.should == <<-TEXT
58
+ "id" "name" "parent_id" "position"
59
+ 1 "one" "" 1
60
+ 2 "two" "" 2
61
+ 3 "three" "" 3
62
+ 4 "two.one" 2 1
63
+ 5 "two.two" 2 2
64
+ 6 "two.two.one" 5 1
65
+ 7 "one.two" 1 2
66
+ 8 "one.one" 1 1
67
+ 9 "five" "" 5
68
+ 10 "four" "" 4
69
+ 11 "five.one" 9 1
70
+ 12 "two.three" 2 3
71
+ TEXT
72
+ end
73
+
74
+ it "should export everything with comma delimiter" do
75
+ mem_stream = StringIO.new("", "w+")
76
+ DB[:nodes].export(mem_stream, :delimiter => ',')
77
+ mem_stream.pos = 0
78
+ mem_stream.read.should == <<-TEXT
79
+ "id","name","parent_id","position"
80
+ 1,"one","",1
81
+ 2,"two","",2
82
+ 3,"three","",3
83
+ 4,"two.one",2,1
84
+ 5,"two.two",2,2
85
+ 6,"two.two.one",5,1
86
+ 7,"one.two",1,2
87
+ 8,"one.one",1,1
88
+ 9,"five","",5
89
+ 10,"four","",4
90
+ 11,"five.one",9,1
91
+ 12,"two.three",2,3
92
+ TEXT
93
+ end
94
+
95
+ it "should export everything with comma delimiter and no quote characters" do
96
+ mem_stream = StringIO.new("", "w+")
97
+ DB[:nodes].export(mem_stream, :delimiter => ',', :quote_char => '')
98
+ mem_stream.pos = 0
99
+ mem_stream.read.should == <<-TEXT
100
+ id,name,parent_id,position
101
+ 1,one,,1
102
+ 2,two,,2
103
+ 3,three,,3
104
+ 4,two.one,2,1
105
+ 5,two.two,2,2
106
+ 6,two.two.one,5,1
107
+ 7,one.two,1,2
108
+ 8,one.one,1,1
109
+ 9,five,,5
110
+ 10,four,,4
111
+ 11,five.one,9,1
112
+ 12,two.three,2,3
113
+ TEXT
114
+ end
115
+
116
+ it "should export selected" do
117
+ mem_stream = StringIO.new("", "w+")
118
+ DB[:nodes].filter(:id < 3).select(:id, :name).export(mem_stream)
119
+ mem_stream.pos = 0
120
+ mem_stream.read.should == "\"id\"\t\"name\"\n1\t\"one\"\n2\t\"two\"\n"
121
+ end
122
+
123
+ it "should not export headers" do
124
+ mem_stream = StringIO.new("", "w+")
125
+ DB[:nodes].export(mem_stream, :headers => false)
126
+ mem_stream.pos = 0
127
+ mem_stream.read.should == <<-TEXT
128
+ 1 "one" "" 1
129
+ 2 "two" "" 2
130
+ 3 "three" "" 3
131
+ 4 "two.one" 2 1
132
+ 5 "two.two" 2 2
133
+ 6 "two.two.one" 5 1
134
+ 7 "one.two" 1 2
135
+ 8 "one.one" 1 1
136
+ 9 "five" "" 5
137
+ 10 "four" "" 4
138
+ 11 "five.one" 9 1
139
+ 12 "two.three" 2 3
140
+ TEXT
141
+ end
142
+
143
+ it "should explicitly export headers" do
144
+ mem_stream = StringIO.new("", "w+")
145
+ DB[:nodes].export(mem_stream, :headers => true)
146
+ mem_stream.pos = 0
147
+ mem_stream.read.should == <<-TEXT
148
+ "id" "name" "parent_id" "position"
149
+ 1 "one" "" 1
150
+ 2 "two" "" 2
151
+ 3 "three" "" 3
152
+ 4 "two.one" 2 1
153
+ 5 "two.two" 2 2
154
+ 6 "two.two.one" 5 1
155
+ 7 "one.two" 1 2
156
+ 8 "one.one" 1 1
157
+ 9 "five" "" 5
158
+ 10 "four" "" 4
159
+ 11 "five.one" 9 1
160
+ 12 "two.three" 2 3
161
+ TEXT
162
+ end
57
163
  end
58
- end
164
+ end
@@ -1,157 +1,159 @@
1
1
  require 'helper'
2
2
 
3
- DB = Sequel.sqlite
3
+ module SequelTreeTest
4
+ DB = Sequel.sqlite
4
5
 
5
- DB.create_table :nodes do
6
- primary_key :id
7
- String :name
8
- Integer :parent_id
9
- Integer :position
10
- end
6
+ DB.create_table :nodes do
7
+ primary_key :id
8
+ String :name
9
+ Integer :parent_id
10
+ Integer :position
11
+ end
11
12
 
12
- NODES = [
13
- {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
14
- {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
15
- {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
16
- {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
17
- {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
18
- {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
19
- {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
20
- {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
21
- {:id => 9, :name => "five", :parent_id => nil, :position => 5},
22
- {:id => 10, :name => "four", :parent_id => nil, :position => 4},
23
- {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
24
- {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
25
- ]
13
+ NODES = [
14
+ {:id => 1, :name => 'one', :parent_id => nil, :position => 1},
15
+ {:id => 2, :name => 'two', :parent_id => nil, :position => 2},
16
+ {:id => 3, :name => 'three', :parent_id => nil, :position => 3},
17
+ {:id => 4, :name => "two.one", :parent_id => 2, :position => 1},
18
+ {:id => 5, :name => "two.two", :parent_id => 2, :position => 2},
19
+ {:id => 6, :name => "two.two.one", :parent_id => 5, :position => 1},
20
+ {:id => 7, :name => "one.two", :parent_id => 1, :position => 2},
21
+ {:id => 8, :name => "one.one", :parent_id => 1, :position => 1},
22
+ {:id => 9, :name => "five", :parent_id => nil, :position => 5},
23
+ {:id => 10, :name => "four", :parent_id => nil, :position => 4},
24
+ {:id => 11, :name => "five.one", :parent_id => 9, :position => 1},
25
+ {:id => 12, :name => "two.three", :parent_id => 2, :position => 3},
26
+ ]
26
27
 
27
- DB.create_table :lorems do
28
- primary_key :id
29
- String :name
30
- Integer :ipsum_id
31
- Integer :neque
32
- end
28
+ DB.create_table :lorems do
29
+ primary_key :id
30
+ String :name
31
+ Integer :ipsum_id
32
+ Integer :neque
33
+ end
33
34
 
34
- LOREMS = [
35
- {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
36
- {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
37
- {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
38
- {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
39
- ]
35
+ LOREMS = [
36
+ {:id => 1, :name => 'Lorem', :ipsum_id => nil, :neque => 4},
37
+ {:id => 2, :name => 'Ipsum', :ipsum_id => nil, :neque => 3},
38
+ {:id => 4, :name => "Neque", :ipsum_id => 2, :neque => 2},
39
+ {:id => 5, :name => "Porro", :ipsum_id => 2, :neque => 1},
40
+ ]
40
41
 
41
- NODES.each{|node| DB[:nodes].insert(node)}
42
- LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
42
+ NODES.each{|node| DB[:nodes].insert(node)}
43
+ LOREMS.each{|lorem| DB[:lorems].insert(lorem)}
43
44
 
44
- class Node < Sequel::Model
45
- plugin :tree
46
- end
45
+ class Node < Sequel::Model
46
+ plugin :tree
47
+ end
47
48
 
48
- class NaturalNode < Sequel::Model(:nodes)
49
- plugin :tree
50
- end
49
+ class NaturalNode < Sequel::Model(:nodes)
50
+ plugin :tree
51
+ end
51
52
 
52
- class OrderedNode < Sequel::Model(:nodes)
53
- plugin :tree, :order => :position
54
- end
53
+ class OrderedNode < Sequel::Model(:nodes)
54
+ plugin :tree, :order => :position
55
+ end
55
56
 
56
- class Lorem < Sequel::Model
57
- plugin :tree, :key => :ipsum_id, :order => :neque
58
- end
57
+ class Lorem < Sequel::Model
58
+ plugin :tree, :key => :ipsum_id, :order => :neque
59
+ end
59
60
 
60
- describe Sequel::Plugins::Tree do
61
+ describe Sequel::Plugins::Tree do
61
62
 
62
- it "should instantiate" do
63
- Node.all.size.should == 12
64
- end
63
+ it "should instantiate" do
64
+ Node.all.size.should == 12
65
+ end
65
66
 
66
- it "should find top level nodes" do
67
- Node.roots.count.should == 5
68
- end
67
+ it "should find top level nodes" do
68
+ Node.roots.count.should == 5
69
+ end
69
70
 
70
- it "should find all descendants of a node" do
71
- two = Node.find(:id => 2)
72
- two.name.should == "two"
73
- two.descendants.map{|m| m[:id]}.should == [4, 5, 12]
74
- end
71
+ it "should find all descendants of a node" do
72
+ two = Node.find(:id => 2)
73
+ two.name.should == "two"
74
+ two.descendants.map{|m| m[:id]}.should == [4, 5, 12]
75
+ end
75
76
 
76
- it "should find all ancestors of a node" do
77
- twotwoone = Node.find(:id => 6)
78
- twotwoone.name.should == "two.two.one"
79
- twotwoone.ancestors.map{|m| m[:id]}.should == [5, 2]
80
- end
77
+ it "should find all ancestors of a node" do
78
+ twotwoone = Node.find(:id => 6)
79
+ twotwoone.name.should == "two.two.one"
80
+ twotwoone.ancestors.map{|m| m[:id]}.should == [5, 2]
81
+ end
81
82
 
82
- it "should find all siblings of a node, excepting self" do
83
- twoone = Node.find(:id => 4)
84
- twoone.name.should == "two.one"
85
- twoone.siblings.map{|m| m[:id]}.should == [5, 12]
86
- end
83
+ it "should find all siblings of a node, excepting self" do
84
+ twoone = Node.find(:id => 4)
85
+ twoone.name.should == "two.one"
86
+ twoone.siblings.map{|m| m[:id]}.should == [5, 12]
87
+ end
87
88
 
88
- it "should find all siblings of a node, including self" do
89
- twoone = Node.find(:id => 4)
90
- twoone.name.should == "two.one"
91
- twoone.self_and_siblings.map{|m| m[:id]}.should == [4, 5, 12]
92
- end
89
+ it "should find all siblings of a node, including self" do
90
+ twoone = Node.find(:id => 4)
91
+ twoone.name.should == "two.one"
92
+ twoone.self_and_siblings.map{|m| m[:id]}.should == [4, 5, 12]
93
+ end
93
94
 
94
- it "should find siblings for root nodes" do
95
- three = Node.find(:id => 3)
96
- three.name.should == "three"
97
- three.self_and_siblings.map{|m| m[:id]}.should == [1, 2, 3, 9, 10]
98
- end
95
+ it "should find siblings for root nodes" do
96
+ three = Node.find(:id => 3)
97
+ three.name.should == "three"
98
+ three.self_and_siblings.map{|m| m[:id]}.should == [1, 2, 3, 9, 10]
99
+ end
99
100
 
100
- it "should find correct root for a node" do
101
- twotwoone = Node.find(:id => 6)
102
- twotwoone.name.should == "two.two.one"
103
- twotwoone.root[:id].should == 2
101
+ it "should find correct root for a node" do
102
+ twotwoone = Node.find(:id => 6)
103
+ twotwoone.name.should == "two.two.one"
104
+ twotwoone.root[:id].should == 2
104
105
 
105
- three = Node.find(:id => 3)
106
- three.name.should == "three"
107
- three.root[:id].should == 3
106
+ three = Node.find(:id => 3)
107
+ three.name.should == "three"
108
+ three.root[:id].should == 3
108
109
 
109
- fiveone = Node.find(:id => 11)
110
- fiveone.name.should == "five.one"
111
- fiveone.root[:id].should == 9
112
- end
113
-
114
- describe "Nodes in natural database order" do
115
- it "iterate top-level nodes in natural database order" do
116
- NaturalNode.roots.count.should == 5
117
- NaturalNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 5, 4]
110
+ fiveone = Node.find(:id => 11)
111
+ fiveone.name.should == "five.one"
112
+ fiveone.root[:id].should == 9
118
113
  end
114
+
115
+ describe "Nodes in natural database order" do
116
+ it "iterate top-level nodes in natural database order" do
117
+ NaturalNode.roots.count.should == 5
118
+ NaturalNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 5, 4]
119
+ end
119
120
 
120
- it "should have children" do
121
- one = NaturalNode.find(:id => 1)
122
- one.name.should == "one"
123
- one.children.count.should == 2
124
- end
121
+ it "should have children" do
122
+ one = NaturalNode.find(:id => 1)
123
+ one.name.should == "one"
124
+ one.children.count.should == 2
125
+ end
125
126
 
126
- it "children should be natural database order" do
127
- one = NaturalNode.find(:id => 1)
128
- one.name.should == "one"
129
- one.children.map{|m| m[:position]}.should == [2, 1]
127
+ it "children should be natural database order" do
128
+ one = NaturalNode.find(:id => 1)
129
+ one.name.should == "one"
130
+ one.children.map{|m| m[:position]}.should == [2, 1]
131
+ end
130
132
  end
131
- end
132
133
 
133
- describe "Nodes in specified order" do
134
- it "iterate top-level nodes in order by position" do
135
- OrderedNode.roots.count.should == 5
136
- OrderedNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 4, 5]
137
- end
134
+ describe "Nodes in specified order" do
135
+ it "iterate top-level nodes in order by position" do
136
+ OrderedNode.roots.count.should == 5
137
+ OrderedNode.roots.inject([]){|ids, p| ids << p.position}.should == [1, 2, 3, 4, 5]
138
+ end
138
139
 
139
- it "children should be in specified order" do
140
- one = OrderedNode.find(:id => 1)
141
- one.name.should == "one"
142
- one.children.map{|m| m[:position]}.should == [1, 2]
140
+ it "children should be in specified order" do
141
+ one = OrderedNode.find(:id => 1)
142
+ one.name.should == "one"
143
+ one.children.map{|m| m[:position]}.should == [1, 2]
144
+ end
143
145
  end
144
- end
145
146
 
146
- describe "Lorems in specified order" do
147
- it "iterate top-level nodes in order by position" do
148
- Lorem.roots.count.should == 2
149
- Lorem.roots.inject([]){|ids, p| ids << p.neque}.should == [3, 4]
150
- end
147
+ describe "Lorems in specified order" do
148
+ it "iterate top-level nodes in order by position" do
149
+ Lorem.roots.count.should == 2
150
+ Lorem.roots.inject([]){|ids, p| ids << p.neque}.should == [3, 4]
151
+ end
151
152
 
152
- it "children should be specified order" do
153
- one = Lorem.find(:id => 2)
154
- one.children.map{|m| m[:neque]}.should == [1, 2]
153
+ it "children should be specified order" do
154
+ one = Lorem.find(:id => 2)
155
+ one.children.map{|m| m[:neque]}.should == [1, 2]
156
+ end
155
157
  end
156
158
  end
157
- end
159
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lang
@@ -45,6 +45,7 @@ files:
45
45
  - LICENSE
46
46
  - README.md
47
47
  - Rakefile
48
+ - lib/extensions/export.rb
48
49
  - lib/sequel_plus.rb
49
50
  - lib/sequel_tree.rb
50
51
  - test/helper.rb