/[A3C]/bin/pgsql2model.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/pgsql2model.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 178 by dpavlin, Mon Jun 16 19:11:55 2008 UTC revision 179 by dpavlin, Mon Jun 16 19:40:21 2008 UTC
# Line 19  instead to files. Line 19  instead to files.
19    
20  use lib 'lib';  use lib 'lib';
21    
 use Jifty;  
22  use Strix;  use Strix;
23  use File::Slurp;  use base qw/JiftyModelCreator/;
24  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
25  use Getopt::Long;  use Getopt::Long;
26    
# Line 46  use A3C::Record schema { Line 45  use A3C::Record schema {
45  /;  /;
46    
47  my $methods;  my $methods;
 my $create;  
48  my $columns;  my $columns;
49    my $create;
50    
51  my $dbh = Strix->dbh( $instance );  my $dbh = Strix->dbh( $instance );
52    
# Line 134  use A3C::DefaultACL; Line 133  use A3C::DefaultACL;
133  1;  1;
134  /;  /;
135    
136  if ( $debug ) {  JiftyModelCreator->write( $ModelName, $model, $create );
         print "##### ----- start of created model $ModelName\n\n$model\n\n#### ---- END of created model $ModelName\n";  
 } else {  
         my $model_path = "lib/A3C/Model/$ModelName.pm";  
         write_file( $model_path, $model );  
         print "Created $model_path\n";  
 }  
   
 my $test = <<'__END_OF_TEST__';  
 #!/usr/bin/env perl  
 use warnings;  
 use strict;  
   
 =head1 DESCRIPTION  
   
 A basic test harness for the _ModelName_ model.  
137    
 =cut  
   
 use Jifty::Test tests => 11;  
   
 # Make sure we can load the model  
 use_ok('A3C::Model::_ModelName_');  
   
 # Grab a system user  
 my $system_user = A3C::CurrentUser->superuser;  
 ok($system_user, "Found a system user");  
   
 # Try testing a create  
 my $o = A3C::Model::_ModelName_->new(current_user => $system_user);  
 my ($id) = $o->create(  
 _create_1_);  
 ok($id, "_ModelName_ create returned success");  
 ok($o->id, "New _ModelName_ has valid id set");  
 is($o->id, $id, "Create returned the right id");  
   
 # And another  
 $o->create(  
 _create_2_);  
 ok($o->id, "_ModelName_ create returned another value");  
 isnt($o->id, $id, "And it is different from the previous one");  
   
 # Searches in general  
 my $collection =  A3C::Model::_ModelName_Collection->new(current_user => $system_user);  
 $collection->unlimit;  
 is($collection->count, 2, "Finds two records");  
   
 # Searches in specific  
 $collection->limit(column => 'id', value => $o->id);  
 is($collection->count, 1, "Finds one record with specific id");  
   
 # Delete one of them  
 $o->delete;  
 $collection->redo_search;  
 is($collection->count, 0, "Deleted row is gone");  
   
 # And the other one is still there  
 $collection->unlimit;  
 is($collection->count, 1, "Still one left");  
 __END_OF_TEST__  
   
 $test =~ s/_ModelName_/$ModelName/gs;  
   
 foreach my $round ( 1 .. 2 ) {  
         my $data;  
         $data .= qq/\t\t'$_' => / . dump( $create->{$_} ) . qq/,\n/ foreach keys %$create;  
         warn "$round data = $data\n" if $debug;  
         $test =~ s/_create_${round}_/$data/gs;  
 }  
   
 if ( $debug ) {  
         print "##### ----- template test\n$test\n";  
 } else {  
         my $test_path = "t/00-model-$ModelName.t";  
         write_file( $test_path, $test );  
         print "Created $test_path\n";  
         chmod 0755, $test_path;  
 }  

Legend:
Removed from v.178  
changed lines
  Added in v.179

  ViewVC Help
Powered by ViewVC 1.1.26