Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Translators/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Blueprint\Translators;

use Blueprint\Models\Column;
use Illuminate\Support\Str;
use Blueprint\Models\Column;

class Rules
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public static function fromColumn(string $context, Column $column)
'unsignedInteger',
'unsignedMediumInteger',
'unsignedSmallInteger',
'unsignedTinyInteger'
'unsignedTinyInteger',
])) {
array_push($rules, 'integer');

Expand All @@ -45,6 +45,10 @@ public static function fromColumn(string $context, Column $column)
}
}

if (in_array($column->dataType(), ['json'])) {
array_push($rules, 'json');
}

if (in_array($column->dataType(), [
'decimal',
'double',
Expand Down
16 changes: 13 additions & 3 deletions tests/Feature/Translators/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Tests\Feature\Translators;

use Tests\TestCase;
use Blueprint\Models\Column;
use Blueprint\Translators\Rules;
use Tests\TestCase;

/**
* @see Rules
Expand Down Expand Up @@ -158,12 +158,22 @@ public function forColumn_return_exists_rule_for_the_unique_modifier()
$this->assertContains('unique:connection.table,column', Rules::fromColumn('connection.table', $column));
}

/**
* @test
*/
public function forColumn_return_json_rule_for_the_json_type()
{
$column = new Column('column', 'json');

$this->assertContains('json', Rules::fromColumn('context', $column));
}

public function stringDataTypesProvider()
{
return [
['string'],
['char'],
['text']
['text'],
];
}

Expand Down Expand Up @@ -212,7 +222,7 @@ public function relationshipColumnProvider()
return [
['test_id', 'tests'],
['user_id', 'users'],
['sheep_id', 'sheep']
['sheep_id', 'sheep'],
];
}
}