Permalink
Browse files

Fixed error behavior when parse_tree or ruby2ruby are not available. …

…Fixed error behavior when sequel_model is not available. 100% code coverage.
  • Loading branch information...
1 parent ce46f77 commit 79dc455691b74edaaa91a1d4c9b788477c95486c @ciconia ciconia committed Jan 1, 2008
Showing with 84 additions and 8 deletions.
  1. +8 −0 core/CHANGELOG
  2. +2 −6 core/lib/sequel.rb
  3. +2 −2 core/lib/sequel/dataset/sequelizer.rb
  4. +13 −0 core/spec/sequel_spec.rb
  5. +59 −0 core/spec/sequelizer_spec.rb
View
@@ -1,3 +1,11 @@
+=== SVN
+
+* 100% code coverage.
+
+* Fixed error behavior when sequel_model is not available.
+
+* Fixed error behavior when parse_tree or ruby2ruby are not available.
+
=== 0.5.0.2 (2007-01-01)
* Fixed String#to_time to raise error correctly for invalid time stamps.
View
@@ -53,13 +53,9 @@ def method_missing(m, *args)
# stub for Sequel::Model()
def Model(*args)
require 'sequel_model'
- if respond_to?(:Model)
- send(:Model, *args)
- else
- raise LoadError
- end
+ send(:Model, *args)
rescue LoadError
- raise SequelError, "The sequel_model library could not be found. In order to use Sequel models please install sequel_model."
+ raise Error, "The sequel_model library could not be found. In order to use Sequel models please install sequel_model."
end
end
end
@@ -337,7 +337,7 @@ def proc_to_sql(proc, opts = {})
require 'parse_tree'
rescue Exception
module Sequel::Dataset::Sequelizer
- def proc_to_sql(proc)
+ def proc_to_sql(*args)
raise Sequel::Error, "You must have the ParseTree gem installed in order to use block filters."
end
end
@@ -347,7 +347,7 @@ def proc_to_sql(proc)
require 'ruby2ruby'
rescue Exception
module Sequel::Dataset::Sequelizer
- def ext_expr(e)
+ def ext_expr(*args)
raise Sequel::Error, "You must have the Ruby2Ruby gem installed in order to use this block filter."
end
end
View
@@ -1,6 +1,19 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
describe "Sequel::Model()" do
+ specify "should raise Sequel::Error if sequel_model lib is not available" do
+ module Kernel
+ alias_method :orig_sq_require, :require
+ def require(*args); raise LoadError; end
+ end
+ db = Sequel::Database.new
+ Sequel::Model.instance_eval {@db = db}
+ proc {Sequel::Model(:items)}.should raise_error(Sequel::Error)
+ module Kernel
+ alias_method :require, :orig_sq_require
+ end
+ end
+
specify "should auto-load sequel_model and create a sequel model" do
db = Sequel::Database.new
Sequel::Model.instance_eval {@db = db}
@@ -1,5 +1,64 @@
require File.join(File.dirname(__FILE__), 'spec_helper')
+context "Sequelizer without ParseTree" do
+ setup do
+ module Kernel
+ alias_method :orig_sq_require, :require
+ def require(*args); raise LoadError; end
+ end
+ old_verbose = $VERBOSE
+ $VERBOSE = nil
+ load('lib/sequel/dataset/sequelizer.rb')
+ $VERBOSE = old_verbose
+ @db = Sequel::Database.new
+ @ds = @db[:items]
+ end
+
+ teardown do
+ module Kernel
+ alias_method :require, :orig_sq_require
+ end
+ old_verbose = $VERBOSE
+ $VERBOSE = nil
+ load('lib/sequel/dataset/sequelizer.rb')
+ $VERBOSE = old_verbose
+ end
+
+ specify "should raise error when converting proc to SQL" do
+ proc {@ds.proc_to_sql(proc {:x > 1})}.should raise_error(Sequel::Error)
+ end
+end
+
+context "Sequelizer without Ruby2Ruby" do
+ setup do
+ module Kernel
+ alias_method :orig_sq_require, :require
+ def require(name); raise LoadError if name == 'ruby2ruby'; end
+ end
+ old_verbose = $VERBOSE
+ $VERBOSE = nil
+ load('lib/sequel/dataset/sequelizer.rb')
+ $VERBOSE = old_verbose
+ @db = Sequel::Database.new
+ @ds = @db[:items]
+ end
+
+ teardown do
+ module Kernel
+ alias_method :require, :orig_sq_require
+ end
+ old_verbose = $VERBOSE
+ $VERBOSE = nil
+ load('lib/sequel/dataset/sequelizer.rb')
+ $VERBOSE = old_verbose
+ end
+
+ specify "should raise error only when using external expressions" do
+ proc {@ds.proc_to_sql(proc {:x > 1})}.should_not raise_error(Sequel::Error)
+ proc {@ds.proc_to_sql(proc {1 + 1})}.should raise_error(Sequel::Error)
+ end
+end
+
context "Proc#to_sql" do
DB = Sequel::Database.new
DS = DB[:items]

0 comments on commit 79dc455

Please sign in to comment.