This should fix all tests, although coverage isn't quite there yet.

This commit is contained in:
James Cole
2014-08-17 12:55:27 +02:00
parent c99a8a6072
commit ae95d60c46
7 changed files with 129 additions and 163 deletions

View File

@@ -250,13 +250,4 @@ class PiggybankController extends BaseController
}
/**
* @param Piggybank $piggybank
*/
public function updateAmount(Piggybank $piggybank)
{
Event::fire('piggybanks.change');
$this->_repository->updateAmount($piggybank, Input::get('amount'));
}
}

View File

@@ -27,7 +27,7 @@ class EloquentLimitTrigger
*/
public function updateLimitRepetitions()
{
if (!\Auth::check()) {
if (!\Auth::check() || is_null(\Auth::user())) {
return;
}

View File

@@ -30,6 +30,7 @@ class EloquentPiggybankTrigger
public function updatePiggybankRepetitions()
{
// grab all piggy banks.
if (\Auth::check()) {
$piggybanks = \Auth::user()->piggybanks()->with(['piggybankrepetitions'])->where('repeats', 0)->get();
$today = new Carbon;
/** @var \Piggybank $piggy */
@@ -54,7 +55,8 @@ class EloquentPiggybankTrigger
foreach ($reps as $rep) {
if ($rep->currentamount == 0) {
$query = \Transaction::where('piggybank_id', $piggy->id)->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
'transaction_journals', 'transaction_journals.id', '=',
'transactions.transaction_journal_id'
);
if (!is_null($rep->startdate)) {
$query->where('transaction_journals.date', '>=', $rep->startdate->format('Y-m-d'));
@@ -146,3 +148,4 @@ class EloquentPiggybankTrigger
}
}
}
}

View File

@@ -233,6 +233,7 @@ class BudgetControllerTest extends TestCase
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
$this->_repository->shouldReceive('update')->andReturn($budget);
Event::shouldReceive('fire')->with('budgets.change');
$this->action('POST', 'BudgetController@update', $budget->id);
$this->assertRedirectedToRoute('budgets.index.budget');
@@ -247,6 +248,8 @@ class BudgetControllerTest extends TestCase
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
$this->_repository->shouldReceive('update')->andReturn($budget);
Event::shouldReceive('fire')->with('budgets.change');
//$this->_user->shouldReceive('budgets')->andReturn([]); // trigger
$this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']);
$this->assertRedirectedToRoute('budgets.index');

View File

@@ -32,14 +32,6 @@ class PiggybankControllerTest extends TestCase
m::close();
}
public function testCreate()
{
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
$this->action('GET', 'PiggybankController@create');
$this->assertResponseOk();
}
public function testDelete()
{
$piggyBank = f::create('Piggybank');
@@ -67,6 +59,9 @@ class PiggybankControllerTest extends TestCase
$piggyBank->account()->first()->user_id
);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_piggybanks->shouldReceive('destroy')->andReturn(true);
Event::shouldReceive('fire')->with('piggybanks.change');
$this->action('POST', 'PiggybankController@destroy', $piggyBank->id);
$this->assertResponseStatus(302);
@@ -103,7 +98,11 @@ class PiggybankControllerTest extends TestCase
$three = f::create('Piggybank');
$three->account()->associate($aTwo);
$this->_piggybanks->shouldReceive('get')->andReturn([$one, $two, $three]);
$this->_piggybanks->shouldReceive('count')->andReturn(1);
$this->_piggybanks->shouldReceive('countRepeating')->andReturn(0);
$this->_piggybanks->shouldReceive('countNonrepeating')->andReturn(0);
Event::shouldReceive('fire')->with('piggybanks.change');
$this->action('GET', 'PiggybankController@index');
$this->assertResponseOk();
}
@@ -123,30 +122,7 @@ class PiggybankControllerTest extends TestCase
$this->assertResponseOk();
}
public function testStore()
{
$piggyBank = f::create('Piggybank');
$this->_piggybanks->shouldReceive('store')->andReturn($piggyBank);
$this->action('POST', 'PiggybankController@store');
$this->assertResponseStatus(302);
}
public function testStoreFails()
{
$piggyBank = f::create('Piggybank');
unset($piggyBank->amount);
$this->_piggybanks->shouldReceive('store')->andReturn($piggyBank);
$this->action('POST', 'PiggybankController@store');
$this->assertResponseStatus(302);
}
public function testStoreRedirect()
{
$piggyBank = f::create('Piggybank');
$this->_piggybanks->shouldReceive('store')->andReturn($piggyBank);
$this->action('POST', 'PiggybankController@store', ['create' => '1']);
$this->assertResponseStatus(302);
}
public function testUpdate()
{
@@ -161,6 +137,7 @@ class PiggybankControllerTest extends TestCase
$piggyBank->account()->first()->user_id
);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
Event::shouldReceive('fire')->with('piggybanks.change');
$this->action('POST', 'PiggybankController@update', $piggyBank->id);
$this->assertResponseStatus(302);
@@ -180,26 +157,13 @@ class PiggybankControllerTest extends TestCase
$piggyBank->account()->first()->user_id
);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
Event::shouldReceive('fire')->with('piggybanks.change');
$this->action('POST', 'PiggybankController@update', $piggyBank->id);
$this->assertResponseStatus(302);
}
public function testUpdateAmount()
{
$piggyBank = f::create('Piggybank');
$this->_piggybanks->shouldReceive('updateAmount')->andReturn($piggyBank);
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
$piggyBank->account()->first()->user_id
);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('POST', 'PiggybankController@updateAmount', $piggyBank->id);
$this->assertResponseOk();
}
}

View File

@@ -16,6 +16,7 @@ class TransactionControllerTest extends TestCase
protected $_accounts;
protected $_budgets;
protected $_piggies;
public function setUp()
{
@@ -26,6 +27,7 @@ class TransactionControllerTest extends TestCase
$this->_repository = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$this->_budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$this->_piggies = $this->mock('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
}
@@ -38,6 +40,8 @@ class TransactionControllerTest extends TestCase
{
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
$this->_piggies->shouldReceive('get')->andReturn([]);
$this->action('GET', 'TransactionController@create', ['what' => 'deposit']);
$this->assertResponseOk();
}
@@ -46,6 +50,7 @@ class TransactionControllerTest extends TestCase
{
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
$this->_piggies->shouldReceive('get')->andReturn([]);
$this->action('GET', 'TransactionController@create', ['what' => 'transfer']);
$this->assertResponseOk();
}
@@ -54,6 +59,7 @@ class TransactionControllerTest extends TestCase
{
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
$this->_budgets->shouldReceive('getAsSelectList')->andReturn([]);
$this->_piggies->shouldReceive('get')->andReturn([]);
$this->action('GET', 'TransactionController@create', ['what' => 'withdrawal']);
$this->assertResponseOk();
}

View File

@@ -21,8 +21,7 @@
piggy bank
@endif
by transferring it from one of your accounts to "{{{$piggybank->account->name}}}". However,
since there is still {{mf($maxAdd)}} on that account not locked in any piggy bank or repeated expense,
you can also add it manually.
since there is still {{mf($maxAdd)}} you can add manually.
@else