Permalink
Browse files

Merge branch 'master' into apple-touch

  • Loading branch information...
2 parents c761169 + 25f056b commit 211b11a688b12ad40410892e59f31cbda1633c98 David FRANCOIS committed Jan 4, 2012
Showing with 10 additions and 6 deletions.
  1. +8 −4 app/models/account_operation.rb
  2. +1 −1 app/models/transfer.rb
  3. +1 −1 test/unit/account_operation_test.rb
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
require 'digest'
class AccountOperation < ActiveRecord::Base
@@ -59,7 +58,7 @@ def refresh_orders
end
def confirmed?
- (bt_tx_confirmations >= MIN_BTC_CONFIRMATIONS) or bt_tx_id.nil? or (amount < 0)
+ bt_tx_id.nil? or (amount < 0) or (bt_tx_confirmations >= MIN_BTC_CONFIRMATIONS)
end
def refresh_account_address
@@ -198,15 +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
- # TODO : Unread does not appear!
def as_json(options={})
super(options.merge(
:only => [
:id, :address, :email, :amount, :currency, :bt_tx_confirmations, :bt_tx_id, :comment, :created_at
],
:methods => [
- :unread
+ :unread,
+ :confirmed?,
+ :required_confirmations
]
)
)
View
@@ -17,7 +17,7 @@ class Transfer < AccountOperation
:inclusion => { :in => ["LRUSD", "LREUR", "EUR", "BTC"] }
def type_name
- type.gsub(/Transfer/, "").underscore.gsub(/\_/, " ").titleize
+ type.gsub(/Transfer$/, "").underscore.gsub(/\_/, " ").titleize
end
state_machine do
@@ -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("{\"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 211b11a

Please sign in to comment.