-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added setup() class method to create the short-class => schema-class …
…binding * adjust schema() to use the new bindings schemes of setup(); * remove 01-basic.t, no longer adequate. Signed-off-by: Pedro Melo <melo@simplicidade.org>
- Loading branch information
Showing
11 changed files
with
157 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
use lib 't/tlib'; | ||
use Test::More; | ||
use Test::Exception; | ||
use S2; | ||
|
||
throws_ok sub { DBICx::Shortcuts->connect_info }, | ||
qr/Class 'DBICx::Shortcuts' needs to override 'connect_info[(][)]'/, | ||
'The connect_info() method dies by default'; | ||
|
||
throws_ok sub { DBICx::Shortcuts->setup('NoSuchClass') }, | ||
qr/Can't locate NoSuchClass.pm in [@]INC/, | ||
'Failure to load Schema class detected'; | ||
|
||
throws_ok sub { S2->setup('Schema') }, | ||
qr/Shortcut failed, 'my_books' already defined in 'S2', /, | ||
'Shortcut conflict with method detected'; | ||
|
||
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
use lib 't/tlib'; | ||
use Test::More; | ||
use Test::Exception; | ||
use S3; | ||
|
||
eval "require DBD::SQLite"; | ||
plan skip_all => 'API tests require DBD::SQLite, ' if $@; | ||
|
||
lives_ok sub { S3->schema->deploy }, 'Schema deployed sucessfuly'; | ||
|
||
## Basic API | ||
my $rs = S3->my_books; | ||
isa_ok($rs, 'DBIx::Class::ResultSet', 'Got the expected resultset'); | ||
|
||
my $not_found = S3->my_books(-1); | ||
ok(!defined $not_found, 'Find for non-existing ID, undef'); | ||
|
||
$rs = S3->my_books({id => 2}); | ||
isa_ok($rs, 'DBIx::Class::ResultSet', 'Got a resultset'); | ||
|
||
|
||
## Now with real data | ||
my $love = S3->my_books->create({title => 'Love your Catalyst'}); | ||
ok($love, 'Got something'); | ||
isa_ok($love, 'Schema::Result::MyBooks', '... and it seems a MyBook'); | ||
|
||
my $hate = S3->my_books->create({title => 'Hate ponies'}); | ||
ok($hate, 'Second book ok'); | ||
isa_ok($hate, 'Schema::Result::MyBooks', '... proper class at least'); | ||
|
||
is($hate->title, S3->my_books($hate->id)->title, 'Find shortcut works'); | ||
is( | ||
$hate->title, | ||
S3->my_books({id => $hate->id})->first->title, | ||
'Search shortcut works' | ||
); | ||
|
||
is( | ||
$love->title, | ||
S3->my_books(undef, { sort => 'title DESC' })->first->title, | ||
'Search without contitions shortcut works' | ||
); | ||
|
||
done_testing(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package S1; | ||
use parent 'DBICx::Shortcuts'; | ||
|
||
__PACKAGE__->setup('Schema'); | ||
|
||
sub connect_info {} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package S2; | ||
use parent 'DBICx::Shortcuts'; | ||
|
||
sub connect_info {} | ||
|
||
sub my_books {} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package S3; | ||
use parent 'DBICx::Shortcuts'; | ||
use File::Temp qw( tmpnam ); | ||
|
||
__PACKAGE__->setup('Schema'); | ||
|
||
my $tmpname = tmpnam(); | ||
sub connect_info { | ||
return ("dbi:SQLite:$tmpname"); | ||
} | ||
|
||
END { | ||
unlink($tmpname) if $tmpname; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package Schema::Result::MyBooks; | ||
use parent 'DBIx::Class'; | ||
use parent 'DBIx::Class::ResultSource'; | ||
|
||
__PACKAGE__->load_components('Core'); | ||
__PACKAGE__->table('my_books'); | ||
__PACKAGE__->add_columns(qw(id)); | ||
__PACKAGE__->add_columns( | ||
id => { | ||
data_type => 'INT', | ||
is_nullable => 0, | ||
is_auto_increment => 1, | ||
}, | ||
title => { | ||
data_type => 'VARCHAR', | ||
is_nullable => 0, | ||
}, | ||
); | ||
__PACKAGE__->set_primary_key(qw(id)); | ||
|
||
1; |