Skip to content
Browse files

Added confirmations to go in serialization

  • Loading branch information...
1 parent 1466b05 commit 25f056bf8589df213013b012e3d4e5d3e7cf919f David FRANCOIS committed Jan 4, 2012
Showing with 8 additions and 2 deletions.
  1. +7 −1 app/models/account_operation.rb
  2. +1 −1 test/unit/account_operation_test.rb
View
8 app/models/account_operation.rb
@@ -197,14 +197,20 @@ def unread
account && (id > account.max_read_tx_id)
end
+ # Extra confirmations this account operation requires to be considered confirmed
+ def required_confirmations
+ (MIN_BTC_CONFIRMATIONS - bt_tx_confirmations) unless confirmed?
+ end
+
def as_json(options={})
super(options.merge(
:only => [
:id, :address, :email, :amount, :currency, :bt_tx_confirmations, :bt_tx_id, :comment, :created_at
],
:methods => [
:unread,
- :confirmed?
+ :confirmed?,
+ :required_confirmations
]
)
)
View
2 test/unit/account_operation_test.rb
@@ -84,7 +84,7 @@ class AccountOperationTest < ActiveSupport::TestCase
# We want to make sure the JSON serialization does not include the model name as root
test "serialization should not include root model name" do
assert_equal JSON::parse(AccountOperation.new.to_json({})),
- JSON::parse("{\"confirmed?\":true,\"comment\":null,\"bt_tx_id\":null,\"address\":null,\"created_at\":null,\"unread\":null,\"id\":null,\"amount\":0.0,\"bt_tx_confirmations\":0,\"currency\":null,\"email\":null}")
+ JSON::parse("{\"required_confirmations\":null,\"confirmed?\":true,\"comment\":null,\"bt_tx_id\":null,\"address\":null,\"created_at\":null,\"unread\":null,\"id\":null,\"amount\":0.0,\"bt_tx_confirmations\":0,\"currency\":null,\"email\":null}")
end
# Under no circumstances should a user account have a negative balance

0 comments on commit 25f056b

Please sign in to comment.
Something went wrong with that request. Please try again.