sequel_core 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +1 -1
- data/lib/sequel_core/dataset/sequelizer.rb +9 -2
- data/spec/dataset_spec.rb +9 -5
- data/spec/sequelizer_spec.rb +11 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_core"
|
12
|
-
VERS = "1.0.
|
12
|
+
VERS = "1.0.7"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
@@ -285,7 +285,14 @@ class Sequel::Dataset
|
|
285
285
|
l = e[1]
|
286
286
|
r = eval_expr(e[2], b, opts)
|
287
287
|
raise Sequel::Error::InvalidExpression, "#{l} = #{r}. Did you mean :#{l} == #{r}?"
|
288
|
-
when :if
|
288
|
+
when :if
|
289
|
+
op, c, br1, br2 = *e
|
290
|
+
if ext_expr(c, b, opts)
|
291
|
+
eval_expr(br1, b, opts)
|
292
|
+
elsif br2
|
293
|
+
eval_expr(br2, b, opts)
|
294
|
+
end
|
295
|
+
when :dstr
|
289
296
|
ext_expr(e, b, opts)
|
290
297
|
else
|
291
298
|
raise Sequel::Error::InvalidExpression, "Invalid expression tree: #{e.inspect}"
|
@@ -308,7 +315,7 @@ class Sequel::Dataset
|
|
308
315
|
"(#{e[1..-1].map {|i| pt_expr(i, b, opts)}.join(JOIN_AND)})"
|
309
316
|
when :or # x || y
|
310
317
|
"(#{pt_expr(e[1], b, opts)} OR #{pt_expr(e[2], b, opts)})"
|
311
|
-
when :call, :vcall, :iter, :match3 # method calls, blocks
|
318
|
+
when :call, :vcall, :iter, :match3, :if # method calls, blocks
|
312
319
|
eval_expr(e, b, opts)
|
313
320
|
when :block # block of statements
|
314
321
|
if opts[:comma_separated]
|
data/spec/dataset_spec.rb
CHANGED
@@ -1117,9 +1117,13 @@ context "Dataset#join_table" do
|
|
1117
1117
|
proc {@d.join_table(:invalid, :a, :b)}.should raise_error(Sequel::Error)
|
1118
1118
|
end
|
1119
1119
|
|
1120
|
-
specify "should
|
1120
|
+
specify "should support aliased tables" do
|
1121
1121
|
@d.from('stats s').join('players p', :id => :player_id).sql.should ==
|
1122
1122
|
'SELECT * FROM stats s INNER JOIN players p ON (p.id = s.player_id)'
|
1123
|
+
|
1124
|
+
ds = Sequel::Dataset.new(nil).from(:foo => :f). \
|
1125
|
+
join_table(:inner, :bar, :id => :bar_id).sql.should ==
|
1126
|
+
'SELECT * FROM foo f INNER JOIN bar ON (bar.id = f.bar_id)'
|
1123
1127
|
end
|
1124
1128
|
|
1125
1129
|
specify "should allow for arbitrary conditions in the JOIN clause" do
|
@@ -1133,11 +1137,11 @@ context "Dataset#join_table" do
|
|
1133
1137
|
"SELECT * FROM items LEFT OUTER JOIN categories ON (categories.status IN (1, 2, 3))"
|
1134
1138
|
end
|
1135
1139
|
|
1136
|
-
specify "should
|
1137
|
-
|
1138
|
-
|
1139
|
-
'SELECT * FROM foo f INNER JOIN bar ON (bar.id = f.bar_id)'
|
1140
|
+
specify "should raise error for a table without a source" do
|
1141
|
+
proc {Sequel::Dataset.new(nil).join('players p', :id => :player_id)}. \
|
1142
|
+
should raise_error(Sequel::Error)
|
1140
1143
|
end
|
1144
|
+
|
1141
1145
|
end
|
1142
1146
|
|
1143
1147
|
context "Dataset#[]=" do
|
data/spec/sequelizer_spec.rb
CHANGED
@@ -474,6 +474,17 @@ context "Proc#to_sql" do
|
|
474
474
|
|
475
475
|
proc {:x == ("%d" % prod).lit}.sql.should == "(x = 1)"
|
476
476
|
end
|
477
|
+
|
478
|
+
specify "should support conditional filters" do
|
479
|
+
@criteria = nil
|
480
|
+
proc {if @criteria; :x.like @criteria; end}.sql.should == nil
|
481
|
+
|
482
|
+
@criteria = 'blah'
|
483
|
+
proc {if @criteria; :x.like @criteria; end}.sql.should == "(x LIKE 'blah')"
|
484
|
+
|
485
|
+
@criteria = nil
|
486
|
+
proc {if @criteria; :x.like @criteria; else; :x.like 'ddd'; end}.sql.should == "(x LIKE 'ddd')"
|
487
|
+
end
|
477
488
|
end
|
478
489
|
|
479
490
|
context "Proc#to_sql stock" do
|