mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Added unicity to AccountType model. Fixed some tests because of this.
This commit is contained in:
		| @@ -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'); | ||||
|                   } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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(); | ||||
|  | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -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 | ||||
|           ] | ||||
| ); | ||||
		Reference in New Issue
	
	Block a user