Combined patches from RT#70734 and RT#44769
[dbsrgits/SQL-Translator.git] / t / 56-sqlite-producer.t
index e01d2b1..752559d 100644 (file)
@@ -2,11 +2,12 @@
 # vim: set ft=perl:
 
 use strict;
-use Test::More tests => 2;
+use Test::More tests => 3;
 use Test::SQL::Translator qw(maybe_plan);
 use FindBin qw/$Bin/;
 
 use SQL::Translator::Schema::View;
+use SQL::Translator::Schema::Table;
 use SQL::Translator::Producer::SQLite;
 
 {
@@ -34,3 +35,28 @@ use SQL::Translator::Producer::SQLite;
     SELECT id, name FROM thing" ];
   is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');
 }
+{
+    my $create_opts;
+
+    my $table = SQL::Translator::Schema::Table->new(
+        name => 'foo_table',
+    );
+    $table->add_field(
+        name => 'foreign_key',
+        data_type => 'integer',
+    );
+    my $constraint = SQL::Translator::Schema::Constraint->new(
+        table => $table,
+        name => 'fk',
+        type => 'FOREIGN_KEY',
+        fields => ['foreign_key'],
+        reference_fields => ['id'],
+        reference_table => 'foo',
+        on_delete => 'RESTRICT',
+        on_update => 'CASCADE',
+    );
+
+    my $expected = [ "FOREIGN KEY ('foreign_key') REFERENCES 'foo'('id') ON DELETE RESTRICT ON UPDATE CASCADE"];
+    my $result =  [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)];
+    is_deeply($result, $expected, 'correct "FOREIGN KEY"');
+}