Unit tests fixed + models & routers update

This commit is contained in:
Jonathan Labreuille
2016-02-04 11:41:05 +01:00
parent 12c9623e2f
commit c2cb88f995
18 changed files with 148 additions and 154 deletions

View File

@@ -39,7 +39,6 @@ class Model extends \Sudzy\ValidModel {
$this->setTimestamp();
try {
parent::save();
return true;
} catch(\Sudzy\ValidationException $e) {
$this->setError($e->getValidationErrors());
} catch(\PDOException $e) {
@@ -47,7 +46,7 @@ class Model extends \Sudzy\ValidModel {
} catch(\Exception $e) {
$this->setError($e->getMessage());
}
return false;
return $this;
}
function trash() {

View File

@@ -32,16 +32,7 @@ class NewsletterTemplate extends Model {
$template->set($data);
}
$saved = $template->save();
if($saved === true) {
return true;
} else {
$errors = $template->getValidationErrors();
if(!empty($errors)) {
return $errors;
}
}
return false;
$template->save();
return $template;
}
}

View File

@@ -164,8 +164,7 @@ class Segment extends Model {
$segment->set($data);
}
$segment->save();
return $segment;
return $segment->save();
}
static function getPublic() {

View File

@@ -10,8 +10,7 @@ class Setting extends Model {
parent::__construct();
$this->addValidations('name', array(
'required' => 'name_is_blank',
'isString' => 'name_is_not_string'
'required' => __('You need to specify a name.')
));
}
@@ -55,10 +54,11 @@ class Setting extends Model {
$value = serialize($value);
}
return Setting::createOrUpdate(array(
$setting = Setting::createOrUpdate(array(
'name' => $key,
'value' => $value
));
return ($setting->id() > 0 && $setting->getErrors() === false);
} else {
$main_key = array_shift($keys);
@@ -101,8 +101,7 @@ class Setting extends Model {
}
public static function createOrUpdate($model) {
$exists = self::where('name', $model['name'])
->find_one();
$exists = self::where('name', $model['name'])->findOne();
if($exists === false) {
$new_model = self::create();