sequel 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -565,3 +565,29 @@ context "Model.db_schema" do
565
565
  @c.primary_key.should == :id
566
566
  end
567
567
  end
568
+
569
+ context "Model#use_transactions" do
570
+ before do
571
+ @c = Class.new(Sequel::Model(:items))
572
+ end
573
+
574
+ specify "should return class value by default" do
575
+ @c.use_transactions = true
576
+ @c.new.use_transactions.should == true
577
+ @c.use_transactions = false
578
+ @c.new.use_transactions.should == false
579
+ end
580
+
581
+ specify "should return set value if manually set" do
582
+ instance = @c.new
583
+ instance.use_transactions = false
584
+ instance.use_transactions.should == false
585
+ @c.use_transactions = true
586
+ instance.use_transactions.should == false
587
+
588
+ instance.use_transactions = true
589
+ instance.use_transactions.should == true
590
+ @c.use_transactions = false
591
+ instance.use_transactions.should == true
592
+ end
593
+ end
@@ -158,7 +158,7 @@ describe "Model#save" do
158
158
  res.should == [nil, nil]
159
159
  end
160
160
 
161
- it "should use Model's save_in_transaction setting by default" do
161
+ it "should use Model's use_transactions setting by default" do
162
162
  @c.use_transactions = true
163
163
  @c.load(:id => 3, :x => 1, :y => nil).save(:y)
164
164
  MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
@@ -169,7 +169,7 @@ describe "Model#save" do
169
169
  MODEL_DB.reset
170
170
  end
171
171
 
172
- it "should inherit Model's save_in_transaction setting" do
172
+ it "should inherit Model's use_transactions setting" do
173
173
  @c.use_transactions = true
174
174
  Class.new(@c).load(:id => 3, :x => 1, :y => nil).save(:y)
175
175
  MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
@@ -180,7 +180,7 @@ describe "Model#save" do
180
180
  MODEL_DB.reset
181
181
  end
182
182
 
183
- it "should use object's save_in_transaction setting" do
183
+ it "should use object's use_transactions setting" do
184
184
  o = @c.load(:id => 3, :x => 1, :y => nil)
185
185
  o.use_transactions = false
186
186
  @c.use_transactions = true
@@ -207,6 +207,56 @@ describe "Model#save" do
207
207
  MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
208
208
  MODEL_DB.reset
209
209
  end
210
+
211
+ it "should rollback if before_save returns false and raise_on_save_failure = true" do
212
+ o = @c.load(:id => 3, :x => 1, :y => nil)
213
+ o.use_transactions = true
214
+ o.raise_on_save_failure = true
215
+ def o.before_save
216
+ false
217
+ end
218
+ proc { o.save(:y) }.should raise_error(Sequel::BeforeHookFailed)
219
+ MODEL_DB.sqls.should == ["BEGIN", "ROLLBACK"]
220
+ MODEL_DB.reset
221
+ end
222
+
223
+ it "should not rollback outer transactions if before_save returns false and raise_on_save_failure = false" do
224
+ o = @c.load(:id => 3, :x => 1, :y => nil)
225
+ o.use_transactions = true
226
+ o.raise_on_save_failure = false
227
+ def o.before_save
228
+ false
229
+ end
230
+ MODEL_DB.transaction do
231
+ o.save(:y).should == nil
232
+ MODEL_DB.run "BLAH"
233
+ end
234
+ MODEL_DB.sqls.should == ["BEGIN", "BLAH", "COMMIT"]
235
+ MODEL_DB.reset
236
+ end
237
+
238
+ it "should rollback if before_save returns false and raise_on_save_failure = false" do
239
+ o = @c.load(:id => 3, :x => 1, :y => nil)
240
+ o.use_transactions = true
241
+ o.raise_on_save_failure = false
242
+ def o.before_save
243
+ false
244
+ end
245
+ o.save(:y).should == nil
246
+ MODEL_DB.sqls.should == ["BEGIN", "ROLLBACK"]
247
+ MODEL_DB.reset
248
+ end
249
+
250
+ it "should not rollback if before_save throws Rollback and use_transactions = false" do
251
+ o = @c.load(:id => 3, :x => 1, :y => nil)
252
+ o.use_transactions = false
253
+ def o.before_save
254
+ raise Sequel::Rollback
255
+ end
256
+ proc { o.save(:y) }.should raise_error(Sequel::Rollback)
257
+ MODEL_DB.sqls.should == []
258
+ MODEL_DB.reset
259
+ end
210
260
  end
211
261
 
212
262
  describe "Model#marshallable" do
@@ -760,6 +810,18 @@ describe Sequel::Model, "#destroy" do
760
810
  @instance.destroy
761
811
  end
762
812
 
813
+ it "should run within a transaction if :transaction option is true" do
814
+ @instance.use_transactions = false
815
+ @model.db.should_receive(:transaction)
816
+ @instance.destroy(:transaction => true)
817
+ end
818
+
819
+ it "should not run within a transaction if :transaction option is false" do
820
+ @instance.use_transactions = true
821
+ @model.db.should_not_receive(:transaction)
822
+ @instance.destroy(:transaction => false)
823
+ end
824
+
763
825
  it "should run before_destroy and after_destroy hooks" do
764
826
  @model.send(:define_method, :before_destroy){MODEL_DB.execute('before blah')}
765
827
  @model.send(:define_method, :after_destroy){MODEL_DB.execute('after blah')}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 -08:00
12
+ date: 2009-12-01 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -57,6 +57,7 @@ extra_rdoc_files:
57
57
  - doc/release_notes/3.4.0.txt
58
58
  - doc/release_notes/3.5.0.txt
59
59
  - doc/release_notes/3.6.0.txt
60
+ - doc/release_notes/3.7.0.txt
60
61
  files:
61
62
  - COPYING
62
63
  - CHANGELOG
@@ -94,6 +95,7 @@ files:
94
95
  - doc/release_notes/3.4.0.txt
95
96
  - doc/release_notes/3.5.0.txt
96
97
  - doc/release_notes/3.6.0.txt
98
+ - doc/release_notes/3.7.0.txt
97
99
  - doc/schema.rdoc
98
100
  - doc/sharding.rdoc
99
101
  - doc/virtual_rows.rdoc
@@ -176,7 +178,6 @@ files:
176
178
  - spec/model/spec_helper.rb
177
179
  - spec/model/validations_spec.rb
178
180
  - spec/rcov.opts
179
- - spec/spec.opts
180
181
  - spec/spec_config.rb
181
182
  - spec/spec_config.rb.example
182
183
  - lib/sequel.rb
data/spec/spec.opts DELETED
File without changes