sequel 0.2.0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,6 +45,12 @@ context "Proc#to_sql" do
45
45
  def xyz; 321; end
46
46
  proc {:x == xyz}.to_sql.should == "(x = 321)"
47
47
  proc {:x == xyz.to_s}.to_sql.should == "(x = '321')"
48
+
49
+ def y1(x); x; end
50
+ def y2; 111; end
51
+
52
+ proc {:x == y1(222)}.to_sql.should == "(x = 222)"
53
+ proc {:x == y2}.to_sql.should == "(x = 111)"
48
54
  end
49
55
 
50
56
  specify "should support constants" do
@@ -184,16 +190,16 @@ context "Proc#to_sql" do
184
190
  end
185
191
 
186
192
  specify "should support comparison to sub-queries" do
187
- # @ds2 = DB[:test].select(:node_id)
188
- #
189
- # proc {:id == @ds2}.to_sql.should == \
190
- # "(id IN (SELECT node_id FROM test))"
191
- #
192
- # proc {:id == DB[:test].select(:node_id)}.to_sql.should == \
193
- # "(id IN (SELECT node_id FROM test))"
193
+ @ds2 = DB[:test].select(:node_id)
194
+
195
+ proc {:id == @ds2}.to_sql.should == \
196
+ "(id IN (SELECT node_id FROM test))"
197
+
198
+ proc {:id == DB[:test].select(:node_id)}.to_sql.should == \
199
+ "(id IN (SELECT node_id FROM test))"
194
200
 
195
- # proc {:id == DB[:test].select(:node_id).filter {:active == true}}.to_sql.should == \
196
- # "(id IN (SELECT node_id FROM test WHERE (active = 't')))"
201
+ proc {:id == DB[:test].select(:node_id).filter {:active == true}}.to_sql.should == \
202
+ "(id IN (SELECT node_id FROM test WHERE (active = 't')))"
197
203
 
198
204
  proc {:price >= DB[:items].select(:price)}.to_sql.should == \
199
205
  "(price >= (SELECT price FROM items))"
@@ -267,4 +273,38 @@ context "Proc#to_sql" do
267
273
  "abc" =~ /(ab)/
268
274
  proc {:x == $1}.to_sql.should == "(x = 'ab')"
269
275
  end
276
+
277
+ specify "should evaluate expression not referring to symbols or literal strings." do
278
+ proc {:x > 2 * 3}.to_sql.should == "(x > 6)"
279
+ y = 3
280
+ proc {:x > y * 4}.to_sql.should == "(x > 12)"
281
+
282
+ proc {:AVG[:x] > 4}.to_sql.should == "(AVG(x) > 4)"
283
+
284
+ proc {:AVG[:x] > 4}.to_sql.should == "(AVG(x) > 4)"
285
+
286
+ proc {:y == (1 > 2)}.to_sql.should == "(y = 'f')"
287
+ end
288
+
289
+ specify "should support ternary operator" do
290
+ y = true
291
+ proc {:x > (y ? 1 : 2)}.to_sql.should == "(x > 1)"
292
+
293
+ proc {((1 > 2) ? :x : :y) > 3}.to_sql.should == "(y > 3)"
294
+ end
295
+
296
+ specify "should support strings with embedded Ruby code in them and literalize them" do
297
+ proc {:n == "#{1+2}"}.to_sql.should == "(n = '3')"
298
+
299
+ y = "12'34"
300
+
301
+ proc {:x > "#{y}"}.to_sql.should == "(x > '12''34')"
302
+ end
303
+
304
+ specify "should support format strings and literalize the result" do
305
+ prod = 1
306
+ proc {:x == "abc%d" % prod}.to_sql.should == "(x = 'abc1')"
307
+
308
+ proc {:x == ("%d" % prod).lit}.to_sql.should == "(x = 1)"
309
+ end
270
310
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,32 @@
1
1
  require File.join(File.dirname(__FILE__), '../lib/sequel')
2
2
 
3
- class SchemaDummyDatabase < Sequel::Database
3
+ class MockDataset < Sequel::Dataset
4
+ def insert(*args)
5
+ @db.execute insert_sql(*args)
6
+ end
7
+
8
+ def update(*args)
9
+ @db.execute update_sql(*args)
10
+ end
11
+
12
+ def fetch_rows(sql)
13
+ yield({:id => 1, :x => 1})
14
+ end
15
+ end
16
+
17
+ class MockDatabase < Sequel::Database
4
18
  attr_reader :sqls
5
19
 
6
- # def execute(sql)
7
- # @sqls ||= []
8
- # @sqls << sql
9
- # end
20
+ def execute(sql)
21
+ @sqls ||= []
22
+ @sqls << sql
23
+ end
24
+
25
+ def reset
26
+ @sqls = []
27
+ end
28
+
29
+ def transaction; yield; end
30
+
31
+ def dataset; MockDataset.new(self); end
10
32
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: sequel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0.2
7
- date: 2007-09-07 00:00:00 +03:00
6
+ version: 0.2.1
7
+ date: 2007-09-24 00:00:00 +02:00
8
8
  summary: Lightweight ORM library for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -61,6 +61,7 @@ files:
61
61
  - lib/sequel/error.rb
62
62
  - lib/sequel/expressions.rb
63
63
  - lib/sequel/migration.rb
64
+ - lib/sequel/model
64
65
  - lib/sequel/model.rb
65
66
  - lib/sequel/mysql.rb
66
67
  - lib/sequel/odbc.rb
@@ -72,6 +73,11 @@ files:
72
73
  - lib/sequel/dataset/convenience.rb
73
74
  - lib/sequel/dataset/sequelizer.rb
74
75
  - lib/sequel/dataset/sql.rb
76
+ - lib/sequel/model/base.rb
77
+ - lib/sequel/model/hooks.rb
78
+ - lib/sequel/model/record.rb
79
+ - lib/sequel/model/relations.rb
80
+ - lib/sequel/model/schema.rb
75
81
  - lib/sequel/schema/schema_generator.rb
76
82
  - lib/sequel/schema/schema_sql.rb
77
83
  - CHANGELOG