address some issues with Pg producer and quoting
[dbsrgits/SQL-Translator.git] / t / 47postgres-producer.t
index 447930f..506cd09 100644 (file)
@@ -14,7 +14,7 @@ use FindBin qw/$Bin/;
 #=============================================================================
 
 BEGIN {
-    maybe_plan(51,
+    maybe_plan(53,
         'SQL::Translator::Producer::PostgreSQL',
         'Test::Differences',
     )
@@ -24,6 +24,25 @@ use SQL::Translator;
 
 my $PRODUCER = \&SQL::Translator::Producer::PostgreSQL::create_field;
 
+{
+  my $table = SQL::Translator::Schema::Table->new( name => 'foo.bar' );
+  my $field = SQL::Translator::Schema::Field->new( name => 'baz',
+                                                 table => $table,
+                                                 data_type => 'VARCHAR',
+                                                 size => 10,
+                                                 default_value => 'quux',
+                                                 is_auto_increment => 0,
+                                                 is_nullable => 0,
+                                                 is_foreign_key => 0,
+                                                 is_unique => 0 );
+  $table->add_field($field);
+  my ($create, $fks) = SQL::Translator::Producer::PostgreSQL::create_table($table, { quote_table_names => q{"} });
+  is($table->name, 'foo.bar');
+
+  my $expected = "--\n-- Table: foo.bar\n--\nCREATE TABLE \"foo\".\"bar\" (\n  \"baz\" character varying(10) DEFAULT 'quux' NOT NULL\n)";
+  is($create, $expected);
+}
+
 my $table = SQL::Translator::Schema::Table->new( name => 'mytable');
 
 my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield',
@@ -199,14 +218,14 @@ my $field3_datetime_with_TZ = SQL::Translator::Schema::Field->new(
     size      => 7,
 );
 
-my $field3_datetime_with_TZ_sql = 
+my $field3_datetime_with_TZ_sql =
     SQL::Translator::Producer::PostgreSQL::create_field(
         $field3_datetime_with_TZ
     );
 
 is(
-    $field3_datetime_with_TZ_sql, 
-    'datetime_with_TZ timestamp(6) with time zone', 
+    $field3_datetime_with_TZ_sql,
+    'datetime_with_TZ timestamp(6) with time zone',
     'Create time field with time zone and size, works'
 );
 
@@ -217,14 +236,14 @@ my $field3_time_without_TZ = SQL::Translator::Schema::Field->new(
     size      => 2,
 );
 
-my $field3_time_without_TZ_sql 
+my $field3_time_without_TZ_sql
     = SQL::Translator::Producer::PostgreSQL::create_field(
         $field3_time_without_TZ
     );
 
 is(
-    $field3_time_without_TZ_sql, 
-    'time_without_TZ time(2) without time zone', 
+    $field3_time_without_TZ_sql,
+    'time_without_TZ time(2) without time zone',
     'Create time field without time zone but with size, works'
 );
 
@@ -558,7 +577,7 @@ my $drop_view_8_1_expected = "DROP VIEW view_foo;
 CREATE VIEW view_foo ( id, name ) AS
     SELECT id, name FROM thing
 ";
+
 is($drop_view_8_1_produced, $drop_view_8_1_expected, "My DROP VIEW statement for 8.1 is correct");
 
 my $drop_view_opts2 = { add_drop_view => 1, no_comments => 1, postgres_version => 9.001 };
@@ -568,5 +587,5 @@ my $drop_view_9_1_expected = "DROP VIEW IF EXISTS view_foo;
 CREATE VIEW view_foo ( id, name ) AS
     SELECT id, name FROM thing
 ";
+
 is($drop_view_9_1_produced, $drop_view_9_1_expected, "My DROP VIEW statement for 9.1 is correct");