Skip to content

Commit

Permalink
add user required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ivolovikov committed Oct 16, 2012
1 parent e91331c commit 21b5587
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/controllers/RestUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions demo/models/RestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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),

Expand Down
6 changes: 5 additions & 1 deletion tests/restTest/RestUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ class RestUserTest extends AbstractTest
{
public function testCreate()
{
$result = $this->post('/api/users', array('email' => '[email protected]'));
$result = $this->post('/api/users', array(
'email' => '[email protected]',
'password' => 'hidden_password',
));
$model = json_decode($result['body']);

$this->assertEquals($model->id, 'TEST_ID');
$this->assertEquals($model->email, '[email protected]');
$this->assertFalse(isset($model->password));

$this->assertEquals($result['code'], 201);

Expand Down

0 comments on commit 21b5587

Please sign in to comment.