active_nomad 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.0 2010-12-28
2
+
3
+ * Handle Rollback exceptions in Base class.
4
+
1
5
  == 0.2.3 2010-10-12
2
6
 
3
7
  * #inspect no longer requires a database connection.
@@ -164,10 +164,17 @@ module ActiveNomad
164
164
  #
165
165
  # Override to provide custom transaction semantics.
166
166
  #
167
- # The default #transaction simply yields to the given block.
167
+ # The default #transaction simply yields to the given
168
+ # block.
169
+ #
170
+ # ActiveRecord::Rollback exceptions are also swallowed, as
171
+ # ActiveRecord raises these internally if the save returns
172
+ # false. If you need to provide custom rollback behavior, this
173
+ # is the place to implement it.
168
174
  #
169
175
  def transaction
170
176
  yield
177
+ rescue ActiveRecord::Rollback
171
178
  end
172
179
 
173
180
  def inspect
@@ -1,5 +1,5 @@
1
1
  module ActiveNomad
2
- VERSION = [0, 2, 3]
2
+ VERSION = [0, 3, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -437,26 +437,49 @@ describe ActiveNomad::Base do
437
437
  end
438
438
 
439
439
  describe ".transaction" do
440
- before do
441
- @class = Class.new(ActiveNomad::Base) do
442
- cattr_accessor :transaction_called
443
- def self.transaction
444
- self.transaction_called = true
445
- end
440
+ describe "when #transaction is not overridden" do
441
+ before do
442
+ @class = Class.new(ActiveNomad::Base)
443
+ end
444
+
445
+ it "should run the given block by default" do
446
+ instance = @class.new
447
+ block_called = false
448
+ instance.transaction { block_called = true }
449
+ block_called.should be_true
446
450
  end
447
- end
448
451
 
449
- it "should be overridable to provide custom transaction semantics" do
450
- instance = @class.new
451
- instance.transaction{}
452
- instance.transaction_called.should be_true
452
+ it "should swallow rollbacks by default" do
453
+ instance = @class.new
454
+ instance.to_save { raise ActiveRecord::Rollback }
455
+ lambda do
456
+ instance.transaction { instance.save }
457
+ end.should_not raise_error(ActiveRecord::Rollback)
458
+ end
453
459
  end
454
460
 
455
- it "should be called by #save" do
456
- instance = @class.new
457
- instance.transaction_called.should be_false
458
- instance.save
459
- instance.transaction_called.should be_true
461
+ describe "when #transaction is overridden" do
462
+ before do
463
+ @class = Class.new(ActiveNomad::Base) do
464
+ cattr_accessor :transaction_called
465
+ def self.transaction
466
+ self.transaction_called = true
467
+ end
468
+ end
469
+ end
470
+
471
+ it "should exhibit the custom semantics" do
472
+ instance = @class.new
473
+ instance.transaction{}
474
+ instance.transaction_called.should be_true
475
+ end
476
+
477
+ it "should be called by #save" do
478
+ instance = @class.new
479
+ instance.transaction_called.should be_false
480
+ instance.save
481
+ instance.transaction_called.should be_true
482
+ end
460
483
  end
461
484
  end
462
485
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_nomad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - George Ogata
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-12 00:00:00 -04:00
18
+ date: 2010-12-28 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency