sequel 0.5.0.1 → 0.5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.5.0.2 (2007-01-01)
2
+
3
+ * Fixed String#to_time to raise error correctly for invalid time stamps.
4
+
5
+ * Improved code coverage - now at 99.2%.
6
+
1
7
  === 0.5.0.1 (2007-12-31)
2
8
 
3
9
  * Added a stub for Sequel::Model that auto-loads sequel_model.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "sequel"
12
- VERS = "0.5.0.1"
12
+ VERS = "0.5.0.2"
13
13
  CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
14
14
  RDOC_OPTS = [
15
15
  "--quiet",
@@ -50,7 +50,7 @@ class String
50
50
  begin
51
51
  Time.parse(self)
52
52
  rescue Exception => e
53
- raise Error::InvalidValue, "Invalid time value '#{self}' (#{e.message})"
53
+ raise Sequel::Error::InvalidValue, "Invalid time value '#{self}' (#{e.message})"
54
54
  end
55
55
  # Why does Time.parse('0000-00-00') bork and not return nil or some such?
56
56
  end
@@ -140,9 +140,6 @@ class Sequel::Dataset
140
140
  r = eval_expr(e[3][1], b, opts)
141
141
  if l.is_one_of?(Symbol, Sequel::SQL::Subscript)
142
142
  l|r
143
- elsif l.is_one_of?(Symbol, Sequel::LiteralString, Sequel::SQL::Expression) || \
144
- r.is_one_of?(Symbol, Sequel::LiteralString, Sequel::SQL::Expression)
145
- "(#{literal(l)} #{op} #{literal(r)})".lit
146
143
  else
147
144
  ext_expr(e, b, opts)
148
145
  end
@@ -72,57 +72,57 @@ module Sequel
72
72
  end
73
73
 
74
74
  def add_column(name, type, opts = {})
75
- @operations << {
76
- :op => :add_column,
77
- :name => name,
78
- :type => type
75
+ @operations << { \
76
+ :op => :add_column, \
77
+ :name => name, \
78
+ :type => type \
79
79
  }.merge(opts)
80
80
  end
81
81
 
82
82
  def drop_column(name)
83
- @operations << {
84
- :op => :drop_column,
85
- :name => name
83
+ @operations << { \
84
+ :op => :drop_column, \
85
+ :name => name \
86
86
  }
87
87
  end
88
88
 
89
89
  def rename_column(name, new_name, opts = {})
90
- @operations << {
91
- :op => :rename_column,
92
- :name => name,
93
- :new_name => new_name
90
+ @operations << { \
91
+ :op => :rename_column, \
92
+ :name => name, \
93
+ :new_name => new_name \
94
94
  }.merge(opts)
95
95
  end
96
96
 
97
97
  def set_column_type(name, type)
98
- @operations << {
99
- :op => :set_column_type,
100
- :name => name,
101
- :type => type
98
+ @operations << { \
99
+ :op => :set_column_type, \
100
+ :name => name, \
101
+ :type => type \
102
102
  }
103
103
  end
104
104
 
105
105
  def set_column_default(name, default)
106
- @operations << {
107
- :op => :set_column_default,
108
- :name => name,
109
- :default => default
106
+ @operations << { \
107
+ :op => :set_column_default, \
108
+ :name => name, \
109
+ :default => default \
110
110
  }
111
111
  end
112
112
 
113
113
  def add_index(columns, opts = {})
114
114
  columns = [columns] unless columns.is_a?(Array)
115
- @operations << {
116
- :op => :add_index,
117
- :columns => columns
115
+ @operations << { \
116
+ :op => :add_index, \
117
+ :columns => columns \
118
118
  }.merge(opts)
119
119
  end
120
120
 
121
121
  def drop_index(columns)
122
122
  columns = [columns] unless columns.is_a?(Array)
123
- @operations << {
124
- :op => :drop_index,
125
- :columns => columns
123
+ @operations << { \
124
+ :op => :drop_index, \
125
+ :columns => columns \
126
126
  }
127
127
  end
128
128
  end
@@ -534,6 +534,130 @@ context "Sequel.use_array_tuples" do
534
534
  @ds.set_model(Hash)
535
535
  end
536
536
 
537
+ specify "should work correctly with dataset with transforms" do
538
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
539
+ Sequel.use_array_tuples
540
+
541
+ @ds.transform(:a => [proc {|x| x + 10}, proc {|x| x - 10}])
542
+ a = @ds.first
543
+ a.class.should == Array
544
+ a[:a].should == 11
545
+ a[:b].should == 2
546
+ a[:c].should == 3
547
+ a[:d].should == nil
548
+
549
+ a = @ds.all[0]
550
+ a.class.should == Array
551
+ a[:a].should == 11
552
+ a[:b].should == 2
553
+ a[:c].should == 3
554
+ a[:d].should == nil
555
+ end
556
+
557
+ specify "should work correctly with dataset with model" do
558
+ ccc = Class.new do
559
+ attr_reader :values
560
+ def initialize(v)
561
+ @values = v
562
+ end
563
+ end
564
+
565
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
566
+ Sequel.use_array_tuples
567
+
568
+ @ds.set_model(ccc)
569
+ a = @ds.first
570
+ a.class.should == ccc
571
+ a.values.class.should == Array
572
+ a.values[:a].should == 1
573
+ a.values[:b].should == 2
574
+ a.values[:c].should == 3
575
+ a.values[:d].should == nil
576
+
577
+ a = @ds.all[0]
578
+ a.class.should == ccc
579
+ a.values.class.should == Array
580
+ a.values[:a].should == 1
581
+ a.values[:b].should == 2
582
+ a.values[:c].should == 3
583
+ a.values[:d].should == nil
584
+
585
+ @ds.each(:naked => true) do |a|
586
+ a.class.should == Array
587
+ a[:a].should == 1
588
+ a[:b].should == 2
589
+ a[:c].should == 3
590
+ a[:d].should == nil
591
+ end
592
+ end
593
+
594
+ specify "should work correctly with dataset with model and transform" do
595
+ ccc = Class.new do
596
+ attr_reader :values
597
+ def initialize(v)
598
+ @values = v
599
+ end
600
+ end
601
+
602
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
603
+ Sequel.use_array_tuples
604
+
605
+ @ds.transform(:a => [proc {|x| x + 10}, proc {|x| x - 10}])
606
+ @ds.set_model(ccc)
607
+ a = @ds.first
608
+ a.class.should == ccc
609
+ a.values.class.should == Array
610
+ a.values[:a].should == 11
611
+ a.values[:b].should == 2
612
+ a.values[:c].should == 3
613
+ a.values[:d].should == nil
614
+
615
+ a = @ds.all[0]
616
+ a.class.should == ccc
617
+ a.values.class.should == Array
618
+ a.values[:a].should == 11
619
+ a.values[:b].should == 2
620
+ a.values[:c].should == 3
621
+ a.values[:d].should == nil
622
+
623
+ @ds.each(:naked => true) do |a|
624
+ a.class.should == Array
625
+ a[:a].should == 11
626
+ a[:b].should == 2
627
+ a[:c].should == 3
628
+ a[:d].should == nil
629
+ end
630
+ end
631
+
632
+ specify "should work correctly with denuded dataset" do
633
+ ccc = Class.new do
634
+ attr_reader :values
635
+ def initialize(v)
636
+ @values = v
637
+ end
638
+ end
639
+
640
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
641
+ Sequel.use_array_tuples
642
+
643
+ @ds.set_model(ccc)
644
+ @ds.set_model(nil)
645
+
646
+ a = @ds.first
647
+ a.class.should == Array
648
+ a[:a].should == 1
649
+ a[:b].should == 2
650
+ a[:c].should == 3
651
+ a[:d].should == nil
652
+
653
+ a = @ds.all[0]
654
+ a.class.should == Array
655
+ a[:a].should == 1
656
+ a[:b].should == 2
657
+ a[:c].should == 3
658
+ a[:d].should == nil
659
+ end
660
+
537
661
  specify "should be reversible using Sequel.use_hash_tuples" do
538
662
  Sequel.use_array_tuples
539
663
  @ds.first.class.should == Array
@@ -541,4 +665,15 @@ context "Sequel.use_array_tuples" do
541
665
  Sequel.use_hash_tuples
542
666
  @ds.first.should == {:a => 1, :b => 2, :c => 3}
543
667
  end
668
+
669
+ specify "should apply and unapply correctly to dataset with array_tuples_fetch_rows" do
670
+ @c.class_def(:fetch_rows) {'yo hash'}
671
+ @c.class_def(:array_tuples_fetch_rows) {'yo array'}
672
+ Sequel.use_array_tuples
673
+
674
+ @ds.fetch_rows.should == 'yo array'
675
+
676
+ Sequel.use_hash_tuples
677
+ @ds.fetch_rows.should == 'yo hash'
678
+ end
544
679
  end
@@ -8,13 +8,6 @@ context "Enumerable#send_each" do
8
8
  end
9
9
  end
10
10
 
11
- context "String#to_time" do
12
- specify "should convert the string into a Time object" do
13
- "2007-07-11".to_time.should == Time.parse("2007-07-11")
14
- "06:30".to_time.should == Time.parse("06:30")
15
- end
16
- end
17
-
18
11
  context "Range#interval" do
19
12
  specify "should return the interval between the beginning and end of the range" do
20
13
  (1..10).interval.should == 9
@@ -288,3 +288,14 @@ context "Symbol" do
288
288
  end
289
289
  end
290
290
 
291
+ context "String#to_time" do
292
+ specify "should convert the string into a Time object" do
293
+ "2007-07-11".to_time.should == Time.parse("2007-07-11")
294
+ "06:30".to_time.should == Time.parse("06:30")
295
+ end
296
+
297
+ specify "should raise Error::InvalidValue for an invalid time" do
298
+ proc {'0000-00-00'.to_time}.should raise_error(Sequel::Error::InvalidValue)
299
+ end
300
+ end
301
+
@@ -557,6 +557,20 @@ context "An unknown database scheme" do
557
557
  end
558
558
  end
559
559
 
560
+ context "A broken adapter (lib is there but the class is not)" do
561
+ setup do
562
+ FileUtils.touch('lib/sequel/adapters/blah.rb')
563
+ end
564
+
565
+ teardown do
566
+ FileUtils.rm('lib/sequel/adapters/blah.rb')
567
+ end
568
+
569
+ specify "should raise an error" do
570
+ proc {Sequel.connect('blah://blow')}.should raise_error(Sequel::Error::AdapterNotFound)
571
+ end
572
+ end
573
+
560
574
  context "Database#uri_to_options" do
561
575
  specify "should convert a URI to an options hash" do
562
576
  h = Sequel::Database.uri_to_options(URI.parse('ttt://uuu:ppp@192.168.60.1:1234/blah'))
@@ -785,4 +799,13 @@ context "Database#drop_view" do
785
799
  end
786
800
  end
787
801
 
788
-
802
+ # TODO: beaf this up with specs for all supported ops
803
+ context "Database#alter_table_sql" do
804
+ setup do
805
+ @db = DummyDatabase.new
806
+ end
807
+
808
+ specify "should raise error for an invalid op" do
809
+ proc {@db.alter_table_sql(:mau, :op => :blah)}.should raise_error(Sequel::Error)
810
+ end
811
+ end
data/spec/dataset_spec.rb CHANGED
@@ -1,13 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), "spec_helper")
2
2
 
3
- SQLITE_DB = Sequel("sqlite:/")
4
- SQLITE_DB.create_table :items do
5
- integer :id, :primary_key => true, :auto_increment => true
6
- text :name
7
- float :value
8
- end
9
- SQLITE_DB.create_table(:time) {timestamp :t}
10
-
11
3
  context "Dataset" do
12
4
  setup do
13
5
  @dataset = Sequel::Dataset.new("db")
@@ -1425,10 +1417,6 @@ context "Dataset#single_record" do
1425
1417
 
1426
1418
  @d = @c.new(nil).from(:test)
1427
1419
  @e = @cc.new(nil).from(:test)
1428
-
1429
- @d_empty = SQLITE_DB[:items]
1430
- @d_empty.delete # remove all records
1431
-
1432
1420
  end
1433
1421
 
1434
1422
  specify "should call each and return the first record" do
@@ -1440,7 +1428,7 @@ context "Dataset#single_record" do
1440
1428
  end
1441
1429
 
1442
1430
  specify "should return nil if no record is present" do
1443
- @d_empty.single_record.should be_nil
1431
+ @e.single_record.should be_nil
1444
1432
  end
1445
1433
  end
1446
1434
 
@@ -1451,9 +1439,12 @@ context "Dataset#single_value" do
1451
1439
  yield({1 => sql})
1452
1440
  end
1453
1441
  end
1442
+ @cc = Class.new(@c) do
1443
+ def fetch_rows(sql); end
1444
+ end
1445
+
1454
1446
  @d = @c.new(nil).from(:test)
1455
- @d_empty = SQLITE_DB[:items]
1456
- @d_empty.delete # remove all records
1447
+ @e = @cc.new(nil).from(:test)
1457
1448
  end
1458
1449
 
1459
1450
  specify "should call each and return the first value of the first record" do
@@ -1465,7 +1456,7 @@ context "Dataset#single_value" do
1465
1456
  end
1466
1457
 
1467
1458
  specify "should return nil" do
1468
- @d_empty.single_value.should be_nil
1459
+ @e.single_value.should be_nil
1469
1460
  end
1470
1461
 
1471
1462
  end
@@ -1741,11 +1732,15 @@ context "Dataset#destroy" do
1741
1732
  @d.set_model(@m)
1742
1733
  end
1743
1734
 
1744
- specify "should destroy raise for every model in the dataset" do
1735
+ specify "should call destroy for every model instance in the dataset" do
1745
1736
  count = @d.destroy
1746
1737
  count.should == 2
1747
1738
  DESTROYED.should == MODELS
1748
- end
1739
+ end
1740
+
1741
+ specify "should raise error if no models are associated with the dataset" do
1742
+ proc {@d.naked.destroy}.should raise_error(Sequel::Error)
1743
+ end
1749
1744
  end
1750
1745
 
1751
1746
  context "Dataset#<<" do
@@ -35,6 +35,14 @@ context "PrettyTable" do
35
35
  /\n(\|x\|y\|)|(\|y\|x\|)\n/
36
36
  end
37
37
 
38
+ specify "should infer columns from array with keys" do
39
+ a = [1, 2, 3]
40
+ a.keys = [:a, :b, :c]
41
+ Sequel::PrettyTable.print([a])
42
+ @output.rewind
43
+ @output.read.should =~ /\n\|a\|b\|c\|\n/
44
+ end
45
+
38
46
  specify "should calculate the maximum width of each column correctly" do
39
47
  Sequel::PrettyTable.print(@data2, [:a, :b])
40
48
  @output.rewind
@@ -57,4 +57,30 @@ describe Sequel::Schema::Generator do
57
57
  @indexes[1][:columns].should include(:title)
58
58
  @indexes[1][:columns].should include(:body)
59
59
  end
60
+ end
61
+
62
+ describe Sequel::Schema::AlterTableGenerator do
63
+ before :all do
64
+ @generator = Sequel::Schema::AlterTableGenerator.new(SchemaDummyDatabase.new) do
65
+ add_column :aaa, :text
66
+ drop_column :bbb
67
+ rename_column :ccc, :ho
68
+ set_column_type :ddd, :float
69
+ set_column_default :eee, 1
70
+ add_index [:fff, :ggg]
71
+ drop_index :hhh
72
+ end
73
+ end
74
+
75
+ specify "should generate operation records" do
76
+ @generator.operations.should == [
77
+ {:op => :add_column, :name => :aaa, :type => :text},
78
+ {:op => :drop_column, :name => :bbb},
79
+ {:op => :rename_column, :name => :ccc, :new_name => :ho},
80
+ {:op => :set_column_type, :name => :ddd, :type => :float},
81
+ {:op => :set_column_default, :name => :eee, :default => 1},
82
+ {:op => :add_index, :columns => [:fff, :ggg]},
83
+ {:op => :drop_index, :columns => [:hhh]}
84
+ ]
85
+ end
60
86
  end
data/spec/schema_spec.rb CHANGED
@@ -1,14 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- class SchemaDummyDatabase < Sequel::Database
4
- attr_reader :sqls
5
-
6
- def execute(sql)
7
- @sqls ||= []
8
- @sqls << sql
9
- end
10
- end
11
-
12
3
  context "DB#create_table" do
13
4
  setup do
14
5
  @db = SchemaDummyDatabase.new
@@ -237,4 +228,3 @@ context "DB#drop_table" do
237
228
  @db.sqls.should == ['DROP TABLE cats']
238
229
  end
239
230
  end
240
-
@@ -0,0 +1,10 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "Sequel::Model()" do
4
+ specify "should auto-load sequel_model and create a sequel model" do
5
+ db = Sequel::Database.new
6
+ Sequel::Model.instance_eval {@db = db}
7
+ c = Class.new(Sequel::Model(:items))
8
+ c.dataset.sql.should == "SELECT * FROM items"
9
+ end
10
+ end
@@ -327,6 +327,11 @@ context "Proc#to_sql" do
327
327
  proc {:units * :price}.to_sql.should == "(units * price)"
328
328
  end
329
329
 
330
+ specify "should support | operator" do
331
+ proc {(:x | 1) > 0}.to_sql.should == "(x[1] > 0)"
332
+ proc {10 | 1}.to_sql.should == 11
333
+ end
334
+
330
335
  specify "should support globals" do
331
336
  $aaaa_zzzz = 400
332
337
  proc {:x > $aaaa_zzzz}.to_sql.should == "(x > 400)"
data/spec/spec_helper.rb CHANGED
@@ -32,3 +32,13 @@ class MockDatabase < Sequel::Database
32
32
 
33
33
  def dataset; MockDataset.new(self); end
34
34
  end
35
+
36
+ class SchemaDummyDatabase < Sequel::Database
37
+ attr_reader :sqls
38
+
39
+ def execute(sql)
40
+ @sqls ||= []
41
+ @sqls << sql
42
+ end
43
+ end
44
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.1
4
+ version: 0.5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-31 00:00:00 +02:00
12
+ date: 2008-01-01 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -80,6 +80,7 @@ files:
80
80
  - spec/rcov.opts
81
81
  - spec/schema_generator_spec.rb
82
82
  - spec/schema_spec.rb
83
+ - spec/sequel_spec.rb
83
84
  - spec/sequelizer_spec.rb
84
85
  - spec/spec.opts
85
86
  - spec/spec_helper.rb