Some more tests, don't know if they'll cover.

This commit is contained in:
James Cole
2014-07-09 13:35:33 +02:00
parent 84f4e80da1
commit 61f7fbe951
8 changed files with 90 additions and 9 deletions

View File

@@ -3,6 +3,10 @@
class Budget extends Component {
protected $isSubclass = true;
public static $factory = [
'name' => 'string',
'user_id' => 'factory|User',
'class' => 'Budget'
];
}

View File

@@ -3,4 +3,9 @@
class Category extends Component
{
protected $isSubclass = true;
public static $factory = [
'name' => 'string',
'user_id' => 'factory|User',
'class' => 'Category'
];
}

View File

@@ -14,6 +14,11 @@ class Component extends Firefly\Database\SingleTableInheritanceEntity
protected $table = 'components';
protected $subclassField = 'class';
public static $factory = [
'name' => 'string',
'user_id' => 'factory|User',
];
public function transactions()
{
return $this->belongsToMany('Transaction');

View File

@@ -11,6 +11,13 @@ class Transaction extends Elegant
'amount' => 'required|between:-65536,65536',
];
public static $factory
= [
'account_id' => 'factory|Account',
'transaction_journal_id' => 'factory|TransactionJournal',
'description' => 'string',
'amount' => 'integer:5'
];
public function account()
{
@@ -31,6 +38,7 @@ class Transaction extends Elegant
{
return $this->belongsToMany('Budget');
}
public function categories()
{
return $this->belongsToMany('Category');

View File

@@ -1,9 +1,16 @@
<?php
class TransactionCurrency extends Eloquent {
class TransactionCurrency extends Eloquent
{
public function transactionJournals() {
public static $factory
= [
'code' => 'string'
];
public function transactionJournals()
{
return $this->hasMany('TransactionJournal');
}

View File

@@ -13,6 +13,15 @@ class TransactionJournal extends Elegant
'completed' => 'required|between:0,1'
];
public static $factory
= [
'transaction_type_id' => 'factory|TransactionType',
'transaction_currency_id' => 'factory|TransactionCurrency',
'description' => 'string',
'completed' => '1',
'date' => 'date|Y-m-d'
];
public function transactionType()
{
return $this->belongsTo('TransactionType');
@@ -35,12 +44,16 @@ class TransactionJournal extends Elegant
public function budgets()
{
return $this->belongsToMany('Budget','component_transaction_journal','transaction_journal_id','component_id');
return $this->belongsToMany(
'Budget', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
);
}
public function categories()
{
return $this->belongsToMany('Category','component_transaction_journal','transaction_journal_id','component_id');
return $this->belongsToMany(
'Category', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
);
}
public function getDates()
@@ -48,11 +61,14 @@ class TransactionJournal extends Elegant
return array('created_at', 'updated_at', 'date');
}
public function scopeAfter($query, \Carbon\Carbon $date) {
return $query->where('date','>=',$date->format('Y-m-d'));
public function scopeAfter($query, \Carbon\Carbon $date)
{
return $query->where('date', '>=', $date->format('Y-m-d'));
}
public function scopeBefore($query, \Carbon\Carbon $date) {
return $query->where('date','<=',$date->format('Y-m-d'));
public function scopeBefore($query, \Carbon\Carbon $date)
{
return $query->where('date', '<=', $date->format('Y-m-d'));
}
}

View File

@@ -6,4 +6,8 @@ class TransactionType extends Eloquent {
return $this->hasMany('TransactionJournal');
}
public static $factory = [
'type' => 'string'
];
}