From fa4d56d4e5b87fb3869cc195b1653b8c7717ab79 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 22 Apr 2009 19:37:44 +0800 Subject: [PATCH] test app schema --- lib/JiftyX/CloudTags.pm | 6 ++- t/00-load.t | 8 ++- t/TestApp/Makefile.PL | 7 +++ t/TestApp/bin/jifty | 16 ++++++ t/TestApp/etc/config.yml | 73 +++++++++++++++++++++++++++ t/TestApp/lib/TestApp/Model/Labels.pm | 23 +++++++++ t/TestApp/lib/TestApp/Model/Posts.pm | 14 +++++ t/TestApp/t/00-model-Labels.t | 49 ++++++++++++++++++ t/TestApp/t/00-model-Posts.t | 49 ++++++++++++++++++ 9 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 t/TestApp/Makefile.PL create mode 100755 t/TestApp/bin/jifty create mode 100644 t/TestApp/etc/config.yml create mode 100644 t/TestApp/lib/TestApp/Model/Labels.pm create mode 100644 t/TestApp/lib/TestApp/Model/Posts.pm create mode 100644 t/TestApp/t/00-model-Labels.t create mode 100644 t/TestApp/t/00-model-Posts.t diff --git a/lib/JiftyX/CloudTags.pm b/lib/JiftyX/CloudTags.pm index ed300a1..3021154 100644 --- a/lib/JiftyX/CloudTags.pm +++ b/lib/JiftyX/CloudTags.pm @@ -8,9 +8,11 @@ our $VERSION = '0.01'; has 'collection' => (is => 'rw', isa => 'Object'); -sub new { - my $class = shift; +sub init { + my $self = shift; my $collection = shift; + use Data::Dumper::Simple; + warn Dumper( $self ); } diff --git a/t/00-load.t b/t/00-load.t index 86cce1c..5308d25 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -1,4 +1,5 @@ -#!perl -T +#!perl +use lib 'lib'; use Test::More tests => 1; @@ -7,3 +8,8 @@ BEGIN { } diag( "Testing JiftyX::CloudTags $JiftyX::CloudTags::VERSION, Perl $], $^X" ); + + +use JiftyX::CloudTags; +my $cloudtags = new JiftyX::CloudTags; +ok( $cloudtags ); diff --git a/t/TestApp/Makefile.PL b/t/TestApp/Makefile.PL new file mode 100644 index 0000000..ec9ccd1 --- /dev/null +++ b/t/TestApp/Makefile.PL @@ -0,0 +1,7 @@ +use inc::Module::Install; + +name 'TestApp'; +version '0.01'; +requires 'Jifty' => '0.90409'; + +WriteAll; diff --git a/t/TestApp/bin/jifty b/t/TestApp/bin/jifty new file mode 100755 index 0000000..118d895 --- /dev/null +++ b/t/TestApp/bin/jifty @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use UNIVERSAL::require; + +BEGIN { + Jifty::Util->require or die $UNIVERSAL::require::ERROR; + my $root = Jifty::Util->app_root(quiet => 1); + unshift @INC, "$root/lib" if ($root); +} + +use Jifty; +use Jifty::Script; + +local $SIG{INT} = sub { warn "Stopped\n"; exit; }; +Jifty::Script->dispatch(); diff --git a/t/TestApp/etc/config.yml b/t/TestApp/etc/config.yml new file mode 100644 index 0000000..4c69dfa --- /dev/null +++ b/t/TestApp/etc/config.yml @@ -0,0 +1,73 @@ +--- +framework: + AdminMode: 1 + ApplicationClass: TestApp + ApplicationName: TestApp + ApplicationUUID: AB1AAC7A-2F31-11DE-94B8-5EDD63EE90E3 + ConfigFileVersion: 4 + Database: + AutoUpgrade: 1 + CheckSchema: 1 + Database: testapp + Driver: SQLite + Host: localhost + Password: '' + RecordBaseClass: Jifty::DBI::Record::Cachable + User: '' + Version: 0.0.1 + DevelMode: 1 + L10N: + PoDir: share/po + LogLevel: INFO + Mailer: Sendmail + MailerArgs: [] + + Plugins: + - + AdminUI: {} + + - + CompressedCSSandJS: {} + + - + ErrorTemplates: {} + + - + Halo: {} + + - + LetMe: {} + + - + OnlineDocs: {} + + - + REST: {} + + - + SkeletonApp: {} + + PubSub: + Backend: Memcached + Enable: ~ + SkipAccessControl: 0 + TemplateClass: TestApp::View + View: + Handlers: + - Jifty::View::Static::Handler + - Jifty::View::Declare::Handler + - Jifty::View::Mason::Handler + Web: + BaseURL: http://localhost + DataDir: var/mason + Globals: [] + + MasonConfig: + autoflush: 0 + default_escape_flags: h + error_format: text + error_mode: fatal + Port: 8888 + ServeStaticFiles: 1 + StaticRoot: share/web/static + TemplateRoot: share/web/templates diff --git a/t/TestApp/lib/TestApp/Model/Labels.pm b/t/TestApp/lib/TestApp/Model/Labels.pm new file mode 100644 index 0000000..141f700 --- /dev/null +++ b/t/TestApp/lib/TestApp/Model/Labels.pm @@ -0,0 +1,23 @@ +use strict; +use warnings; + +package TestApp::Model::Labels; +use Jifty::DBI::Schema; + +use TestApp::Record schema { + +column name => + type is 'varchar'; + +column hit => + type is 'integer'; + +column posts => + refers_to 'TestApp::Model::PostsCollection'; + +}; + +# Your model-specific methods go here. + +1; + diff --git a/t/TestApp/lib/TestApp/Model/Posts.pm b/t/TestApp/lib/TestApp/Model/Posts.pm new file mode 100644 index 0000000..666909c --- /dev/null +++ b/t/TestApp/lib/TestApp/Model/Posts.pm @@ -0,0 +1,14 @@ +use strict; +use warnings; + +package TestApp::Model::Posts; +use Jifty::DBI::Schema; + +use TestApp::Record schema { + +}; + +# Your model-specific methods go here. + +1; + diff --git a/t/TestApp/t/00-model-Labels.t b/t/TestApp/t/00-model-Labels.t new file mode 100644 index 0000000..5c16648 --- /dev/null +++ b/t/TestApp/t/00-model-Labels.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use warnings; +use strict; + +=head1 DESCRIPTION + +A basic test harness for the Labels model. + +=cut + +use Jifty::Test tests => 11; + +# Make sure we can load the model +use_ok('TestApp::Model::Labels'); + +# Grab a system user +my $system_user = TestApp::CurrentUser->superuser; +ok($system_user, "Found a system user"); + +# Try testing a create +my $o = TestApp::Model::Labels->new(current_user => $system_user); +my ($id) = $o->create(); +ok($id, "Labels create returned success"); +ok($o->id, "New Labels has valid id set"); +is($o->id, $id, "Create returned the right id"); + +# And another +$o->create(); +ok($o->id, "Labels create returned another value"); +isnt($o->id, $id, "And it is different from the previous one"); + +# Searches in general +my $collection = TestApp::Model::LabelsCollection->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"); + diff --git a/t/TestApp/t/00-model-Posts.t b/t/TestApp/t/00-model-Posts.t new file mode 100644 index 0000000..03120ee --- /dev/null +++ b/t/TestApp/t/00-model-Posts.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use warnings; +use strict; + +=head1 DESCRIPTION + +A basic test harness for the Posts model. + +=cut + +use Jifty::Test tests => 11; + +# Make sure we can load the model +use_ok('TestApp::Model::Posts'); + +# Grab a system user +my $system_user = TestApp::CurrentUser->superuser; +ok($system_user, "Found a system user"); + +# Try testing a create +my $o = TestApp::Model::Posts->new(current_user => $system_user); +my ($id) = $o->create(); +ok($id, "Posts create returned success"); +ok($o->id, "New Posts has valid id set"); +is($o->id, $id, "Create returned the right id"); + +# And another +$o->create(); +ok($o->id, "Posts create returned another value"); +isnt($o->id, $id, "And it is different from the previous one"); + +# Searches in general +my $collection = TestApp::Model::PostsCollection->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"); +