1 package RTest::InterfaceModel::DBIC;
3 use base qw/Reaction::Test::WithDB Reaction::Object/;
5 use ComponentUI::TestModel;
8 has '+schema_class' => (default => sub { 'RTest::TestDB' });
10 has im_schema => (is =>'ro', isa => 'ComponentUI::TestModel', lazy_build => 1);
14 my (@dm) = ComponentUI::TestModel->domain_models;
15 Test::More::ok(@dm == 1, 'Correct number of Domain Models');
17 Test::More::ok($dm->name eq '_testdb_schema', 'Domain Model created correctly');
19 ComponentUI::TestModel->new($dm->name => $self->schema);
22 sub test_SchemaClass :Tests {
24 my $s = $self->im_schema;
26 #just make sure here...
27 Test::More::isa_ok( $s, 'Reaction::InterfaceModel::Object',
28 'Correctly override default base object' );
30 my %pa = map{$_->name => $_ } $s->parameter_attributes;
31 Test::More::ok(keys %pa == 3, 'Correct number of Parameter Attributes');
33 Test::More::ok($pa{Foo} && $pa{'Bar'} && $pa{'Baz'},
34 'Parameter Attributes named correctly');
36 #for now since we have no generic collection object
38 ( $pa{Foo}->_isa_metadata eq 'Reaction::InterfaceModel::DBIC::Collection',
39 'Parameter Attributes typed correctly' );
41 Test::More::is($pa{Baz}->reader, 'bazes', 'Correct Baz reader created');
42 Test::More::is($pa{Foo}->reader, 'foo_collection', 'Correct Foo reader created');
43 Test::More::is($pa{Bar}->reader, 'bar_collection', 'Correct Bar reader created');
45 #is this check good enough? Moose will take care of checking the type constraints,
46 # so i dont need tocheck that Moose++ !!
47 my $foo1 = $s->foo_collection;
48 my $foo2 = $s->foo_collection;
50 (Scalar::Util::refaddr($foo1) ne Scalar::Util::refaddr($foo2),
51 'Fresh Collections work');
54 sub test_ObjectClass :Tests {
57 my $collection = $self->im_schema->foo_collection;
58 Test::More::ok( my $im = $collection->find({ id => 1}), 'Find call successful');
60 Test::More::isa_ok( $im, 'ComponentUI::TestModel::Foo',
61 'Correct result class set' );
63 my %pa = map{$_->name => $_ } $im->parameter_attributes;
64 Test::More::ok(keys %pa == 4, 'Correct number of Parameter Attributes');
66 Test::More::is( $pa{first_name}->_isa_metadata, 'NonEmptySimpleStr'
67 ,'Column ParameterAttribute typed correctly');
70 ($pa{baz_list}->_isa_metadata, 'Reaction::InterfaceModel::DBIC::Collection',
71 "Relationship detected successfully");
73 my (@dm) = $im->domain_models;
74 Test::More::ok(@dm == 1, 'Correct number of Domain Models');
76 Test::More::is($dm->name, '_foo_store', 'Domain Model created correctly');
78 my $rs = $collection->_override_action_args_for->{target_model};
79 Test::More::isa_ok( $rs, 'DBIx::Class::ResultSet',
80 'Collection target_type ISA ResultSet' );
82 my $row = $im->_default_action_args_for->{target_model};
83 Test::More::isa_ok( $row, 'DBIx::Class::Row', 'Collection target_type ISA Row' );
85 my $ctx = $self->simple_mock_context;
87 my $create = $collection->action_for('Create', ctx => $ctx);
88 Test::More::isa_ok( $create, 'Reaction::InterfaceModel::Action',
89 'Create action isa Action' );
91 Test::More::isa_ok( $create, 'ComponentUI::TestModel::Foo::Action::Create',
92 'Create action has correct name' );
95 ( $create, 'Reaction::InterfaceModel::Action::DBIC::ResultSet::Create',
96 'Create action isa Action::DBIC::ResultSet::Create' );
99 my $update = $im->action_for('Update', ctx => $ctx);
100 Test::More::isa_ok( $update, 'Reaction::InterfaceModel::Action',
101 'Update action isa Action' );
103 Test::More::isa_ok( $update, 'ComponentUI::TestModel::Foo::Action::Update',
104 'Update action has correct name' );
107 ( $update, 'Reaction::InterfaceModel::Action::DBIC::Result::Update',
108 'Update action isa Action::DBIC::ResultSet::Update' );
110 my $delete = $im->action_for('Delete', ctx => $ctx);
111 Test::More::isa_ok( $delete, 'Reaction::InterfaceModel::Action',
112 'Delete action isa Action' );
114 Test::More::isa_ok( $delete, 'ComponentUI::TestModel::Foo::Action::Delete',
115 'Delete action has correct name' );
118 ( $delete, 'Reaction::InterfaceModel::Action::DBIC::Result::Delete',
119 'Delete action isa Action::DBIC::ResultSet::Delete' );
122 my $custom = $im->action_for('CustomAction', ctx => $ctx);
123 Test::More::isa_ok( $custom, 'Reaction::InterfaceModel::Action',
124 'CustomAction isa Action' );
126 Test::More::isa_ok( $custom, 'ComponentUI::TestModel::Foo::Action::CustomAction',
127 'CustomAction has correct name' );
129 my %params = map {$_->name => $_ } $custom->parameter_attributes;
130 Test::More::ok(exists $params{$_}, "Field ${_} reflected")
131 for qw(first_name last_name baz_list);
133 #TODO -- will I need a mock $c object or what? I dont really know much about
134 # testingcat apps, who wants to volunteer?
135 # main things needing testing is attribute reflection
136 # and correct action class creation (superclasses)