From 3fc793f01407c1297e7c4147486e65abc975e6b9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 9 Jul 2014 13:45:27 +0200 Subject: [PATCH] Fixes and tests for transactions. --- ...344_create_component_transaction_table.php | 1 - app/models/Transaction.php | 4 ++-- app/tests/models/AllModelsTest.php | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php index 6011201f51..cc90d4bfa2 100644 --- a/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php +++ b/app/database/migrations/2014_06_27_165344_create_component_transaction_table.php @@ -15,7 +15,6 @@ class CreateComponentTransactionTable extends Migration { Schema::create('component_transaction', function(Blueprint $table) { $table->increments('id'); - $table->timestamps(); $table->integer('component_id')->unsigned(); $table->integer('transaction_id')->unsigned(); diff --git a/app/models/Transaction.php b/app/models/Transaction.php index eaea8e0c7c..40d323d970 100644 --- a/app/models/Transaction.php +++ b/app/models/Transaction.php @@ -36,11 +36,11 @@ class Transaction extends Elegant public function budgets() { - return $this->belongsToMany('Budget'); + return $this->belongsToMany('Budget','component_transaction','transaction_id','component_id'); } public function categories() { - return $this->belongsToMany('Category'); + return $this->belongsToMany('Category','component_transaction','transaction_id','component_id'); } } \ No newline at end of file diff --git a/app/tests/models/AllModelsTest.php b/app/tests/models/AllModelsTest.php index ac70dadcba..6872e57654 100644 --- a/app/tests/models/AllModelsTest.php +++ b/app/tests/models/AllModelsTest.php @@ -35,10 +35,15 @@ class AllModelsTest extends TestCase $account->user()->associate($user); $pref->user()->associate($user); + $user->accounts()->save($account); + $user->preferences()->save($pref); $this->assertEquals($account->user_id, $user->id); $this->assertEquals($pref->user_id,$user->id); + $this->assertCount(1, $user->accounts()->get()); + $this->assertCount(1, $user->preferences()->get()); + $this->assertTrue(true); @@ -49,6 +54,7 @@ class AllModelsTest extends TestCase */ public function testUserAccounts() { + $this->assertTrue(true); } @@ -84,4 +90,20 @@ class AllModelsTest extends TestCase $this->assertEquals($tj->transaction_currency_id,$tj->transactionCurrency()->first()->id); } + + public function testTransactions() { + $transaction = FactoryMuff::create('Transaction'); + + $budget = FactoryMuff::create('Budget'); + $category = FactoryMuff::create('Category'); + + $transaction->components()->save($budget); + $transaction->components()->save($category); + + $this->assertCount(2,$transaction->components()->get()); + $this->assertCount(1,$transaction->budgets()->get()); + $this->assertCount(1,$transaction->categories()->get()); + + + } } \ No newline at end of file