mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix rule validation issues.
This commit is contained in:
parent
49c5c9ba15
commit
d9dad4387e
@ -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',
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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 = [
|
||||
|
Loading…
Reference in New Issue
Block a user