diff --git a/tests/fixtures/plugins/database/tester/models/Post.php b/tests/fixtures/plugins/database/tester/models/Post.php index f583f303f..750dfd649 100644 --- a/tests/fixtures/plugins/database/tester/models/Post.php +++ b/tests/fixtures/plugins/database/tester/models/Post.php @@ -4,7 +4,6 @@ use Model; class Post extends Model { - /** * @var string The database table used by the model. */ @@ -122,3 +121,13 @@ class RevisionablePost extends Post } } + +class ValidationPost extends Post +{ + use \October\Rain\Database\Traits\Validation; + + public $rules = [ + 'title' => 'required|min:3|max:255', + 'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:database_tester_posts'], + ]; +} diff --git a/tests/unit/plugins/database/ModelTest.php b/tests/unit/plugins/database/ModelTest.php index 4dd6bc8fc..492b39505 100644 --- a/tests/unit/plugins/database/ModelTest.php +++ b/tests/unit/plugins/database/ModelTest.php @@ -31,4 +31,4 @@ class ModelTest extends PluginTestCase { Post::create(['title' => 'Hi!', 'slug' => 'authenticity']); } -} \ No newline at end of file +} diff --git a/tests/unit/plugins/database/ValidationModelTest.php b/tests/unit/plugins/database/ValidationModelTest.php new file mode 100644 index 000000000..483cc4477 --- /dev/null +++ b/tests/unit/plugins/database/ValidationModelTest.php @@ -0,0 +1,35 @@ +runPluginRefreshCommand('Database.Tester'); + } + + /** + * @expectedException October\Rain\Database\ModelException + */ + public function test_slug_has_to_be_unique() + { + $post = ValidationPost::create([ + 'title' => 'This is a new post', + 'slug' => 'post-1', + 'description' => 'Testing...' + ]); + + $this->assertNotFalse($post); + + $post2 = ValidationPost::create([ + 'title' => 'this is another post with the same slug', + 'slug' => 'post-1', + 'description' => 'testing....' + ]); + } +}