Fix tests and fix coverage.

This commit is contained in:
James Cole
2015-06-06 15:36:12 +02:00
parent 681167bc1b
commit db020db34b
19 changed files with 381 additions and 286 deletions

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Log;
use Watson\Validating\ValidatingTrait;
/**
@@ -71,7 +72,7 @@ use Watson\Validating\ValidatingTrait;
* @property-read mixed $correct_amount
* @method static \FireflyIII\Models\TransactionJournal orderBy
* @method static \FireflyIII\Models\TransactionJournal|null first
* @property-read mixed $source_account
* @property-read mixed $source_account
*/
class TransactionJournal extends Model
{
@@ -219,36 +220,6 @@ class TransactionJournal extends Model
return $this->belongsToMany('FireflyIII\Models\Tag');
}
/**
* @return Account
*/
public function getAssetAccountAttribute()
{
// if it's a deposit, it's the one thats positive
// if it's a withdrawal, it's the one thats negative
// otherwise, it's either (return first one):
switch ($this->transactionType->type) {
case 'Deposit':
return $this->transactions()->where('amount', '>', 0)->first()->account;
case 'Withdrawal':
return $this->transactions()->where('amount', '<', 0)->first()->account;
}
return $this->transactions()->first()->account;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* @return string
*/
@@ -265,6 +236,15 @@ class TransactionJournal extends Model
return '0';
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* @codeCoverageIgnore
* @return string[]
@@ -308,27 +288,6 @@ class TransactionJournal extends Model
return $account;
}
/**
* @return Account
*/
public function getExpenseAccountAttribute()
{
// if it's a deposit, it's the one thats negative
// if it's a withdrawal, it's the one thats positive
// otherwise, it's either (return first one):
switch ($this->transactionType->type) {
case 'Deposit':
return $this->transactions()->where('amount', '<', 0)->first()->account;
case 'Withdrawal':
return $this->transactions()->where('amount', '>', 0)->first()->account;
}
return $this->transactions()->first()->account;
}
/**
* @return Account
*/
@@ -341,6 +300,7 @@ class TransactionJournal extends Model
return $cache->get(); // @codeCoverageIgnore
}
$account = $this->transactions()->where('amount', '<', 0)->first()->account;
$cache->store($account);
return $account;