Merge pull request #924 from cachethq/model-casts
Added casts properties to all models, re-ordered model properties
This commit is contained in:
@@ -23,16 +23,37 @@ class Component extends Model implements HasPresenter
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* List of attributes that have default values.
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $attributes = [
|
||||
'order' => 0,
|
||||
'group_id' => 0,
|
||||
'description' => '',
|
||||
'link' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required|string',
|
||||
'status' => 'integer|required',
|
||||
'link' => 'url',
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'order' => 'int',
|
||||
'group_id' => 'int',
|
||||
'description' => 'string',
|
||||
'link' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
@@ -49,24 +70,16 @@ class Component extends Model implements HasPresenter
|
||||
];
|
||||
|
||||
/**
|
||||
* List of attributes that have default values.
|
||||
* The validation rules.
|
||||
*
|
||||
* @var mixed[]
|
||||
* @var string[]
|
||||
*/
|
||||
protected $attributes = [
|
||||
'order' => 0,
|
||||
'group_id' => 0,
|
||||
'description' => '',
|
||||
'link' => '',
|
||||
public $rules = [
|
||||
'name' => 'required|string',
|
||||
'status' => 'integer|required',
|
||||
'link' => 'url',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* Components can belong to a group.
|
||||
*
|
||||
|
||||
@@ -24,8 +24,9 @@ class ComponentGroup extends Model
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'order' => 'integer',
|
||||
'order' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,18 +23,29 @@ class Incident extends Model implements HasPresenter
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* The accessors to append to the model's serialized form.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'component_id' => 'integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'visible' => 'required|boolean',
|
||||
'message' => 'required',
|
||||
protected $appends = ['human_status'];
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'visible' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dates = ['scheduled_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
@@ -52,26 +63,16 @@ class Incident extends Model implements HasPresenter
|
||||
];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's serialized form.
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = ['human_status'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dates = ['scheduled_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'visible' => 'integer',
|
||||
public $rules = [
|
||||
'component_id' => 'integer',
|
||||
'name' => 'required',
|
||||
'status' => 'required|integer',
|
||||
'visible' => 'required|boolean',
|
||||
'message' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,13 +20,14 @@ class IncidentTemplate extends Model
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required',
|
||||
'template' => 'required',
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'template' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,16 @@ class IncidentTemplate extends Model
|
||||
*/
|
||||
protected $fillable = ['name', 'template'];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required',
|
||||
'template' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*/
|
||||
|
||||
@@ -37,16 +37,17 @@ class Metric extends Model implements HasPresenter
|
||||
];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
'default_value' => 'numeric',
|
||||
'places' => 'numeric|min:0|max:4',
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'display_chart' => 'bool',
|
||||
'default_value' => 'int',
|
||||
'calc_type' => 'int',
|
||||
'places' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -64,6 +65,19 @@ class Metric extends Model implements HasPresenter
|
||||
'places',
|
||||
];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required',
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'boolean',
|
||||
'default_value' => 'numeric',
|
||||
'places' => 'numeric|min:0|max:4',
|
||||
];
|
||||
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,17 @@ class MetricPoint extends Model implements HasPresenter
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'metric_id' => 'int',
|
||||
'value' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
||||
@@ -15,6 +15,17 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'value' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
|
||||
@@ -21,21 +21,16 @@ class Subscriber extends Model implements HasPresenter
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'email' => 'required|email',
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'email' => 'string',
|
||||
'verify_code' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['email'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
@@ -44,13 +39,19 @@ class Subscriber extends Model implements HasPresenter
|
||||
protected $dates = ['verified_at'];
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
* The fillable properties.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'email' => 'string',
|
||||
'verify_code' => 'string',
|
||||
protected $fillable = ['email'];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'email' => 'required|email',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,16 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fillable properties.
|
||||
*
|
||||
|
||||
@@ -25,16 +25,27 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||
use Authenticatable, CanResetPassword, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $rules = [
|
||||
'username' => ['required', 'regex:/\A(?!.*[:;]-\))[ -~]+\z/'],
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'username' => 'string',
|
||||
'email' => 'string',
|
||||
'google_2fa_secret' => 'string',
|
||||
'api_key' => 'string',
|
||||
'active' => 'bool',
|
||||
'level' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* The properties that cannot be mass assigned.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* The hidden properties.
|
||||
*
|
||||
@@ -45,11 +56,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||
protected $hidden = ['password', 'remember_token', 'google_2fa_secret'];
|
||||
|
||||
/**
|
||||
* The properties that cannot be mass assigned.
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = [];
|
||||
public $rules = [
|
||||
'username' => ['required', 'regex:/\A(?!.*[:;]-\))[ -~]+\z/'],
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
|
||||
@@ -23,9 +23,9 @@ class ComponentGroupTest extends AbstractTestCase
|
||||
$groups = factory('CachetHQ\Cachet\Models\ComponentGroup', 3)->create();
|
||||
|
||||
$this->get('/api/v1/components/groups');
|
||||
$this->seeJson(['id' => (string) $groups[0]->id]);
|
||||
$this->seeJson(['id' => (string) $groups[1]->id]);
|
||||
$this->seeJson(['id' => (string) $groups[2]->id]);
|
||||
$this->seeJson(['id' => $groups[0]->id]);
|
||||
$this->seeJson(['id' => $groups[1]->id]);
|
||||
$this->seeJson(['id' => $groups[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class ComponentTest extends AbstractTestCase
|
||||
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create();
|
||||
|
||||
$this->get('/api/v1/components');
|
||||
$this->seeJson(['id' => (string) $components[0]->id]);
|
||||
$this->seeJson(['id' => (string) $components[1]->id]);
|
||||
$this->seeJson(['id' => (string) $components[2]->id]);
|
||||
$this->seeJson(['id' => $components[0]->id]);
|
||||
$this->seeJson(['id' => $components[1]->id]);
|
||||
$this->seeJson(['id' => $components[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class IncidentTest extends AbstractTestCase
|
||||
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();
|
||||
|
||||
$this->get('/api/v1/incidents');
|
||||
$this->seeJson(['id' => (string) $incidents[0]->id]);
|
||||
$this->seeJson(['id' => (string) $incidents[1]->id]);
|
||||
$this->seeJson(['id' => (string) $incidents[2]->id]);
|
||||
$this->seeJson(['id' => $incidents[0]->id]);
|
||||
$this->seeJson(['id' => $incidents[1]->id]);
|
||||
$this->seeJson(['id' => $incidents[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ class MetricPointTest extends AbstractTestCase
|
||||
]);
|
||||
|
||||
$this->get("/api/v1/metrics/{$metric->id}/points");
|
||||
$this->seeJson(['id' => (string) $metricPoint[0]->id]);
|
||||
$this->seeJson(['id' => (string) $metricPoint[1]->id]);
|
||||
$this->seeJson(['id' => (string) $metricPoint[2]->id]);
|
||||
$this->seeJson(['id' => $metricPoint[0]->id]);
|
||||
$this->seeJson(['id' => $metricPoint[1]->id]);
|
||||
$this->seeJson(['id' => $metricPoint[2]->id]);
|
||||
}
|
||||
|
||||
public function testPostMetricPointUnauthorized()
|
||||
@@ -52,7 +52,7 @@ class MetricPointTest extends AbstractTestCase
|
||||
]);
|
||||
|
||||
$this->post("/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
|
||||
$this->seeJson(['value' => (string) $metricPoint->value]);
|
||||
$this->seeJson(['value' => $metricPoint->value]);
|
||||
}
|
||||
|
||||
public function testPostMetricPointTimestamp()
|
||||
@@ -69,7 +69,7 @@ class MetricPointTest extends AbstractTestCase
|
||||
$postData['timestamp'] = $timestamp;
|
||||
|
||||
$this->post("/api/v1/metrics/{$metric->id}/points", $postData);
|
||||
$this->seeJson(['value' => (string) $metricPoint->value, 'created_at' => $datetime]);
|
||||
$this->seeJson(['value' => $metricPoint->value, 'created_at' => $datetime]);
|
||||
}
|
||||
|
||||
public function testPutMetricPoint()
|
||||
@@ -82,7 +82,7 @@ class MetricPointTest extends AbstractTestCase
|
||||
$this->put("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
|
||||
'value' => 999,
|
||||
]);
|
||||
$this->seeJson(['value' => '999']);
|
||||
$this->seeJson(['value' => 999]);
|
||||
}
|
||||
|
||||
public function testDeleteMetricPoint()
|
||||
|
||||
@@ -23,9 +23,9 @@ class MetricTest extends AbstractTestCase
|
||||
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create();
|
||||
|
||||
$this->get('/api/v1/metrics');
|
||||
$this->seeJson(['id' => (string) $metrics[0]->id]);
|
||||
$this->seeJson(['id' => (string) $metrics[1]->id]);
|
||||
$this->seeJson(['id' => (string) $metrics[2]->id]);
|
||||
$this->seeJson(['id' => $metrics[0]->id]);
|
||||
$this->seeJson(['id' => $metrics[1]->id]);
|
||||
$this->seeJson(['id' => $metrics[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user