Fix rule validation issues.

This commit is contained in:
James Cole 2017-09-03 15:57:13 +02:00
parent 49c5c9ba15
commit d9dad4387e
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 33 additions and 13 deletions

View File

@ -13,7 +13,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
/**
* Class RuleFormRequest
@ -57,8 +57,8 @@ class RuleFormRequest extends Request
*/
public function rules()
{
/** @var RuleGroupRepositoryInterface $repository */
$repository = app(RuleGroupRepositoryInterface::class);
/** @var RuleRepositoryInterface $repository */
$repository = app(RuleRepositoryInterface::class);
$validTriggers = array_keys(config('firefly.rule-triggers'));
$validActions = array_keys(config('firefly.rule-actions'));
@ -69,7 +69,6 @@ class RuleFormRequest extends Request
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rules,title,' . intval($this->get('id'));
}
$rules = [
'title' => $titleRule,
'description' => 'between:1,5000',

View File

@ -56,6 +56,21 @@ class RuleRepository implements RuleRepositoryInterface
return true;
}
/**
* @param int $ruleId
*
* @return Rule
*/
public function find(int $ruleId): Rule
{
$rule = $this->user->rules()->find($ruleId);
if (is_null($rule)) {
return new Rule;
}
return $rule;
}
/**
* FIxXME can return null
*

View File

@ -38,6 +38,14 @@ interface RuleRepositoryInterface
*/
public function destroy(Rule $rule): bool;
/**
* @param int $ruleId
*
* @return Rule
*/
public function find(int $ruleId): Rule;
/**
* @return RuleGroup
*/

View File

@ -243,13 +243,12 @@ class RuleControllerTest extends TestCase
public function testStore()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$ruleGroupRepos->shouldReceive('find')->andReturn(new RuleGroup)->once();
$repository->shouldReceive('store')->andReturn(new Rule);
$repository->shouldReceive('find')->withArgs([0])->andReturn(new Rule)->once();
$this->session(['rules.create.uri' => 'http://localhost']);
$data = [
@ -375,12 +374,11 @@ class RuleControllerTest extends TestCase
public function testUpdate()
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$rule = Rule::find(1);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$ruleGroupRepos->shouldReceive('find')->andReturn(new RuleGroup)->once();
$repository->shouldReceive('find')->withArgs([1])->andReturn($rule)->once();
$repository->shouldReceive('update');
$data = [