Permalink
Browse files

Improved code coverage - now at 99.2%. Fixed String#to_time to raise …

…error correctly for invalid time stamps. Version 0.5.0.2.
  • Loading branch information...
ciconia committed Jan 1, 2008
1 parent 65a863f commit ce46f77df425d61fc071a10f951069e75c5f57c4
View
@@ -1,3 +1,9 @@
+=== 0.5.0.2 (2007-01-01)
+
+* Fixed String#to_time to raise error correctly for invalid time stamps.
+
+* Improved code coverage - now at 99.2%.
+
=== 0.5.0.1 (2007-12-31)
* Added a stub for Sequel::Model that auto-loads sequel_model.
View
@@ -9,7 +9,7 @@ include FileUtils
# Configuration
##############################################################################
NAME = "sequel"
-VERS = "0.5.0.1"
+VERS = "0.5.0.2"
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
RDOC_OPTS = [
"--quiet",
@@ -50,7 +50,7 @@ def to_time
begin
Time.parse(self)
rescue Exception => e
- raise Error::InvalidValue, "Invalid time value '#{self}' (#{e.message})"
+ raise Sequel::Error::InvalidValue, "Invalid time value '#{self}' (#{e.message})"
end
# Why does Time.parse('0000-00-00') bork and not return nil or some such?
end
@@ -140,9 +140,6 @@ def call_expr(e, b, opts)
r = eval_expr(e[3][1], b, opts)
if l.is_one_of?(Symbol, Sequel::SQL::Subscript)
l|r
- elsif l.is_one_of?(Symbol, Sequel::LiteralString, Sequel::SQL::Expression) || \
- r.is_one_of?(Symbol, Sequel::LiteralString, Sequel::SQL::Expression)
- "(#{literal(l)} #{op} #{literal(r)})".lit
else
ext_expr(e, b, opts)
end
@@ -72,57 +72,57 @@ def initialize(db, &block)
end
def add_column(name, type, opts = {})
- @operations << {
- :op => :add_column,
- :name => name,
- :type => type
+ @operations << { \
+ :op => :add_column, \
+ :name => name, \
+ :type => type \
}.merge(opts)
end
def drop_column(name)
- @operations << {
- :op => :drop_column,
- :name => name
+ @operations << { \
+ :op => :drop_column, \
+ :name => name \
}
end
def rename_column(name, new_name, opts = {})
- @operations << {
- :op => :rename_column,
- :name => name,
- :new_name => new_name
+ @operations << { \
+ :op => :rename_column, \
+ :name => name, \
+ :new_name => new_name \
}.merge(opts)
end
def set_column_type(name, type)
- @operations << {
- :op => :set_column_type,
- :name => name,
- :type => type
+ @operations << { \
+ :op => :set_column_type, \
+ :name => name, \
+ :type => type \
}
end
def set_column_default(name, default)
- @operations << {
- :op => :set_column_default,
- :name => name,
- :default => default
+ @operations << { \
+ :op => :set_column_default, \
+ :name => name, \
+ :default => default \
}
end
def add_index(columns, opts = {})
columns = [columns] unless columns.is_a?(Array)
- @operations << {
- :op => :add_index,
- :columns => columns
+ @operations << { \
+ :op => :add_index, \
+ :columns => columns \
}.merge(opts)
end
def drop_index(columns)
columns = [columns] unless columns.is_a?(Array)
- @operations << {
- :op => :drop_index,
- :columns => columns
+ @operations << { \
+ :op => :drop_index, \
+ :columns => columns \
}
end
end
@@ -534,11 +534,146 @@ def fetch_rows(sql, &block)
@ds.set_model(Hash)
end
+ specify "should work correctly with dataset with transforms" do
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
+ Sequel.use_array_tuples
+
+ @ds.transform(:a => [proc {|x| x + 10}, proc {|x| x - 10}])
+ a = @ds.first
+ a.class.should == Array
+ a[:a].should == 11
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+
+ a = @ds.all[0]
+ a.class.should == Array
+ a[:a].should == 11
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+ end
+
+ specify "should work correctly with dataset with model" do
+ ccc = Class.new do
+ attr_reader :values
+ def initialize(v)
+ @values = v
+ end
+ end
+
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
+ Sequel.use_array_tuples
+
+ @ds.set_model(ccc)
+ a = @ds.first
+ a.class.should == ccc
+ a.values.class.should == Array
+ a.values[:a].should == 1
+ a.values[:b].should == 2
+ a.values[:c].should == 3
+ a.values[:d].should == nil
+
+ a = @ds.all[0]
+ a.class.should == ccc
+ a.values.class.should == Array
+ a.values[:a].should == 1
+ a.values[:b].should == 2
+ a.values[:c].should == 3
+ a.values[:d].should == nil
+
+ @ds.each(:naked => true) do |a|
+ a.class.should == Array
+ a[:a].should == 1
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+ end
+ end
+
+ specify "should work correctly with dataset with model and transform" do
+ ccc = Class.new do
+ attr_reader :values
+ def initialize(v)
+ @values = v
+ end
+ end
+
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
+ Sequel.use_array_tuples
+
+ @ds.transform(:a => [proc {|x| x + 10}, proc {|x| x - 10}])
+ @ds.set_model(ccc)
+ a = @ds.first
+ a.class.should == ccc
+ a.values.class.should == Array
+ a.values[:a].should == 11
+ a.values[:b].should == 2
+ a.values[:c].should == 3
+ a.values[:d].should == nil
+
+ a = @ds.all[0]
+ a.class.should == ccc
+ a.values.class.should == Array
+ a.values[:a].should == 11
+ a.values[:b].should == 2
+ a.values[:c].should == 3
+ a.values[:d].should == nil
+
+ @ds.each(:naked => true) do |a|
+ a.class.should == Array
+ a[:a].should == 11
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+ end
+ end
+
+ specify "should work correctly with denuded dataset" do
+ ccc = Class.new do
+ attr_reader :values
+ def initialize(v)
+ @values = v
+ end
+ end
+
+ @ds.first.should == {:a => 1, :b => 2, :c => 3}
+ Sequel.use_array_tuples
+
+ @ds.set_model(ccc)
+ @ds.set_model(nil)
+
+ a = @ds.first
+ a.class.should == Array
+ a[:a].should == 1
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+
+ a = @ds.all[0]
+ a.class.should == Array
+ a[:a].should == 1
+ a[:b].should == 2
+ a[:c].should == 3
+ a[:d].should == nil
+ end
+
specify "should be reversible using Sequel.use_hash_tuples" do
Sequel.use_array_tuples
@ds.first.class.should == Array
Sequel.use_hash_tuples
@ds.first.should == {:a => 1, :b => 2, :c => 3}
end
+
+ specify "should apply and unapply correctly to dataset with array_tuples_fetch_rows" do
+ @c.class_def(:fetch_rows) {'yo hash'}
+ @c.class_def(:array_tuples_fetch_rows) {'yo array'}
+ Sequel.use_array_tuples
+
+ @ds.fetch_rows.should == 'yo array'
+
+ Sequel.use_hash_tuples
+ @ds.fetch_rows.should == 'yo hash'
+ end
end
@@ -8,13 +8,6 @@
end
end
-context "String#to_time" do
- specify "should convert the string into a Time object" do
- "2007-07-11".to_time.should == Time.parse("2007-07-11")
- "06:30".to_time.should == Time.parse("06:30")
- end
-end
-
context "Range#interval" do
specify "should return the interval between the beginning and end of the range" do
(1..10).interval.should == 9
View
@@ -288,3 +288,14 @@ def quote_column_ref(c); "`#{c}`"; end
end
end
+context "String#to_time" do
+ specify "should convert the string into a Time object" do
+ "2007-07-11".to_time.should == Time.parse("2007-07-11")
+ "06:30".to_time.should == Time.parse("06:30")
+ end
+
+ specify "should raise Error::InvalidValue for an invalid time" do
+ proc {'0000-00-00'.to_time}.should raise_error(Sequel::Error::InvalidValue)
+ end
+end
+
View
@@ -557,6 +557,20 @@ class CCC < Sequel::Database
end
end
+context "A broken adapter (lib is there but the class is not)" do
+ setup do
+ FileUtils.touch('lib/sequel/adapters/blah.rb')
+ end
+
+ teardown do
+ FileUtils.rm('lib/sequel/adapters/blah.rb')
+ end
+
+ specify "should raise an error" do
+ proc {Sequel.connect('blah://blow')}.should raise_error(Sequel::Error::AdapterNotFound)
+ end
+end
+
context "Database#uri_to_options" do
specify "should convert a URI to an options hash" do
h = Sequel::Database.uri_to_options(URI.parse('ttt://uuu:ppp@192.168.60.1:1234/blah'))
@@ -785,4 +799,13 @@ def fetch_rows(sql); yield({:sql => sql}); end
end
end
-
+# TODO: beaf this up with specs for all supported ops
+context "Database#alter_table_sql" do
+ setup do
+ @db = DummyDatabase.new
+ end
+
+ specify "should raise error for an invalid op" do
+ proc {@db.alter_table_sql(:mau, :op => :blah)}.should raise_error(Sequel::Error)
+ end
+end
Oops, something went wrong.

0 comments on commit ce46f77

Please sign in to comment.