Browse Source

Fix scope option not working in validateUnique.

The scope option exists in $context not $options. Add a previously
failing test as well.
Mark Story 11 years ago
parent
commit
ee5300668c
2 changed files with 6 additions and 3 deletions
  1. 1 1
      src/ORM/Table.php
  2. 5 2
      tests/TestCase/ORM/TableTest.php

+ 1 - 1
src/ORM/Table.php

@@ -2055,7 +2055,7 @@ class Table implements RepositoryInterface, EventListenerInterface
         );
         $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]);

+ 5 - 2
tests/TestCase/ORM/TableTest.php

@@ -3673,13 +3673,16 @@ class TableTest extends TestCase
         $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));
     }