From 21b5587fd21588ccccf7cb9f8962ce19c964fe38 Mon Sep 17 00:00:00 2001 From: Volovikov Ivan Date: Wed, 17 Oct 2012 00:24:51 +0400 Subject: [PATCH] add user required fields --- demo/controllers/RestUserController.php | 2 +- demo/models/RestUser.php | 10 +++++++--- tests/restTest/RestUserTest.php | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/demo/controllers/RestUserController.php b/demo/controllers/RestUserController.php index 2c4df9d..59b22ac 100644 --- a/demo/controllers/RestUserController.php +++ b/demo/controllers/RestUserController.php @@ -47,7 +47,7 @@ public function actionView() public function actionCreate() { - $model = new RestUser(); + $model = new RestUser('create'); if ($this->isPost() && ($data = $_POST)) { $model->attributes = $data; diff --git a/demo/models/RestUser.php b/demo/models/RestUser.php index 416ccd9..5cfcff1 100644 --- a/demo/models/RestUser.php +++ b/demo/models/RestUser.php @@ -20,11 +20,14 @@ class RestUser extends CModel public $name = 'Test REST User'; - public $password = 'hidden_password'; + public $password; - public function __construct() + public function __construct($scenario = null) { - $this->attachBehaviors($this->behaviors()); + if ($scenario !== null) { + $this->scenario = $scenario; + } + $this->attachBehaviors($this->behaviors()); } /** @@ -41,6 +44,7 @@ public function attributeNames() public function rules() { return array( + array('email, password', 'required', 'on' => 'create'), array('email', 'email'), array('name, password', 'length', 'max' => 244), diff --git a/tests/restTest/RestUserTest.php b/tests/restTest/RestUserTest.php index 8db5aa8..4eafad6 100644 --- a/tests/restTest/RestUserTest.php +++ b/tests/restTest/RestUserTest.php @@ -14,11 +14,15 @@ class RestUserTest extends AbstractTest { public function testCreate() { - $result = $this->post('/api/users', array('email' => 'test@test.local')); + $result = $this->post('/api/users', array( + 'email' => 'test@test.local', + 'password' => 'hidden_password', + )); $model = json_decode($result['body']); $this->assertEquals($model->id, 'TEST_ID'); $this->assertEquals($model->email, 'test@test.local'); + $this->assertFalse(isset($model->password)); $this->assertEquals($result['code'], 201);