sequel 3.13.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG +36 -0
  2. data/doc/release_notes/3.14.0.txt +118 -0
  3. data/lib/sequel/adapters/oracle.rb +7 -2
  4. data/lib/sequel/adapters/shared/mssql.rb +9 -3
  5. data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
  6. data/lib/sequel/connection_pool/threaded.rb +3 -3
  7. data/lib/sequel/database/connecting.rb +47 -11
  8. data/lib/sequel/database/dataset.rb +17 -6
  9. data/lib/sequel/database/dataset_defaults.rb +15 -3
  10. data/lib/sequel/database/logging.rb +4 -3
  11. data/lib/sequel/database/misc.rb +33 -21
  12. data/lib/sequel/database/query.rb +61 -22
  13. data/lib/sequel/database/schema_generator.rb +108 -45
  14. data/lib/sequel/database/schema_methods.rb +8 -5
  15. data/lib/sequel/dataset/actions.rb +194 -45
  16. data/lib/sequel/dataset/features.rb +1 -1
  17. data/lib/sequel/dataset/graph.rb +51 -43
  18. data/lib/sequel/dataset/misc.rb +29 -5
  19. data/lib/sequel/dataset/mutation.rb +0 -1
  20. data/lib/sequel/dataset/prepared_statements.rb +14 -2
  21. data/lib/sequel/dataset/query.rb +268 -125
  22. data/lib/sequel/dataset/sql.rb +33 -44
  23. data/lib/sequel/extensions/migration.rb +3 -2
  24. data/lib/sequel/extensions/pagination.rb +1 -1
  25. data/lib/sequel/model/associations.rb +89 -87
  26. data/lib/sequel/model/base.rb +386 -109
  27. data/lib/sequel/model/errors.rb +15 -1
  28. data/lib/sequel/model/exceptions.rb +3 -3
  29. data/lib/sequel/model/inflections.rb +2 -2
  30. data/lib/sequel/model/plugins.rb +9 -5
  31. data/lib/sequel/plugins/rcte_tree.rb +43 -15
  32. data/lib/sequel/plugins/schema.rb +6 -5
  33. data/lib/sequel/plugins/serialization.rb +1 -1
  34. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  35. data/lib/sequel/plugins/tree.rb +33 -1
  36. data/lib/sequel/timezones.rb +16 -10
  37. data/lib/sequel/version.rb +1 -1
  38. data/spec/adapters/mssql_spec.rb +36 -2
  39. data/spec/adapters/mysql_spec.rb +4 -4
  40. data/spec/adapters/postgres_spec.rb +1 -1
  41. data/spec/adapters/spec_helper.rb +2 -2
  42. data/spec/core/database_spec.rb +8 -1
  43. data/spec/core/dataset_spec.rb +36 -1
  44. data/spec/extensions/pagination_spec.rb +1 -1
  45. data/spec/extensions/rcte_tree_spec.rb +40 -8
  46. data/spec/extensions/schema_spec.rb +5 -0
  47. data/spec/extensions/serialization_spec.rb +4 -4
  48. data/spec/extensions/single_table_inheritance_spec.rb +7 -0
  49. data/spec/extensions/tree_spec.rb +36 -0
  50. data/spec/integration/dataset_test.rb +19 -0
  51. data/spec/integration/prepared_statement_test.rb +2 -2
  52. data/spec/integration/schema_test.rb +1 -1
  53. data/spec/integration/spec_helper.rb +4 -4
  54. data/spec/integration/timezone_test.rb +27 -21
  55. data/spec/model/associations_spec.rb +5 -5
  56. data/spec/model/dataset_methods_spec.rb +13 -0
  57. data/spec/model/hooks_spec.rb +31 -0
  58. data/spec/model/record_spec.rb +24 -7
  59. data/spec/model/validations_spec.rb +9 -4
  60. metadata +6 -4
@@ -1316,7 +1316,7 @@ describe Sequel::Model, "one_to_many" do
1316
1316
  @c2.one_to_many :attributes, :class => @c1
1317
1317
  n = @c2.new(:id => 1234)
1318
1318
  a = @c1.new(:id => 2345)
1319
- def a.valid?; false; end
1319
+ def a.valid?(opts); false; end
1320
1320
  proc{n.add_attribute(a)}.should raise_error(Sequel::Error)
1321
1321
  proc{n.remove_attribute(a)}.should raise_error(Sequel::Error)
1322
1322
  end
@@ -1325,7 +1325,7 @@ describe Sequel::Model, "one_to_many" do
1325
1325
  @c2.one_to_many :attributes, :class => @c1, :validate=>false
1326
1326
  n = @c2.new(:id => 1234)
1327
1327
  a = @c1.new(:id => 2345)
1328
- def a.valid?; false; end
1328
+ def a.valid?(opts); false; end
1329
1329
  n.add_attribute(a).should == a
1330
1330
  n.remove_attribute(a).should == a
1331
1331
  end
@@ -2199,7 +2199,7 @@ describe Sequel::Model, "many_to_many" do
2199
2199
  @c2.many_to_many :attributes, :class => @c1
