sequel 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.0.1 (2008-06-04)
2
+
3
+ * Make the choice of Time or DateTime optional for typecasting :datetime types, default to Time (jeremyevans)
4
+
5
+ * Reload database schema for table when calling Model.create_table (jeremyevans)
6
+
1
7
  === 2.0.0 (2008-06-01)
2
8
 
3
9
  * Comprehensive update of all documentation (jeremyevans)
data/Rakefile CHANGED
@@ -9,8 +9,8 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "sequel"
12
- VERS = "2.0.0"
13
- SEQUEL_CORE_VERS= "2.0.0"
12
+ VERS = "2.0.1"
13
+ SEQUEL_CORE_VERS= "2.0.1"
14
14
  CLEAN.include ["**/.*.sw?", "pkg", ".config", "rdoc", "coverage"]
15
15
  RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', \
16
16
  'Sequel: The Database Toolkit for Ruby: Model Classes', '--main', 'README']
@@ -326,7 +326,7 @@ module Sequel
326
326
  # Get the schema from the database, fall back on checking the columns
327
327
  # via the database if that will return inaccurate results or if
328
328
  # it raises an error.
329
- def self.get_db_schema # :nodoc:
329
+ def self.get_db_schema(reload = false) # :nodoc:
330
330
  set_columns(nil)
331
331
  return nil unless @dataset
332
332
  schema_hash = {}
@@ -334,7 +334,7 @@ module Sequel
334
334
  single_table = ds_opts[:from] && (ds_opts[:from].length == 1) \
335
335
  && !ds_opts.include?(:join) && !ds_opts.include?(:sql)
336
336
  get_columns = proc{columns rescue []}
337
- if single_table && (schema_array = (db.schema(table_name) rescue nil))
337
+ if single_table && (schema_array = (db.schema(table_name, :reload=>reload) rescue nil))
338
338
  schema_array.each{|k,v| schema_hash[k] = v}
339
339
  if ds_opts.include?(:select)
340
340
  # Dataset only selects certain columns, delete the other
@@ -3,7 +3,7 @@ module Sequel
3
3
  # Creates table.
4
4
  def self.create_table
5
5
  db.create_table_sql_list(table_name, *schema.create_info).each {|s| db << s}
6
- @db_schema = get_db_schema unless @@lazy_load_schema
6
+ @db_schema = get_db_schema(true) unless @@lazy_load_schema
7
7
  columns
8
8
  end
9
9
 
@@ -509,7 +509,7 @@ context "Model.db_schema" do
509
509
 
510
510
  specify "should use the database's schema_for_table and set the columns" do
511
511
  d = @dataset.db
512
- def d.schema(table)
512
+ def d.schema(table, opts = {})
513
513
  [[:x, {:type=>:integer}], [:y, {:type=>:string}]]
514
514
  end
515
515
  @c.dataset = @dataset
@@ -520,7 +520,7 @@ context "Model.db_schema" do
520
520
  specify "should restrict the schema and columns for datasets with a :select option" do
521
521
  ds = @dataset.select(:x, :y___z)
522
522
  d = ds.db
523
- def d.schema(table)
523
+ def d.schema(table, opts = {})
524
524
  [[:x, {:type=>:integer}], [:y, {:type=>:string}]]
525
525
  end
526
526
  def @c.columns; [:x, :z]; end
@@ -701,6 +701,10 @@ describe Sequel::Model, "typecasting" do
701
701
  end
702
702
  end
703
703
 
704
+ teardown do
705
+ Sequel.time_class = Time
706
+ end
707
+
704
708
  specify "should not convert if typecasting is turned off" do
705
709
  @c.typecast_on_assignment = false
706
710
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:integer}})
@@ -828,25 +832,57 @@ describe Sequel::Model, "typecasting" do
828
832
  proc{@c.new.x = 'a'}.should raise_error
829
833
  end
830
834
 
831
- specify "should convert to date for a datetime field" do
835
+ specify "should convert to time for a time field" do
836
+ @c.instance_variable_set(:@db_schema, {:x=>{:type=>:time}})
837
+ m = @c.new
838
+ x = '10:20:30'
839
+ y = x.to_time
840
+ m.x = x
841
+ m.x.should == y
842
+ m.x = y
843
+ m.x.should == y
844
+ end
845
+
846
+ specify "should raise an error if invalid data is used in a time field" do
847
+ @c.instance_variable_set(:@db_schema, {:x=>{:type=>:time}})
848
+ proc{@c.new.x = '0000'}.should raise_error
849
+ proc{@c.new.x = 'a'}.should_not raise_error # Valid Time
850
+ proc{@c.new.x = '2008-10-21'.to_date}.should raise_error
851
+ proc{@c.new.x = '2008-10-21'.to_datetime}.should raise_error
852
+ end
853
+
854
+ specify "should convert to the Sequel.time_class for a datetime field" do
832
855
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:datetime}})
833
856
  m = @c.new
834
- m.x = '2007-10-21 10:20:30'
835
- m.x.should == '2007-10-21 10:20:30'.to_datetime
836
- y = DateTime.new(2007,10,21,10,20,30)
837
- m.x = '2007-10-21 10:20:30'
857
+ x = '2007-10-21T10:20:30-07:00'
858
+ y = x.to_time
859
+ m.x = x
838
860
  m.x.should == y
839
- m.x = '2007-10-21 10:20:30'.to_datetime
861
+ m.x = x.to_datetime
840
862
  m.x.should == y
841
- m.x = '2007-10-21 10:20:30'.to_time
863
+ m.x = x.to_time
842
864
  m.x.should == y
843
865
  m.x = '2007-10-21'.to_date
844
- m.x.should == DateTime.new(2007,10,21)
866
+ m.x.should == '2007-10-21'.to_time
867
+ Sequel.time_class = DateTime
868
+ y = x.to_datetime
869
+ m.x = x
870
+ m.x.should == y
871
+ m.x = x.to_datetime
872
+ m.x.should == y
873
+ m.x = x.to_time
874
+ m.x.should == y
875
+ m.x = '2007-10-21'.to_date
876
+ m.x.should == '2007-10-21'.to_datetime
845
877
  end
846
878
 
847
879
  specify "should raise an error if invalid data is used in a datetime field" do
848
880
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:datetime}})
849
- proc{@c.new.x = 'a'}.should raise_error
881
+ proc{@c.new.x = '0000'}.should raise_error
882
+ proc{@c.new.x = ''}.should_not raise_error # Valid Time
883
+ Sequel.time_class = DateTime
884
+ proc{@c.new.x = '0000'}.should raise_error
885
+ proc{@c.new.x = ''}.should raise_error
850
886
  end
851
887
 
852
888
  end
@@ -26,6 +26,10 @@ class MockDataset < Sequel::Dataset
26
26
  @db.execute(sql)
27
27
  yield({:id => 1, :x => 1})
28
28
  end
29
+
30
+ def quoted_identifier(c)
31
+ "\"#{c}\""
32
+ end
29
33
  end
30
34
 
31
35
  class MockDatabase < Sequel::Database
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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-01 00:00:00 -07:00
12
+ date: 2008-06-04 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - "="
21
21
  - !ruby/object:Gem::Version
22
- version: 2.0.0
22
+ version: 2.0.1
23
23
  version:
24
24
  description: "The Database Toolkit for Ruby: Model Classes"
25
25
  email: code@jeremyevans.net