Skip to content

Commit 3408b67

Browse files
committed
custom rollback references
1 parent 1130859 commit 3408b67

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
deb (0.0.8)
4+
deb (0.0.10)
55
docile
66
rails
77

app/models/deb/transaction.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def self.start(&block)
1818
Docile.dsl_eval(Deb::Builder.new, &block).build
1919
end
2020

21-
def rollback!
21+
def rollback!(ref = nil)
2222
tran = self
2323
self.class.start! do
2424
tran.debit_items.each { |di| credit(di.account, di.amount) }
2525
tran.credit_items.each { |ci| debit(ci.account, ci.amount) }
26-
reference(tran)
26+
reference(ref || tran)
2727
kind(tran.kind)
2828
description("Rollback of #{tran.description}")
2929
end

lib/deb/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Deb
2-
VERSION = "0.0.9"
2+
VERSION = "0.0.10"
33
end

spec/models/transaction_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,30 @@ module Deb
131131
@liability.reload.current_balance.should == 7
132132
end
133133

134-
describe :rollback do
134+
it "should receive custom rollback references" do
135+
@transaction.save!
136+
transaction2 = Transaction.start do
137+
debit @asset, 12
138+
credit @revenue, 5
139+
credit @liability, 7
140+
description "foobar"
141+
kind "baz"
142+
end
143+
transaction2.save!
144+
@rollback = @transaction.rollback!(transaction2)
145+
@rollback.transactionable.should == transaction2
146+
end
147+
148+
describe :default_rollback do
135149
before(:each) do
136150
@transaction.save!
137151
@rollback = @transaction.rollback!
138152
end
139153

154+
it "should keep the reference" do
155+
@rollback.transactionable.should == @transaction
156+
end
157+
140158
it "should be okay" do
141159
@rollback.should_not be_new_record
142160
end

0 commit comments

Comments
 (0)