2200
2200
  n = @c1.new
2201
2201
  a = @c2.load(:id=>123)
2202
- def n.valid?; false; end
2202
+ def n.valid?(opts); false; end
2203
2203
  proc{a.add_attribute(n)}.should raise_error(Sequel::ValidationFailed)
2204
2204
  end
2205
2205
 
@@ -2208,7 +2208,7 @@ describe Sequel::Model, "many_to_many" do
2208
2208
  n = @c1.new
2209
2209
  n.raise_on_save_failure = false
2210
2210
  a = @c2.load(:id=>123)
2211
- def n.valid?; false; end
2211
+ def n.valid?(opts); false; end
2212
2212
  proc{a.add_attribute(n)}.should raise_error(Sequel::Error)
2213
2213
  end
2214
2214
 
@@ -2216,7 +2216,7 @@ describe Sequel::Model, "many_to_many" do
2216
2216
  @c2.many_to_many :attributes, :class => @c1, :validate=>false
2217
2217
  n = @c1.new
2218
2218
  a = @c2.load(:id=>123)
2219
- def n.valid?; false; end
2219
+ def n.valid?(opts); false; end
2220
2220
  a.add_attribute(n)
2221
2221
  n.new?.should == false
2222
2222
  end
@@ -12,6 +12,7 @@ describe Sequel::Model::DatasetMethods, "#destroy" do
12
12
  end
13
13
  end
14
14
  @d = @c.dataset
15
+ MODEL_DB.reset
15
16
  end
16
17
 
17
18
  it "should instantiate objects in the dataset and call destroy on each" do
@@ -37,6 +38,18 @@ describe Sequel::Model::DatasetMethods, "#destroy" do
37
38
  end
38
39
  @d.destroy.should == 0
39
40
  end
41
+
42
+ it "should use a transaction if use_transactions is true for the model" do
43
+ @c.use_transactions = true
44
+ @d.destroy
45
+ MODEL_DB.sqls.should == ["BEGIN", "SELECT * FROM items", "COMMIT"]
46
+ end
47
+
48
+ it "should not use a transaction if use_transactions is false for the model" do
49
+ @c.use_transactions = false
50
+ @d.destroy
51
+ MODEL_DB.sqls.should == ["SELECT * FROM items"]
52
+ end
40
53
  end
41
54
 
42
55
  describe Sequel::Model::DatasetMethods, "#to_hash" do
@@ -89,6 +89,14 @@ describe "Model#before_update && Model#after_update" do
89
89
  MODEL_DB.sqls.should == []
90
90
  end
91
91
 
92
+ specify "#save should cancel the save and raise an error if before_update returns false and raise_on_failure option is true" do
93
+ @c.send(:define_method, :before_update){false}
94
+ @c.raise_on_save_failure = false
95
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should_not raise_error(Sequel::ValidationFailed)
96
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::BeforeHookFailed)
97
+ MODEL_DB.sqls.should == []
98
+ end
99
+
92
100
  specify "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
93
101
  @c.send(:define_method, :before_update){false}
94
102
  @c.raise_on_save_failure = false
@@ -137,6 +145,14 @@ describe "Model#before_save && Model#after_save" do
137
145
  MODEL_DB.sqls.should == []
138
146
  end
139
147
 
148
+ specify "#save should cancel the save and raise an error if before_save returns false and raise_on_failure option is true" do
149
+ @c.send(:define_method, :before_save){false}
150
+ @c.raise_on_save_failure = false
151
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should_not raise_error(Sequel::ValidationFailed)
152
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::BeforeHookFailed)
153
+ MODEL_DB.sqls.should == []
154
+ end
155
+
140
156
  specify "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
141
157
  @c.send(:define_method, :before_save){false}
142
158
  @c.raise_on_save_failure = false
@@ -176,6 +192,13 @@ describe "Model#before_destroy && Model#after_destroy" do
176
192
  MODEL_DB.sqls.should == []
177
193
  end
178
194
 
195
+ specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_failure option is true" do
196
+ @c.send(:define_method, :before_destroy){false}
197
+ @c.raise_on_save_failure = false
198
+ proc{@c.load(:id => 2233).destroy(:raise_on_failure => true)}.should raise_error(Sequel::BeforeHookFailed)
199
+ MODEL_DB.sqls.should == []
200
+ end
201
+
179
202
  specify "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
180
203
  @c.send(:define_method, :before_destroy){false}
181
204
  @c.raise_on_save_failure = false
@@ -231,6 +254,14 @@ describe "Model#before_validation && Model#after_validation" do
231
254
  MODEL_DB.sqls.should == []
232
255
  end
233
256
 
257
+ specify "#save should cancel the save and raise an error if before_validation returns false and raise_on_failure option is true" do
258
+ @c.send(:define_method, :before_validation){false}
259
+ @c.raise_on_save_failure = false
260
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should_not raise_error(Sequel::ValidationFailed)
261
+ proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::BeforeHookFailed)
262
+ MODEL_DB.sqls.should == []
263
+ end
264
+
234
265
  specify "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
235
266
  @c.send(:define_method, :before_validation){false}
