Skip to content

Commit

Permalink
prevent safe attribute column creation closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Oct 14, 2018
1 parent 9c0799d commit 3356974
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec

## 1.0.13 (in progress)

+ [#14](https://github.com/luyadev/luya-testsuite/issues/14) Remove safe validators from column creation.
+ [#13](https://github.com/luyadev/luya-testsuite/issues/13) Convert integer and boolean rule types into integer and boolean column types.

## 1.0.12 (8. October 2018)
Expand Down
10 changes: 10 additions & 0 deletions src/fixtures/ActiveRecordFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ActiveRecordFixture extends ActiveFixture
{
const RULE_TYPE_BOOLEAN = 'boolean';
const RULE_TYPE_INTEGER = 'integer';
const RULE_TYPE_SAFE = 'safe';

/**
* @inheritdoc
Expand Down Expand Up @@ -193,6 +194,8 @@ public function createSchemaFromRules()
foreach ($object->rules() as $row) {
list($attributes, $rule) = $row;

$rule = strtolower($rule);

foreach ((array) $attributes as $name) {

if ($rule == self::RULE_TYPE_BOOLEAN) {
Expand All @@ -204,6 +207,13 @@ public function createSchemaFromRules()
if (!isset($fields[$name])) {
$fields[$name] = Schema::TYPE_TEXT;
}

if ($rule == self::RULE_TYPE_SAFE) {
// remove safe validators fields as they are commonly used for setter getter
if (isset($fields[$name])) {
unset($fields[$name]);
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/data/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public function rules()
[['text'], 'string'],
[['is_deleted'], 'boolean'],

// an attribute which is safe first and integer afterars
// an attribute which is safe first and integer afterawrds
[['switch'], 'safe'],
['switch', 'integer'],
['switch', 'string'],

[['hidden'], 'safe'],
];
}
}

0 comments on commit 3356974

Please sign in to comment.