Skip to content

Commit 34dc595

Browse files
authored
add json rule to json columns (#134)
1 parent 0c056fd commit 34dc595

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Translators/Rules.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Blueprint\Translators;
44

5-
use Blueprint\Models\Column;
65
use Illuminate\Support\Str;
6+
use Blueprint\Models\Column;
77

88
class Rules
99
{
@@ -36,7 +36,7 @@ public static function fromColumn(string $context, Column $column)
3636
'unsignedInteger',
3737
'unsignedMediumInteger',
3838
'unsignedSmallInteger',
39-
'unsignedTinyInteger'
39+
'unsignedTinyInteger',
4040
])) {
4141
array_push($rules, 'integer');
4242

@@ -45,6 +45,10 @@ public static function fromColumn(string $context, Column $column)
4545
}
4646
}
4747

48+
if (in_array($column->dataType(), ['json'])) {
49+
array_push($rules, 'json');
50+
}
51+
4852
if (in_array($column->dataType(), [
4953
'decimal',
5054
'double',

tests/Feature/Translators/RulesTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Tests\Feature\Translators;
44

5+
use Tests\TestCase;
56
use Blueprint\Models\Column;
67
use Blueprint\Translators\Rules;
7-
use Tests\TestCase;
88

99
/**
1010
* @see Rules
@@ -158,12 +158,22 @@ public function forColumn_return_exists_rule_for_the_unique_modifier()
158158
$this->assertContains('unique:connection.table,column', Rules::fromColumn('connection.table', $column));
159159
}
160160

161+
/**
162+
* @test
163+
*/
164+
public function forColumn_return_json_rule_for_the_json_type()
165+
{
166+
$column = new Column('column', 'json');
167+
168+
$this->assertContains('json', Rules::fromColumn('context', $column));
169+
}
170+
161171
public function stringDataTypesProvider()
162172
{
163173
return [
164174
['string'],
165175
['char'],
166-
['text']
176+
['text'],
167177
];
168178
}
169179

@@ -212,7 +222,7 @@ public function relationshipColumnProvider()
212222
return [
213223
['test_id', 'tests'],
214224
['user_id', 'users'],
215-
['sheep_id', 'sheep']
225+
['sheep_id', 'sheep'],
216226
];
217227
}
218228
}

0 commit comments

Comments
 (0)