Skip to content

Commit

Permalink
Fix scope option not working in validateUnique.
Browse files Browse the repository at this point in the history
The scope option exists in $context not $options. Add a previously
failing test as well.
  • Loading branch information
markstory committed Feb 23, 2015
1 parent aeead0f commit ee53006
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -2055,7 +2055,7 @@ public function validateUnique($value, array $context, array $options = null)
);
$fields = array_merge(
[$options['field']],
isset($options['scope']) ? (array)$options['scope'] : []
isset($context['scope']) ? (array)$context['scope'] : []
);
$rule = new IsUnique($fields);
return $rule($entity, ['repository' => $this]);
Expand Down
7 changes: 5 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3673,13 +3673,16 @@ public function testValidateUniqueScope()
$table = TableRegistry::get('Users');
$validator = new Validator;
$validator->add('username', 'unique', [
'rule' => ['validateUnique', ['scope' => 'id']],
'rule' => ['validateUnique', ['derp' => 'erp', 'scope' => 'id']],
'provider' => 'table'
]);
$validator->provider('table', $table);
$data = ['username' => 'larry'];
$data = ['username' => 'larry', 'id' => 3];
$this->assertNotEmpty($validator->errors($data));

$data = ['username' => 'larry', 'id' => 1];
$this->assertEmpty($validator->errors($data));

$data = ['username' => 'jose'];
$this->assertEmpty($validator->errors($data));
}
Expand Down

0 comments on commit ee53006

Please sign in to comment.