[Jifty-commit] r4309 - in Jifty-DBI/trunk: t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Oct 25 12:22:59 EDT 2007


Author: sartak
Date: Thu Oct 25 12:22:59 2007
New Revision: 4309

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/t/10schema.t
   Jifty-DBI/trunk/t/testmodels.pl

Log:
 r44174 at onn:  sartak | 2007-10-25 12:22:28 -0400
 Add failing tests for mandatory columns that aren't active, they shouldn't have the not null constraint


Modified: Jifty-DBI/trunk/t/10schema.t
==============================================================================
--- Jifty-DBI/trunk/t/10schema.t	(original)
+++ Jifty-DBI/trunk/t/10schema.t	Thu Oct 25 12:22:59 2007
@@ -5,7 +5,7 @@
 use Test::More;
 use version;
 
-use constant TESTS_PER_DRIVER => 48;
+use constant TESTS_PER_DRIVER => 77;
 our @available_drivers;
 
 BEGIN {
@@ -29,7 +29,8 @@
   SKIP: {
     my $address_schema = has_schema('Sample::Address',$d);
     my $employee_schema = has_schema('Sample::Employee',$d);
-    unless ($address_schema && $employee_schema) {
+    my $corporation_schema = has_schema('Sample::Corporation',$d);
+    unless ($address_schema && $employee_schema && $corporation_schema) {
       skip "need to work on $d", TESTS_PER_DRIVER;
     }
     
@@ -87,6 +88,19 @@
                       Sample::Address->$address_schema. Sample::Employee->$employee_schema, 
                       "got the right Address+Employee schema for $d");
     
+    my $corporation = Sample::Corporation->new;
+    
+    isa_ok($corporation, 'Sample::Corporation');
+    can_ok($corporation, qw( name ));
+    
+    $ret = $SG->add_model($corporation);
+
+    ok($ret != 0, "added model from an instantiated object");
+
+    is_ignoring_space($SG->create_table_sql_text, 
+                      Sample::Address->$address_schema. Sample::Employee->$employee_schema . Sample::Corporation->$corporation_schema, 
+                      "got the right Address+Employee+Corporation schema for $d");
+    
     my $manually_make_text = join ' ', map { "$_;" } $SG->create_table_sql_statements;
      is_ignoring_space($SG->create_table_sql_text, 
                        $manually_make_text, 
@@ -126,6 +140,37 @@
                         "got the right Address schema for $d version $version");
     }
 
+    for my $version (qw/ 0.2.0 0.2.4 0.2.6 0.2.8 0.2.9 /) {
+
+        Sample::Corporation->schema_version($version);
+
+        my $SG = Jifty::DBI::SchemaGenerator->new($handle, $version);
+        $SG->add_model('Sample::Corporation');
+
+        my $needs_state
+            = version->new($version) >= $version_024_min
+           && version->new($version) <  $version_024_max;
+
+        ok(Sample::Corporation->COLUMNS->{id}->active, 'id active');
+        ok(Sample::Corporation->COLUMNS->{name}->active, 'name active');
+        if ($needs_state) {
+            ok(Sample::Corporation->COLUMNS->{us_state}->active, "state active for version $version");
+            ok(Sample::Corporation->COLUMNS->{us_state}->mandatory, "state mandatory for version $version");
+        }
+
+        else {
+            ok(!Sample::Corporation->COLUMNS->{us_state}->active, "state not active for version $version");
+            ok(!Sample::Corporation->COLUMNS->{us_state}->mandatory, "state not mandatory for version $version");
+        }
+
+        my $corporation_version_schema = $needs_state ? "${corporation_schema}_024"
+            :                                             $corporation_schema;
+
+        is_ignoring_space($SG->create_table_sql_text,
+                        Sample::Corporation->$corporation_version_schema,
+                        "got the right Corporation schema for $d version $version");
+    }
+
     cleanup_schema( 'TestApp', $handle );
     disconnect_handle( $handle );
 }

Modified: Jifty-DBI/trunk/t/testmodels.pl
==============================================================================
--- Jifty-DBI/trunk/t/testmodels.pl	(original)
+++ Jifty-DBI/trunk/t/testmodels.pl	Thu Oct 25 12:22:59 2007
@@ -118,4 +118,68 @@
     };
 }
 
+package Sample::Corporation;
+use Jifty::DBI::Schema;
+use Jifty::DBI::Record schema {
+
+column name =>
+    type is 'varchar',
+    is mandatory;
+
+column us_state =>
+    type is 'varchar',
+    is mandatory,
+    since '0.2.4',
+    till '0.2.8';
+
+};
+
+sub schema_sqlite {
+    return q{
+    CREATE TABLE corporations (
+     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL  ,
+     name varchar NOT NULL
+    ) ;
+    }
+}
+
+sub schema_sqlite_024 {
+    return q{
+    CREATE TABLE corporations (
+     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL  ,
+     name varchar NOT NULL ,
+     us_state varchar 
+    ) ;
+    }
+}
+
+sub schema_pg {
+    return q{
+    CREATE TABLE corporations ( 
+      id serial NOT NULL , 
+      name varchar NOT NULL ,
+      PRIMARY KEY (id)
+    ) ;
+    };
+}
+
+sub schema_pg_024 {
+    return q{
+    CREATE TABLE corporations ( 
+      id serial NOT NULL , 
+      name varchar NOT NULL ,
+      us_state varchar ,
+      PRIMARY KEY (id)
+    ) ;
+    };
+}
+
+my $schema_version = undef;
+sub schema_version {
+    my $class = shift;
+    my $new_schema_version = shift;
+    $schema_version = $new_schema_version if defined $new_schema_version;
+    return $schema_version;
+}
+
 1;


More information about the Jifty-commit mailing list