Skip to content

Commit

Permalink
Fix the query extension to handle blocks that end in nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
chanks committed Feb 28, 2013
1 parent f1b3cf2 commit 1d77a3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/sequel/extensions/query.rb
Expand Up @@ -29,7 +29,9 @@ class Dataset
#
# dataset = DB[:items].select(:x, :y, :z).filter{(x > 1) & (y > 2)}.reverse(:z)
def query(&block)
Query.new(self).instance_eval(&block).dataset
query = Query.new(self)
query.instance_eval(&block)
query.dataset
end

# Proxy object used by Dataset#query.
Expand Down
9 changes: 9 additions & 0 deletions spec/extensions/query_spec.rb
Expand Up @@ -77,6 +77,15 @@
q.class.should == @d.class
q.sql.should == "SELECT * FROM xyz ORDER BY stamp"
end

specify "should support blocks that end in nil" do
condition = false
q = @d.query do
from :xyz
order_by :stamp if condition
end
q.sql.should == "SELECT * FROM xyz"
end

specify "should raise on non-chainable method calls" do
proc {@d.query {row_proc}}.should raise_error(Sequel::Error)
Expand Down

0 comments on commit 1d77a3a

Please sign in to comment.