236
267
  @c.raise_on_save_failure = false
@@ -243,6 +243,18 @@ describe "Model#save" do
243
243
  MODEL_DB.reset
244
244
  end
245
245
 
246
+ it "should rollback if before_save returns false and :raise_on_failure option is true" do
247
+ o = @c.load(:id => 3, :x => 1, :y => nil)
248
+ o.use_transactions = true
249
+ o.raise_on_save_failure = false
250
+ def o.before_save
251
+ false
252
+ end
253
+ proc { o.save(:y, :raise_on_failure => true) }.should raise_error(Sequel::BeforeHookFailed)
254
+ MODEL_DB.sqls.should == ["BEGIN", "ROLLBACK"]
255
+ MODEL_DB.reset
256
+ end
257
+
246
258
  it "should not rollback outer transactions if before_save returns false and raise_on_save_failure = false" do
247
259
  o = @c.load(:id => 3, :x => 1, :y => nil)
248
260
  o.use_transactions = true
@@ -386,7 +398,7 @@ describe "Model#save_changes" do
386
398
 
387
399
  it "should take options passed to save" do
388
400
  o = @c.new(:x => 1)
389
- def o.valid?; false; end
401
+ def o.before_validation; false; end
390
402
  proc{o.save_changes}.should raise_error(Sequel::Error)
391
403
  MODEL_DB.sqls.should == []
392
404
  o.save_changes(:validate=>false)
@@ -944,17 +956,22 @@ end
944
956
  describe Sequel::Model, "#exists?" do
945
957
  before(:each) do
946
958
  @model = Class.new(Sequel::Model(:items))
947
- @m = @model.new
959
+ @ds = @model.dataset
960
+ def @ds.fetch_rows(sql)
961
+ db.execute(sql)
962
+ yield(:x=>1) if sql =~ /id = 1/
963
+ end
964
+ MODEL_DB.reset
948
965
  end
949
966
 
950
- it "should returns true when #this.count > 0" do
951
- @m.this.meta_def(:count) {1}
952
- @m.exists?.should be_true
967
+ it "should do a query to check if the record exists" do
968
+ @model.load(:id=>1).exists?.should be_true
969
+ MODEL_DB.sqls.should == ['SELECT 1 FROM items WHERE (id = 1) LIMIT 1']
953
970
  end
954
971
 
955
972
  it "should return false when #this.count == 0" do
956
- @m.this.meta_def(:count) {0}
957
- @m.exists?.should be_false
973
+ @model.load(:id=>2).exists?.should be_false
974
+ MODEL_DB.sqls.should == ['SELECT 1 FROM items WHERE (id = 2) LIMIT 1']
958
975
  end
959
976
  end
960
977
 
@@ -128,7 +128,7 @@ describe "Model#save" do
128
128
  columns :id, :x
129
129
 
130
130
  def validate
131
- errors[:id] << 'blah' unless x == 7
131
+ errors.add(:id, 'blah') unless x == 7
132
132
  end
133
133
  end
134
134
  @m = @c.load(:id => 4, :x=>6)
@@ -153,11 +153,16 @@ describe "Model#save" do
153
153
  @m.save(:validate=>false)
154
154
  MODEL_DB.sqls.should == ['UPDATE people SET x = 6 WHERE (id = 4)']
155
155
  end
156
-
156
+
157
157
  specify "should raise error if validations fail and raise_on_save_faiure is true" do
158
- proc{@m.save}.should raise_error(Sequel::ValidationFailed){ |e| e.errors.should == @m.errors }
158
+ proc{@m.save}.should raise_error(Sequel::ValidationFailed){|e| e.errors.should == @m.errors }
159
159
  end
160
-
160
+
161
+ specify "should raise error if validations fail and :raise_on_failure option is true" do
162
+ @m.raise_on_save_failure = false
163
+ proc{@m.save(:raise_on_failure => true)}.should raise_error(Sequel::ValidationFailed)
164
+ end
165
+
161
166
  specify "should return nil if validations fail and raise_on_save_faiure is false" do
162
167
  @m.raise_on_save_failure = false
163
168
  @m.save.should == nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
- - 13
8
+ - 14
9
9
  - 0
10
- version: 3.13.0
10
+ version: 3.14.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Evans
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-01 00:00:00 -07:00
18
+ date: 2010-08-02 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -77,6 +77,7 @@ extra_rdoc_files:
77
77
  - doc/release_notes/3.11.0.txt
78
78
  - doc/release_notes/3.12.0.txt
79
79
  - doc/release_notes/3.13.0.txt
80
+ - doc/release_notes/3.14.0.txt
80
81
  files:
81
82
  - COPYING
82
83
  - CHANGELOG
@@ -121,6 +122,7 @@ files:
121
122
  - doc/release_notes/3.11.0.txt
122
123
  - doc/release_notes/3.12.0.txt
123
124
  - doc/release_notes/3.13.0.txt
125
+ - doc/release_notes/3.14.0.txt
124
126
  - doc/sharding.rdoc
125
127
  - doc/sql.rdoc
126
128
  - doc/virtual_rows.rdoc