Added unicity to AccountType model. Fixed some tests because of this.

This commit is contained in:
James Cole 2014-08-31 10:03:24 +02:00
parent 58b3334f05
commit 2e342e47a7
4 changed files with 49 additions and 80 deletions

View File

@ -11,23 +11,6 @@ use Illuminate\Database\Schema\Blueprint;
class CreateAccountTypesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'account_types', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('type', 50);
$table->boolean('editable');
}
);
}
/**
* Reverse the migrations.
*
@ -38,4 +21,23 @@ class CreateAccountTypesTable extends Migration
Schema::drop('account_types');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'account_types', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('type', 50);
$table->boolean('editable');
$table->unique('type');
}
);
}
}

View File

@ -68,21 +68,21 @@ class AccountTest extends TestCase
// user should equal test user:
$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());
// 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();
$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');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -142,9 +140,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -173,9 +169,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -204,12 +198,8 @@ class AccountTest extends TestCase
public function testIndex()
{
// two account types:
$personalType = f::create('AccountType');
$personalType->type = 'Default account';
$personalType->save();
$benType = f::create('AccountType');
$benType->type = 'Beneficiary account';
$benType->save();
$personalType = \AccountType::whereType('Default account')->first();
$benType = \AccountType::whereType('Beneficiary account')->first();
// create two accounts:
/** @var \Account $account */
@ -251,9 +241,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -285,9 +273,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -306,9 +292,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -325,9 +309,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -343,9 +325,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();
@ -370,9 +350,7 @@ class AccountTest extends TestCase
$account = f::create('Account');
/** @var \AccountType $accountType */
$accountType = f::create('AccountType');
$accountType->type = 'Default account';
$accountType->save();
$accountType = \AccountType::whereType('Default account')->first();
$account->accountType()->associate($accountType);
$account->save();

View File

@ -77,10 +77,8 @@ class ChartControllerTest extends TestCase
public function testHomeAccountInfo()
{
$account = f::create('Account');
$type = f::create('AccountType');
$type->type = 'Default account';
$type->save();
$account->accounttype()->associate($type);
$accountType = \AccountType::whereType('Default account')->first();
$account->accounttype()->associate($accountType);
$account->save();
// for successful binding:
Auth::shouldReceive('user')->andReturn($account->user()->first());

View File

@ -2,18 +2,9 @@
use League\FactoryMuffin\Facade;
Facade::define(
'AccountType',
[
'type' => function () {
$types = [
'Default account',
'Cash account',
'Initial balance account',
'Beneficiary account'
];
return $types[rand(0, 3)];
},
'editable' => 1
]
'AccountType',
[
'type' => 'unique:word',
'editable' => 1
]
);