From f670cfd0d1ce4753a2c76b27cdc01e8471e4cc4a Mon Sep 17 00:00:00 2001 From: groditi Date: Wed, 12 Sep 2007 19:57:03 +0000 Subject: first checkin tests fail everywhere but demo works. yay? --- t/im_dbic.t | 5 - t/lib/RTest/InterfaceModel/DBIC.pm | 140 --------------------------- t/lib/RTest/InterfaceModel/Reflector/DBIC.pm | 39 +++----- 3 files changed, 14 insertions(+), 170 deletions(-) delete mode 100644 t/lib/RTest/InterfaceModel/DBIC.pm (limited to 't') diff --git a/t/im_dbic.t b/t/im_dbic.t index db4f772..24035bb 100644 --- a/t/im_dbic.t +++ b/t/im_dbic.t @@ -3,13 +3,8 @@ use strict; use warnings; use Test::Class; -use RTest::InterfaceModel::DBIC; use RTest::InterfaceModel::Reflector::DBIC; -Test::Class->runtests( - RTest::InterfaceModel::DBIC->new(), -); - Test::Class->runtests( RTest::InterfaceModel::Reflector::DBIC->new(), ); diff --git a/t/lib/RTest/InterfaceModel/DBIC.pm b/t/lib/RTest/InterfaceModel/DBIC.pm deleted file mode 100644 index 3a2bf57..0000000 --- a/t/lib/RTest/InterfaceModel/DBIC.pm +++ /dev/null @@ -1,140 +0,0 @@ -package RTest::InterfaceModel::DBIC; - -use base qw/Reaction::Test::WithDB Reaction::Object/; -use Reaction::Class; -use ComponentUI::TestModel; -use Test::More (); - -has '+schema_class' => (default => sub { 'RTest::TestDB' }); - -has im_schema => (is =>'ro', isa => 'ComponentUI::TestModel', lazy_build => 1); -sub build_im_schema{ - my $self = shift; - - my (@dm) = ComponentUI::TestModel->domain_models; - Test::More::ok(@dm == 1, 'Correct number of Domain Models'); - my $dm = shift @dm; - Test::More::ok($dm->name eq '_testdb_schema', 'Domain Model created correctly'); - - ComponentUI::TestModel->new($dm->name => $self->schema); -} - -sub test_SchemaClass :Tests { - my $self = shift; - my $s = $self->im_schema; - - #just make sure here... - Test::More::isa_ok( $s, 'Reaction::InterfaceModel::Object', - 'Correctly override default base object' ); - - my %pa = map{$_->name => $_ } $s->parameter_attributes; - Test::More::ok(keys %pa == 3, 'Correct number of Parameter Attributes'); - - Test::More::ok($pa{Foo} && $pa{'Bar'} && $pa{'Baz'}, - 'Parameter Attributes named correctly'); - - #for now since we have no generic collection object - Test::More::ok - ( $pa{Foo}->_isa_metadata eq 'Reaction::InterfaceModel::DBIC::Collection', - 'Parameter Attributes typed correctly' ); - - Test::More::is($pa{Baz}->reader, 'bazes', 'Correct Baz reader created'); - Test::More::is($pa{Foo}->reader, 'foo_collection', 'Correct Foo reader created'); - Test::More::is($pa{Bar}->reader, 'bar_collection', 'Correct Bar reader created'); - - #is this check good enough? Moose will take care of checking the type constraints, - # so i dont need tocheck that Moose++ !! - my $foo1 = $s->foo_collection; - my $foo2 = $s->foo_collection; - Test::More::ok - (Scalar::Util::refaddr($foo1) ne Scalar::Util::refaddr($foo2), - 'Fresh Collections work'); -} - -sub test_ObjectClass :Tests { - my $self = shift; - - my $collection = $self->im_schema->foo_collection; - Test::More::ok( my $im = $collection->find({ id => 1}), 'Find call successful'); - - Test::More::isa_ok( $im, 'ComponentUI::TestModel::Foo', - 'Correct result class set' ); - - my %pa = map{$_->name => $_ } $im->parameter_attributes; - Test::More::ok(keys %pa == 4, 'Correct number of Parameter Attributes'); - - Test::More::is( $pa{first_name}->_isa_metadata, 'NonEmptySimpleStr' - ,'Column ParameterAttribute typed correctly'); - - Test::More::is - ($pa{baz_list}->_isa_metadata, 'Reaction::InterfaceModel::DBIC::Collection', - "Relationship detected successfully"); - - my (@dm) = $im->domain_models; - Test::More::ok(@dm == 1, 'Correct number of Domain Models'); - my $dm = shift @dm; - Test::More::is($dm->name, '_foo_store', 'Domain Model created correctly'); - - my $rs = $collection->_override_action_args_for->{target_model}; - Test::More::isa_ok( $rs, 'DBIx::Class::ResultSet', - 'Collection target_type ISA ResultSet' ); - - my $row = $im->_default_action_args_for->{target_model}; - Test::More::isa_ok( $row, 'DBIx::Class::Row', 'Collection target_type ISA Row' ); - - my $ctx = $self->simple_mock_context; - - my $create = $collection->action_for('Create', ctx => $ctx); - Test::More::isa_ok( $create, 'Reaction::InterfaceModel::Action', - 'Create action isa Action' ); - - Test::More::isa_ok( $create, 'ComponentUI::TestModel::Foo::Action::Create', - 'Create action has correct name' ); - - Test::More::isa_ok - ( $create, 'Reaction::InterfaceModel::Action::DBIC::ResultSet::Create', - 'Create action isa Action::DBIC::ResultSet::Create' ); - - - my $update = $im->action_for('Update', ctx => $ctx); - Test::More::isa_ok( $update, 'Reaction::InterfaceModel::Action', - 'Update action isa Action' ); - - Test::More::isa_ok( $update, 'ComponentUI::TestModel::Foo::Action::Update', - 'Update action has correct name' ); - - Test::More::isa_ok - ( $update, 'Reaction::InterfaceModel::Action::DBIC::Result::Update', - 'Update action isa Action::DBIC::ResultSet::Update' ); - - my $delete = $im->action_for('Delete', ctx => $ctx); - Test::More::isa_ok( $delete, 'Reaction::InterfaceModel::Action', - 'Delete action isa Action' ); - - Test::More::isa_ok( $delete, 'ComponentUI::TestModel::Foo::Action::Delete', - 'Delete action has correct name' ); - - Test::More::isa_ok - ( $delete, 'Reaction::InterfaceModel::Action::DBIC::Result::Delete', - 'Delete action isa Action::DBIC::ResultSet::Delete' ); - - - my $custom = $im->action_for('CustomAction', ctx => $ctx); - Test::More::isa_ok( $custom, 'Reaction::InterfaceModel::Action', - 'CustomAction isa Action' ); - - Test::More::isa_ok( $custom, 'ComponentUI::TestModel::Foo::Action::CustomAction', - 'CustomAction has correct name' ); - - my %params = map {$_->name => $_ } $custom->parameter_attributes; - Test::More::ok(exists $params{$_}, "Field ${_} reflected") - for qw(first_name last_name baz_list); - - #TODO -- will I need a mock $c object or what? I dont really know much about - # testingcat apps, who wants to volunteer? - # main things needing testing is attribute reflection - # and correct action class creation (superclasses) -} - - -1; diff --git a/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm b/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm index 1215788..9451c00 100644 --- a/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm +++ b/t/lib/RTest/InterfaceModel/Reflector/DBIC.pm @@ -18,52 +18,42 @@ has im_schema => (is =>'ro', isa => 'RTest::TestIM', lazy_build => 1); sub build_im_schema{ my $self = shift; - my $reflector = Reaction::InterfaceModel::Reflector::DBIC - ->new(model_class => 'RTest::TestIM'); + my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new; - $reflector->reflect_model( - domain_model_class => 'RTest::TestDB', - #exclude_submodels => ['FooBaz'], - reflect_submodels => [qw/Foo Bar Baz/] + $reflector->reflect_schema( + model_class => 'RTest::TestIM', + schema_class => 'RTest::TestDB', + sources => [qw/Foo Bar Baz/] ); my (@dm) = RTest::TestIM->domain_models; Test::More::ok(@dm == 1, 'Correct number of Domain Models'); my $dm = shift @dm; - - print STDERR "instantiating with domain name of " . $dm->name . "\n"; RTest::TestIM->new($dm->name => $self->schema); } sub test_classnames : Tests{ my $self = shift; - my $reflector = Reaction::InterfaceModel::Reflector::DBIC - ->new(model_class => 'RTest::__TestIM'); + my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new; - Test::More::ok( - Class::MOP::is_class_loaded( 'RTest::__TestIM'), - "Successfully created IM class" - ); Test::More::is( - $reflector->submodel_classname_from_source_name('Foo'), + $reflector->class_name_from_source_name('RTest::__TestIM','Foo'), 'RTest::__TestIM::Foo', 'Correct naming scheme for submodels' ); - Test::More::is( - $reflector->classname_for_collection_of('RTest::__TestIM::Foo'), + $reflector->class_name_for_collection_of('RTest::__TestIM::Foo'), 'RTest::__TestIM::Foo::Collection', 'Correct naming scheme for submodel collections' ); } -sub test_reflect_model :Tests { +sub test_reflect_schema :Tests { my $self = shift; my $s = $self->im_schema; - Test::More::isa_ok( $s, 'Reaction::InterfaceModel::Object', - 'Correct base' ); + Test::More::isa_ok( $s, 'Reaction::InterfaceModel::Object', 'Correct base' ); my %pa = map{$_->name => $_ } $s->parameter_attributes; Test::More::ok(keys %pa == 3, 'Correct number of Parameter Attributes'); @@ -93,7 +83,7 @@ sub test_reflect_model :Tests { } -sub test_add_submodel_to_model :Tests { +sub test_add_source_to_model :Tests { my $self = shift; my $s = $self->im_schema; @@ -110,7 +100,7 @@ sub test_add_submodel_to_model :Tests { Test::More::ok( $attr->has_default, "${_} has a default"); Test::More::ok( $attr->is_default_a_coderef, "${_}'s defaultis a coderef"); Test::More::is( $attr->reader, $reader, "Correct ${_} reader"); - Test::More::is( $attr->domain_model, "_RTest_TestDB", "Correct ${_} domain_model"); + Test::More::is( $attr->domain_model, "_rtest_testdb_store", "Correct ${_} domain_model"); Test::More::isa_ok( $s->$reader, @@ -178,9 +168,8 @@ sub test_reflect_submodel :Tests{ Test::More::ok(@dm == 1, 'Correct number of Domain Models'); my $dm = shift @dm; - my $dm_name = $sm; - $dm_name =~ s/([a-z0-9])([A-Z])/${1}_${2}/g ; - $dm_name = "_" . lc($dm_name) . "_store"; + my $dm_name = Reaction::InterfaceModel::Reflector::DBIC + ->dm_name_from_source_name($sm); Test::More::is($dm->_is_metadata, "rw", "Correct is metadata"); Test::More::ok($dm->is_required, "DM is_required"); -- cgit v1.2.3-54-g00ecf