sequel 0.1.9.11 → 0.1.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +16 -2
- data/Rakefile +1 -1
- data/lib/sequel/model.rb +1 -1
- data/lib/sequel/pretty_table.rb +1 -1
- data/lib/sequel/schema/schema_generator.rb +5 -1
- data/spec/connection_pool_spec.rb +1 -1
- data/spec/core_ext_spec.rb +1 -1
- data/spec/database_spec.rb +1 -1
- data/spec/dataset_spec.rb +9 -1
- data/spec/expressions_spec.rb +1 -1
- data/spec/migration_spec.rb +14 -2
- data/spec/model_spec.rb +47 -0
- data/spec/pretty_table_spec.rb +58 -0
- data/spec/schema_generator_spec.rb +60 -0
- data/spec/schema_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -0
- metadata +7 -2
data/CHANGELOG
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
-
=== 0.
|
1
|
+
=== 0.1.9.12 (2007-08-26)
|
2
|
+
|
3
|
+
* Added spec for PrettyTable.
|
4
|
+
|
5
|
+
* Added specs for Schema::Generator and Model (#36 thanks technoweenie).
|
6
|
+
|
7
|
+
* Fixed Sequel::Model.set_schema (#36 thanks technoweenie.)
|
8
|
+
|
9
|
+
* Added support for no options on Schema::Generator#foreign_key (#36 thanks technoweenie.)
|
10
|
+
|
11
|
+
* Implemented (restored?) Schema::Generator#primary_key_name (#36 thanks technoweenie.)
|
12
|
+
|
13
|
+
* Better spec code coverage.
|
14
|
+
|
15
|
+
=== 0.1.9.11 (2007-08-24)
|
2
16
|
|
3
17
|
* Changed Dataset#set_model to allow supplying additional arguments to the model's initialize method (#35). Thanks Sunny Hirai.
|
4
18
|
|
5
|
-
=== 0.
|
19
|
+
=== 0.1.9.10 (2007-08-22)
|
6
20
|
|
7
21
|
* Changed schema generation code to generate separate statements for CREATE TABLE and each CREATE INDEX (#34).
|
8
22
|
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.1.9.
|
9
|
+
VERS = "0.1.9.12"
|
10
10
|
CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
|
11
11
|
RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
|
12
12
|
"--opname", "index.html",
|
data/lib/sequel/model.rb
CHANGED
@@ -64,7 +64,7 @@ module Sequel
|
|
64
64
|
|
65
65
|
def self.set_schema(name = nil, &block)
|
66
66
|
name ? set_table_name(name) : name = table_name
|
67
|
-
@schema = Schema::Generator.new(name, &block)
|
67
|
+
@schema = Schema::Generator.new(db, name, &block)
|
68
68
|
if @schema.primary_key_name
|
69
69
|
set_primary_key @schema.primary_key_name
|
70
70
|
end
|
data/lib/sequel/pretty_table.rb
CHANGED
@@ -14,6 +14,10 @@ module Sequel
|
|
14
14
|
column(name, type, opts)
|
15
15
|
end
|
16
16
|
|
17
|
+
def primary_key_name
|
18
|
+
@primary_key ? @primary_key[:name] : nil
|
19
|
+
end
|
20
|
+
|
17
21
|
def primary_key(name, type = nil, opts = nil)
|
18
22
|
@primary_key = @db.serial_primary_key_options.merge({
|
19
23
|
:name => name
|
@@ -27,7 +31,7 @@ module Sequel
|
|
27
31
|
@columns << {:name => name, :type => type}.merge(opts || {})
|
28
32
|
end
|
29
33
|
|
30
|
-
def foreign_key(name, opts)
|
34
|
+
def foreign_key(name, opts = nil)
|
31
35
|
@columns << {:name => name, :type => :integer}.merge(opts || {})
|
32
36
|
end
|
33
37
|
|
data/spec/core_ext_spec.rb
CHANGED
data/spec/database_spec.rb
CHANGED
data/spec/dataset_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
context "Dataset" do
|
4
4
|
setup do
|
@@ -1502,6 +1502,14 @@ context "Dataset#print" do
|
|
1502
1502
|
@output.read.should == \
|
1503
1503
|
"+-+-+\n|a|b|\n+-+-+\n|1|2|\n|3|4|\n|5|6|\n+-+-+\n"
|
1504
1504
|
end
|
1505
|
+
|
1506
|
+
specify "should default to the dataset's columns" do
|
1507
|
+
@dataset.meta_def(:columns) {[:a, :b]}
|
1508
|
+
@dataset.print
|
1509
|
+
@output.rewind
|
1510
|
+
@output.read.should == \
|
1511
|
+
"+-+-+\n|a|b|\n+-+-+\n|1|2|\n|3|4|\n|5|6|\n+-+-+\n"
|
1512
|
+
end
|
1505
1513
|
end
|
1506
1514
|
|
1507
1515
|
context "Dataset#multi_insert" do
|
data/spec/expressions_spec.rb
CHANGED
data/spec/migration_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
context "Migration classes" do
|
4
4
|
setup do
|
@@ -86,7 +86,7 @@ MIGRATION_001 = %[
|
|
86
86
|
create(1111)
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
89
|
+
def down
|
90
90
|
drop(1111)
|
91
91
|
end
|
92
92
|
end
|
@@ -174,6 +174,11 @@ context "Sequel::Migrator" do
|
|
174
174
|
[CreateSessions, CreateNodes, CreateUsers]
|
175
175
|
end
|
176
176
|
|
177
|
+
specify "should load the migration classes for the specified range" do
|
178
|
+
Sequel::Migrator.migration_classes('.', 0, 5, :down).should == \
|
179
|
+
[CreateAttributes, CreateUsers, CreateNodes, CreateSessions]
|
180
|
+
end
|
181
|
+
|
177
182
|
specify "should start from current + 1 for the up direction" do
|
178
183
|
Sequel::Migrator.migration_classes('.', 3, 1, :up).should == \
|
179
184
|
[CreateNodes, CreateUsers]
|
@@ -238,4 +243,11 @@ context "Sequel::Migrator" do
|
|
238
243
|
|
239
244
|
Sequel::Migrator.get_current_migration_version(@db).should == 5
|
240
245
|
end
|
246
|
+
|
247
|
+
specify "should apply migrations down to 0 version correctly" do
|
248
|
+
Sequel::Migrator.apply(@db, '.', 0, 5)
|
249
|
+
@db.drops.should == [5555, 3333, 2222, 1111]
|
250
|
+
|
251
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
252
|
+
end
|
241
253
|
end
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
Sequel::Model.db = SchemaDummyDatabase.new
|
4
|
+
|
5
|
+
describe Sequel::Model do
|
6
|
+
before do
|
7
|
+
@model = Class.new(Sequel::Model(:items))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "creates dynamic model subclass with set table name" do
|
11
|
+
@model.table_name.should == :items
|
12
|
+
end
|
13
|
+
|
14
|
+
it "defaults to primary key of id" do
|
15
|
+
@model.primary_key.should == :id
|
16
|
+
end
|
17
|
+
|
18
|
+
it "allow primary key change" do
|
19
|
+
@model.set_primary_key :ssn
|
20
|
+
@model.primary_key.should == :ssn
|
21
|
+
end
|
22
|
+
|
23
|
+
it "allows table name change" do
|
24
|
+
@model.set_table_name :foo
|
25
|
+
@model.table_name.should == :foo
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets schema with implicit table name" do
|
29
|
+
@model.set_schema do
|
30
|
+
primary_key :ssn, :string
|
31
|
+
end
|
32
|
+
@model.primary_key.should == :ssn
|
33
|
+
@model.table_name.should == :items
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets schema with explicit table name" do
|
37
|
+
@model.set_schema :foo do
|
38
|
+
primary_key :id
|
39
|
+
end
|
40
|
+
@model.primary_key.should == :id
|
41
|
+
@model.table_name.should == :foo
|
42
|
+
end
|
43
|
+
|
44
|
+
it "puts the lotion in the basket or it gets the hose again" do
|
45
|
+
# just kidding!
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
context "PrettyTable" do
|
6
|
+
setup do
|
7
|
+
@data1 = [
|
8
|
+
{:x => 3, :y => 4}
|
9
|
+
]
|
10
|
+
|
11
|
+
@data2 = [
|
12
|
+
{:a => 23, :b => 45},
|
13
|
+
{:a => 45, :b => 2377}
|
14
|
+
]
|
15
|
+
|
16
|
+
@data3 = [
|
17
|
+
{:aaa => 1},
|
18
|
+
{:bb => 2},
|
19
|
+
{:c => 3}
|
20
|
+
]
|
21
|
+
|
22
|
+
@output = StringIO.new
|
23
|
+
@orig_stdout = $stdout
|
24
|
+
$stdout = @output
|
25
|
+
end
|
26
|
+
|
27
|
+
teardown do
|
28
|
+
$stdout = @orig_stdout
|
29
|
+
end
|
30
|
+
|
31
|
+
specify "should infer the columns if not given" do
|
32
|
+
Sequel::PrettyTable.print(@data1)
|
33
|
+
@output.rewind
|
34
|
+
@output.read.should =~ \
|
35
|
+
/\n(\|x\|y\|)|(\|y\|x\|)\n/
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "should calculate the maximum width of each column correctly" do
|
39
|
+
Sequel::PrettyTable.print(@data2, [:a, :b])
|
40
|
+
@output.rewind
|
41
|
+
@output.read.should == \
|
42
|
+
"+--+----+\n|a |b |\n+--+----+\n|23|45 |\n|45|2377|\n+--+----+\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "should also take header width into account" do
|
46
|
+
Sequel::PrettyTable.print(@data3, [:aaa, :bb, :c])
|
47
|
+
@output.rewind
|
48
|
+
@output.read.should == \
|
49
|
+
"+---+--+-+\n|aaa|bb|c|\n+---+--+-+\n|1 | | |\n| |2 | |\n| | |3|\n+---+--+-+\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
specify "should print only the specified columns" do
|
53
|
+
Sequel::PrettyTable.print(@data2, [:a])
|
54
|
+
@output.rewind
|
55
|
+
@output.read.should == \
|
56
|
+
"+--+\n|a |\n+--+\n|23|\n|45|\n+--+\n"
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Sequel::Schema::Generator do
|
4
|
+
before :all do
|
5
|
+
@generator = Sequel::Schema::Generator.new(SchemaDummyDatabase.new, :items) do
|
6
|
+
string :title
|
7
|
+
column :body, :text
|
8
|
+
foreign_key :parent_id
|
9
|
+
primary_key :id
|
10
|
+
index :title
|
11
|
+
index [:title, :body]
|
12
|
+
end
|
13
|
+
@table_name, @columns, @indexes = @generator.create_info
|
14
|
+
end
|
15
|
+
|
16
|
+
{:name => :id, :primary_key => true}.each do |field, expected|
|
17
|
+
it "uses default primary key #{field}" do
|
18
|
+
@columns.first[field].should == expected
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "counts primary key as column" do
|
23
|
+
@columns.size.should == 4
|
24
|
+
end
|
25
|
+
|
26
|
+
it "places primary key first" do
|
27
|
+
@columns[0][:primary_key].should be_true
|
28
|
+
@columns[1][:primary_key].should_not be_true
|
29
|
+
@columns[2][:primary_key].should_not be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "retrieves primary key name" do
|
33
|
+
@generator.primary_key_name.should == :id
|
34
|
+
end
|
35
|
+
|
36
|
+
it "keeps columns in order" do
|
37
|
+
@columns[1][:name].should == :title
|
38
|
+
@columns[1][:type].should == :string
|
39
|
+
@columns[2][:name].should == :body
|
40
|
+
@columns[2][:type].should == :text
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates foreign key column" do
|
44
|
+
@columns[3][:name].should == :parent_id
|
45
|
+
@columns[3][:type].should == :integer
|
46
|
+
end
|
47
|
+
|
48
|
+
it "finds columns" do
|
49
|
+
[:title, :body, :parent_id, :id].each do |col|
|
50
|
+
@generator.has_column?(col).should be_true
|
51
|
+
end
|
52
|
+
@generator.has_column?(:foo).should_not be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates indexes" do
|
56
|
+
@indexes[0][:columns].should include(:title)
|
57
|
+
@indexes[1][:columns].should include(:title)
|
58
|
+
@indexes[1][:columns].should include(:body)
|
59
|
+
end
|
60
|
+
end
|
data/spec/schema_spec.rb
CHANGED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sequel
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.9.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.1.9.12
|
7
|
+
date: 2007-08-26 00:00:00 +03:00
|
8
8
|
summary: Lightweight ORM library for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- README
|
34
34
|
- Rakefile
|
35
35
|
- bin/sequel
|
36
|
+
- doc/rdoc
|
36
37
|
- spec/adapters
|
37
38
|
- spec/connection_pool_spec.rb
|
38
39
|
- spec/core_ext_spec.rb
|
@@ -40,7 +41,11 @@ files:
|
|
40
41
|
- spec/dataset_spec.rb
|
41
42
|
- spec/expressions_spec.rb
|
42
43
|
- spec/migration_spec.rb
|
44
|
+
- spec/model_spec.rb
|
45
|
+
- spec/pretty_table_spec.rb
|
46
|
+
- spec/schema_generator_spec.rb
|
43
47
|
- spec/schema_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
44
49
|
- spec/adapters/mysql_spec.rb
|
45
50
|
- spec/adapters/sqlite_spec.rb
|
46
51
|
- lib/sequel
|