add a has_columns method
[dbsrgits/SQL-Translator-2.0-ish.git] / t / 13schema.t
index 9201e5e..9a36167 100644 (file)
@@ -108,8 +108,9 @@ require_ok( 'SQL::Translator::Object::View' );
     my $person_table = SQL::Translator::Object::Table->new({ 
         name     => 'person', 
         schema   => $schema,
+        comments => 'foo',
     });
-    $person_table->comments('foo');
+
     $schema->add_table($person_table);
     is( $person_table->name, 'person', 'Table name is "person"' );
     is( $person_table->is_valid, undef, 'Table is not yet valid' );
@@ -120,7 +121,7 @@ require_ok( 'SQL::Translator::Object::View' );
     #
     # Field default new
     #
-    my $person_table_column = SQL::Translator::Object::Column->new( name => 'foo' );
+    my $person_table_column = SQL::Translator::Object::Column->new( name => 'foo', extra => { foo => 'bar', baz => 'quux' } );
     my $f1 = $person_table->add_column($person_table_column);
     isa_ok( $f1, 'SQL::Translator::Object::Column', 'Column' );
     is( $f1->name, 'foo', 'Field name is "foo"' );
@@ -201,9 +202,8 @@ require_ok( 'SQL::Translator::Object::View' );
     is( $f1->data_type('varchar'), 'varchar', 'Field data type is "varchar"' );
     is( $f1->size('30'), '30', 'Field size is "30"' );
     is( $f1->is_primary_key(0), '0', 'Field is_primary_key is negative' );
+    $person_table->add_field( $f1 );
 
-    $f1->extra({ foo => 'bar' });
-    $f1->extra({ baz => 'quux' });
     my %extra = $f1->extra;
     is( $extra{'foo'}, 'bar', 'Field extra "foo" is "bar"' );
     is( $extra{'baz'}, 'quux', 'Field extra "baz" is "quux"' );
@@ -398,11 +398,14 @@ require_ok( 'SQL::Translator::Object::View' );
 TODO: {
     local $TODO = 'patch Moose Native::Trait';
     dies_ok( sub { my $bad_table = $schema->get_table }, 'Error on no arg to get_table' );
+}
     is($schema->get_table('baz'), undef, 'Nonexistant table returns undef');
 
+TODO: {
+    local $TODO = 'patch Moose Native::Trait';
     dies_ok( sub { my $bad_view = $schema->get_view }, 'Error on no arg to get_view' );
-    is($schema->get_view('baz'), undef, 'Nonexistant view returns undef');
 }
+    is($schema->get_view('baz'), undef, 'Nonexistant view returns undef');
 
     my $good_table = $schema->get_table('foo');
     isa_ok( $good_table, 'SQL::Translator::Object::Table', 'Table "foo"' );
@@ -511,7 +514,7 @@ TODO: {
     #like( $c->error, qr/non-existent field/i,
     #    q[...because there's no "pet_id" field in "pet"]);
 
-    my $pet_id = $t2->add_field({ name => 'pet_id' });
+    my $pet_id = $t2->add_column({ name => 'pet_id' });
     is( $pet_id->name, 'pet_id', 'Added field "pet_id"' );
     
 ##    is( $c->is_valid, 1, 'Constraint now valid' );
@@ -625,8 +628,6 @@ TODO: {
         action              => $action,
     }) or die $s->error;
 
-    $t->add_database_event('insert');
-
     isa_ok( $t, 'SQL::Translator::Object::Trigger', 'Trigger' );
     isa_ok( $t->schema, 'SQL::Translator::Object::Schema', 'Schema' );
     is( $t->schema->name, 'TrigTest', qq[Schema name is "'TrigTest'"] );
@@ -648,7 +649,7 @@ TODO: {
 
 
 
-       my $s2                   = SQL::Translator::Object::Schema->new(name => 'TrigTest2');
+    my $s2                   = SQL::Translator::Object::Schema->new(name => 'TrigTest2');
     $s2->add_table({ name => 'foo' }) or die "Couldn't create table: ", $s2->error;
     my $t2                   = $s2->add_trigger({
         name                => 'foo_trigger',
@@ -657,38 +658,37 @@ TODO: {
         on_table            => 'foo',
         action              => 'update modified=timestamp();',
     }) or die $s2->error;
-    $t2->add_database_event('insert');
-    $t2->add_database_event('update');
-       isa_ok( $t2, 'SQL::Translator::Object::Trigger', 'Trigger' );
+
+    isa_ok( $t2, 'SQL::Translator::Object::Trigger', 'Trigger' );
     isa_ok( $t2->schema, 'SQL::Translator::Object::Schema', 'Schema' );
     is( $t2->schema->name, 'TrigTest2', qq[Schema name is "'TrigTest2'"] );
     is( $t2->name, 'foo_trigger', qq[Name is "foo_trigger"] );
-       is_deeply(
+    is_deeply(
         [$t2->database_events],
         [qw/insert update/],
         "Database events are [qw/insert update/] "
     );
 
-       #isa_ok($t2->database_events,'ARRAY','Database events');
-       
-       #
-       # Trigger equal tests
-       #
-#      isnt(
+    #isa_ok($t2->database_events,'ARRAY','Database events');
+    
+    #
+    # Trigger equal tests
+    #
+#    isnt(
 #        $t1->equals($t2),
 #        1,
 #        'Compare two Triggers with database_event and database_events'
 #    );
 
-       $t1->database_events($database_events);
-       $t2->database_events($database_events);
-#      is($t1->equals($t2),1,'Compare two Triggers with database_event');
+    $t1->database_events($database_events);
+    $t2->database_events($database_events);
+#    is($t1->equals($t2),1,'Compare two Triggers with database_event');
 
-       $t2->database_events('');
-       $t1->database_events([qw/update insert/]);
-       $t2->database_events([qw/insert update/]);
-#      is($t1->equals($t2),1,'Compare two Triggers with database_events');
-       
+    $t2->database_events('');
+    $t1->database_events([qw/update insert/]);
+    $t2->database_events([qw/insert update/]);
+#    is($t1->equals($t2),1,'Compare two Triggers with database_events');
+    
     #
     # $schema-> drop_trigger
     #
@@ -722,7 +722,6 @@ TODO: {
         comments   => $comments,
     }); # or die $s->error;
     $p->parameters([ qw/foo bar/ ]);
-    $p->comments($comments);
 
     isa_ok( $p, 'SQL::Translator::Object::Procedure', 'Procedure' );
     isa_ok( $p->schema, 'SQL::Translator::Object::Schema', 'Schema' );