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 +4 -0
- data/lib/active_nomad.rb +8 -1
- data/lib/active_nomad/version.rb +1 -1
- data/spec/unit/active_nomad_spec.rb +39 -16
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/active_nomad.rb
CHANGED
@@ -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
|
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
|
data/lib/active_nomad/version.rb
CHANGED
@@ -437,26 +437,49 @@ describe ActiveNomad::Base do
|
|
437
437
|
end
|
438
438
|
|
439
439
|
describe ".transaction" do
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
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
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
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
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 2
|
9
8
|
- 3
|
10
|
-
|
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-
|
18
|
+
date: 2010-12-28 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|