9 ? ( skip_all => 'needs Moose for testing' )
15 DBICNGTest::Schema::ResultSet:Person; Example Resultset
19 Tests for the various Schema roles you can either use or apply
23 =head2 initialize database
25 create a schema and setup
29 use_ok 'DBICNGTest::Schema';
31 ok my $db_file = Path::Class::File->new(qw/t var DBIxClassNG.db/)
32 => 'created a path for the test database';
36 ok my $schema = DBICNGTest::Schema->connect_and_setup($db_file)
37 => 'Created a good Schema';
39 is ref $schema->source('Person'), 'DBIx::Class::ResultSource::Table'
40 => 'Found Expected Person Source';
42 is $schema->resultset('Person')->count, 5
43 => 'Got the correct number of people';
45 is $schema->resultset('Gender')->count, 3
46 => 'Got the correct number of genders';
49 =head2 check query counter
51 Test the query counter role
55 use_ok 'DBIx::Class::Storage::DBI::Role::QueryCounter';
56 DBIx::Class::Storage::DBI::Role::QueryCounter->meta->apply($schema->storage);
58 is $schema->storage->query_count, 0
59 => 'Query Count is zero';
61 is $schema->resultset('Person')->find(1)->name, 'john'
64 is $schema->resultset('Person')->find(2)->name, 'dan'
67 is $schema->storage->query_count, 2
68 => 'Query Count is two';
71 =head2 check at query interval
73 Test the role for associating events with a given query interval
77 use_ok 'DBIx::Class::Schema::Role::AtQueryInterval';
78 DBIx::Class::Schema::Role::AtQueryInterval->meta->apply($schema);
80 ok my $job1 = $schema->create_job(runs=>sub { 'hello'})
83 is $job1->execute, 'hello',
84 => 'Got expected information from the job';
86 ok my $job2 = $schema->create_job(runs=>'job_handler_echo')
89 is $job2->execute($schema, 'hello1'), 'hello1',
90 => 'Got expected information from the job';
92 ok my $interval1 = $schema->create_query_interval(every=>10)
93 => 'Created a interval';
95 ok $interval1->matches(10)
96 => 'correctly matched 10';
98 ok $interval1->matches(20)
99 => 'correctly matched 20';
101 ok !$interval1->matches(22)
102 => 'correctly didnt matched 22';
104 ok my $interval2 = $schema->create_query_interval(every=>10, offset=>2)
105 => 'Created a interval';
107 ok $interval2->matches(12)
108 => 'correctly matched 12';
110 ok $interval2->matches(22)
111 => 'correctly matched 22';
113 ok !$interval2->matches(25)
114 => 'correctly didnt matched 25';
116 ok my $at = $schema->create_at_query_interval(interval=>$interval2, job=>$job2)
117 => 'created the at query interval object';
119 is $at->execute_if_matches(32, $schema, 'hello2'), 'hello2'
120 => 'Got correct return';
122 ok $schema->at_query_intervals([$at])
123 => 'added job to run at a given interval';
125 is_deeply [$schema->execute_jobs_at_query_interval(42, 'hello4')], ['hello4']
126 => 'got expected job return value';
128 =head2 create jobs via express method
130 Using the express method, build a bunch of jobs
134 ok my @ats = $schema->create_and_add_at_query_intervals(
146 {runs => sub {101.1}},
147 {runs => sub {101.2}},
150 ) => 'created express method at query intervals';
153 is_deeply [$schema->execute_jobs_at_query_interval(10)], [10]
154 => 'Got Expected return for 10';
156 is_deeply [$schema->execute_jobs_at_query_interval(12, 'hello5')], ['hello5']
157 => 'Got Expected return for 12';
159 is_deeply [$schema->execute_jobs_at_query_interval(20)], [10,20]
160 => 'Got Expected return for 20';
162 is_deeply [$schema->execute_jobs_at_query_interval(30)], [10,30]
163 => 'Got Expected return for 30';
165 is_deeply [$schema->execute_jobs_at_query_interval(60)], [10,20,30]
166 => 'Got Expected return for 60';
168 is_deeply [$schema->execute_jobs_at_query_interval(101)], [101.1,101.2]
169 => 'Got Expected return for 101';
174 Cleanup after ourselves
183 See L<DBIx::Class> for more information regarding authors.
187 You may distribute this code under the same terms as Perl itself.