mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-15 19:22:08 -06:00
Added unicity to AccountType model. Fixed some tests because of this.
This commit is contained in:
parent
58b3334f05
commit
2e342e47a7
@ -11,6 +11,16 @@ use Illuminate\Database\Schema\Blueprint;
|
|||||||
class CreateAccountTypesTable extends Migration
|
class CreateAccountTypesTable extends Migration
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::drop('account_types');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
@ -24,18 +34,10 @@ class CreateAccountTypesTable extends Migration
|
|||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->string('type', 50);
|
$table->string('type', 50);
|
||||||
$table->boolean('editable');
|
$table->boolean('editable');
|
||||||
|
|
||||||
|
$table->unique('type');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::drop('account_types');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,21 +68,21 @@ class AccountTest extends TestCase
|
|||||||
// user should equal test user:
|
// user should equal test user:
|
||||||
$this->assertEquals($user->id, $account->user()->first()->id);
|
$this->assertEquals($user->id, $account->user()->first()->id);
|
||||||
|
|
||||||
// whatever the account type of this account, searching for it using the
|
|
||||||
// scope method should return one account:
|
|
||||||
$accountTypeType = $account->accounttype->type;
|
|
||||||
$this->assertCount(1, \Account::AccountTypeIn([$accountTypeType])->get());
|
|
||||||
|
|
||||||
// lame test
|
|
||||||
$this->assertEquals('testing',\App::environment());
|
$this->assertEquals('testing',\App::environment());
|
||||||
|
|
||||||
// count the number of accounts the account type has. Should be one:
|
\Log::debug('Hello from test!');
|
||||||
|
\Log::debug('Number of accounts: ' . \Account::count());
|
||||||
|
\Log::debug('Number of account types: ' . \AccountType::count());
|
||||||
|
|
||||||
|
foreach(\AccountType::get() as $t) {
|
||||||
|
\Log::debug('AccountType: #'.$t->id.', ' . $t->type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// whatever the account type of this account, searching for it using the
|
||||||
|
// scope method should return one account:
|
||||||
$accountType = $account->accounttype()->first();
|
$accountType = $account->accounttype()->first();
|
||||||
$this->assertCount(1,$accountType->accounts()->get());
|
$accounts = $accountType->accounts()->count();
|
||||||
|
$this->assertCount($accounts, \Account::AccountTypeIn([$accountType->type])->get());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,9 +111,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -142,9 +140,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -173,9 +169,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -204,12 +198,8 @@ class AccountTest extends TestCase
|
|||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
// two account types:
|
// two account types:
|
||||||
$personalType = f::create('AccountType');
|
$personalType = \AccountType::whereType('Default account')->first();
|
||||||
$personalType->type = 'Default account';
|
$benType = \AccountType::whereType('Beneficiary account')->first();
|
||||||
$personalType->save();
|
|
||||||
$benType = f::create('AccountType');
|
|
||||||
$benType->type = 'Beneficiary account';
|
|
||||||
$benType->save();
|
|
||||||
|
|
||||||
// create two accounts:
|
// create two accounts:
|
||||||
/** @var \Account $account */
|
/** @var \Account $account */
|
||||||
@ -251,9 +241,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -285,9 +273,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -306,9 +292,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -325,9 +309,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -343,9 +325,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
@ -370,9 +350,7 @@ class AccountTest extends TestCase
|
|||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
/** @var \AccountType $accountType */
|
/** @var \AccountType $accountType */
|
||||||
$accountType = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$accountType->type = 'Default account';
|
|
||||||
$accountType->save();
|
|
||||||
$account->accountType()->associate($accountType);
|
$account->accountType()->associate($accountType);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
|
@ -77,10 +77,8 @@ class ChartControllerTest extends TestCase
|
|||||||
public function testHomeAccountInfo()
|
public function testHomeAccountInfo()
|
||||||
{
|
{
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
$type = f::create('AccountType');
|
$accountType = \AccountType::whereType('Default account')->first();
|
||||||
$type->type = 'Default account';
|
$account->accounttype()->associate($accountType);
|
||||||
$type->save();
|
|
||||||
$account->accounttype()->associate($type);
|
|
||||||
$account->save();
|
$account->save();
|
||||||
// for successful binding:
|
// for successful binding:
|
||||||
Auth::shouldReceive('user')->andReturn($account->user()->first());
|
Auth::shouldReceive('user')->andReturn($account->user()->first());
|
||||||
|
@ -4,16 +4,7 @@ use League\FactoryMuffin\Facade;
|
|||||||
Facade::define(
|
Facade::define(
|
||||||
'AccountType',
|
'AccountType',
|
||||||
[
|
[
|
||||||
'type' => function () {
|
'type' => 'unique:word',
|
||||||
$types = [
|
|
||||||
'Default account',
|
|
||||||
'Cash account',
|
|
||||||
'Initial balance account',
|
|
||||||
'Beneficiary account'
|
|
||||||
];
|
|
||||||
|
|
||||||
return $types[rand(0, 3)];
|
|
||||||
},
|
|
||||||
'editable' => 1
|
'editable' => 1
|
||||||
]
|
]
|
||||||
);
|
);
|
Loading…
Reference in New Issue
Block a user