--- bin/pgsql2model.pl 2008/06/16 19:11:55 178 +++ bin/pgsql2model.pl 2008/06/16 19:40:21 179 @@ -19,9 +19,8 @@ use lib 'lib'; -use Jifty; use Strix; -use File::Slurp; +use base qw/JiftyModelCreator/; use Data::Dump qw/dump/; use Getopt::Long; @@ -46,8 +45,8 @@ /; my $methods; -my $create; my $columns; +my $create; my $dbh = Strix->dbh( $instance ); @@ -134,81 +133,5 @@ 1; /; -if ( $debug ) { - 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. +JiftyModelCreator->write( $ModelName, $model, $create ); -=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; -}