diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index 48b25b2ece..fc019252fb 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -59,15 +59,19 @@ class TransactionJournal extends Eloquent */ public function getAmount(\Account $account = null) { - + $amount = 0; foreach ($this->transactions as $t) { if (!is_null($account) && $account->id == $t->account_id) { - return floatval($t->amount); + $amount = floatval($t->amount); + break; } if (floatval($t->amount) > 0) { - return floatval($t->amount); + $amount = floatval($t->amount); + break; } } + + return $amount; } /** diff --git a/tests/functional/TransactionControllerCest.php b/tests/functional/TransactionControllerCest.php index 54e337305b..fa7caccfd5 100644 --- a/tests/functional/TransactionControllerCest.php +++ b/tests/functional/TransactionControllerCest.php @@ -106,6 +106,17 @@ class TransactionControllerCest $I->see(intval($journal->getAmount())); } + public function showGroupedJournal(FunctionalTester $I) + { + $journal = TransactionJournal::where('description', 'LIKE', 'Big expense in %')->first(); + + + $I->wantTo('see a grouped transaction'); + $I->amOnPage('/transaction/show/' . $journal->id); + $I->see($journal->description); + $I->see('Money for '.$journal->description); + } + public function store(FunctionalTester $I) { $I->wantTo('store a transaction'); diff --git a/tests/unit/UserTest.php b/tests/unit/UserTest.php index 8a1b60a65f..87b4c9d69e 100644 --- a/tests/unit/UserTest.php +++ b/tests/unit/UserTest.php @@ -23,12 +23,14 @@ class UserTest extends TestCase { $pref = f::create('Preference'); $this->assertEquals($pref->user_id, $pref->user->id); + $this->assertCount(1, $pref->user->preferences()->get()); } public function testReminder() { $reminder = f::create('Reminder'); $this->assertEquals($reminder->user_id, $reminder->user->id); + $this->assertCount(1, $reminder->user->reminders()->get()); } }