Created
January 12, 2011 04:16
-
-
Save yappo/775689 to your computer and use it in GitHub Desktop.
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
use common::sense; | |
use lib 'lib'; | |
use Test::More; | |
use Nigiri; | |
my $nigiri = Nigiri->new('dbi:SQLite:dbname=scrach.db'); | |
isa_ok($nigiri, 'Nigiri::Neta::Base'); | |
isa_ok($nigiri, 'Nigiri::Neta::AnonClass1'); | |
can_ok($nigiri, qw/ user url bookmark /); | |
for my $table (qw/ user url bookmark /) { | |
isa_ok($nigiri->$table, 'Nigiri::Neta::TableBase'); | |
isa_ok($nigiri->$table, 'Nigiri::Neta::AnonClass1::' . $table); | |
my $obj = $nigiri->$table->new; | |
isa_ok($obj, 'Nigiri::Neta::RowBase'); | |
isa_ok($obj, 'Nigiri::Neta::RowNotSavedBase'); | |
isa_ok($obj, 'Nigiri::Neta::AnonClass1::' . $table . '::Row::NotSaved'); | |
ok(defined $obj && not $obj->isa('Nigiri::Neta::' . $table . '::Row')); | |
} | |
my $user = $nigiri->user->new; | |
is($user->name('nekokak'), 'nekokak'); | |
$user->save; | |
isa_ok($user, 'Nigiri::Neta::RowBase'); | |
isa_ok($user, 'Nigiri::Neta::AnonClass1::user::Row'); | |
ok(defined $user && not $user->isa('Nigiri::Neta::RowNotSavedBase')); | |
ok(defined $user && not $user->isa('Nigiri::Neta::user::Row::NotSaved')); | |
my $url = $nigiri->url->new; | |
is($url->title('Google'), 'Google'); | |
is($url->url('http://goo.gl/e'), 'http://goo.gl/e'); | |
$url->save; | |
isa_ok($url, 'Nigiri::Neta::RowBase'); | |
isa_ok($url, 'Nigiri::Neta::AnonClass1::url::Row'); | |
ok(defined $url && not $url->isa('Nigiri::Neta::RowNotSavedBase')); | |
ok(defined $url && not $url->isa('Nigiri::Neta::url::Row::NotSaved')); | |
my $bookmark = $nigiri->bookmark->new; | |
is($bookmark->user_id($user->id), 1); | |
is($bookmark->url_id($url->id), 1); | |
$bookmark->save; | |
isa_ok($bookmark, 'Nigiri::Neta::RowBase'); | |
isa_ok($bookmark, 'Nigiri::Neta::AnonClass1::bookmark::Row'); | |
ok(defined $bookmark && not $bookmark->isa('Nigiri::Neta::RowNotSavedBase')); | |
ok(defined $bookmark && not $bookmark->isa('Nigiri::Neta::bookmark::Row::NotSaved')); | |
done_testing; | |
__END__ | |
CREATE TABLE user ( | |
id INTEGER NOT NULL PRIMARY KEY, | |
name VARCHAR(255) | |
); | |
CREATE TABLE url ( | |
id INTEGER NOT NULL PRIMARY KEY, | |
title VARCHAR(255), | |
url VARCHAR(255) | |
); | |
CREATE TABLE bookmark ( | |
id INTEGER NOT NULL PRIMARY KEY, | |
user_id INT, | |
url_id INT, | |
UNIQUE (user_id, url_id) | |
); | |
CREATE INDEX url_id ON bookmark (url_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment