Skip to content

Commit

Permalink
Revert "Force ExistsIn rule in new Entity even with a not dirty field"
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 19, 2016
1 parent 25dee75 commit 467bde5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/ORM/Rule/ExistsIn.php
Expand Up @@ -94,7 +94,7 @@ public function __invoke(EntityInterface $entity, array $options)
return true;
}

if (!$entity->extract($this->_fields, true) && !$entity->isNew()) {
if (!$entity->extract($this->_fields, true)) {
return true;
}

Expand Down
29 changes: 3 additions & 26 deletions tests/TestCase/ORM/RulesCheckerIntegrationTest.php
Expand Up @@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
*
* @var array
*/
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.categories'];
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags'];

/**
* Tear down
Expand Down Expand Up @@ -442,7 +442,7 @@ public function testExistsInDomainRuleWithObject()
/**
* ExistsIn uses the schema to verify that nullable fields are ok.
*
* @return void
* @return
*/
public function testExistsInNullValue()
{
Expand All @@ -460,33 +460,10 @@ public function testExistsInNullValue()
$this->assertEquals([], $entity->errors('author_id'));
}

/**
* Test ExistsIn on not dirty field in new Entity
*
* @return void
*/
public function testExistsInNotNullValue()
{
$entity = new Entity([
'name' => 'A Category',
]);

$table = TableRegistry::get('Categories');
$table->belongsTo('Categories', [
'foreignKey' => 'parent_id',
'bindingKey' => 'id',
]);
$rules = $table->rulesChecker();
$rules->add($rules->existsIn('parent_id', 'Categories'));

$this->assertFalse($table->save($entity));
$this->assertEquals(['_existsIn' => 'This value does not exist'], $entity->errors('parent_id'));
}

/**
* Tests exists in uses the bindingKey of the association
*
* @return void
* @return
*/
public function testExistsInWithBindingKey()
{
Expand Down

0 comments on commit 467bde5

Please sign in to comment.