added resultset override for ordered as well as tests
[dbsrgits/DBIx-Class.git] / t / ordered / inject_component_update.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Exception;
5 use lib qw(t/lib);
6 use DBICTest;    # do not remove even though it is not used
7
8 #15:01 <@ribasushi> dhoss: you are complicating your life
9 #15:01 <@ribasushi> dhoss: start from the other side:
10 #15:02 <@ribasushi> if currently you add a test to t/??ordered.t that does
11 #                   $ordered_rs->search({ condition to not delete
12 #                   everything})->delete;
13 #15:03 <@ribasushi> dhoss: and then examine the database - you will see
14 #                   numbering is broken
15 #15:03 <@ribasushi> dhoss: use your newly found component injection powers to
16 #                   change the delete into a delete_all behind the scenes - the
17 #                   remaining rows will then be reordered correctly
18 #15:03 <@ribasushi> dhoss: this way you both test that injection works AND you
19 #                   fix Ordered
20
21 my $schema = DBICTest->init_schema();
22 my $artist =
23   $schema->resultset('Artist')->search( {}, { rows => 1 } )
24   ->single;    # braindead sqlite
25 my $cd = $schema->resultset('CD')->create(
26   {
27     artist => $artist,
28     title  => 'Get in order',
29     year   => 2009,
30     tracks => [ { title => 'T1' }, { title => 'T2' }, { title => 'T3' }, ],
31   }
32 );
33
34
35 lives_ok( sub { $cd->delete },
36   "Cascade delete on ordered has_many doesn't bomb" );
37
38 is_deeply(
39   mro::get_linear_isa( ref $schema->resultset("Track") ),
40   [
41     qw(
42     DBIx::Class::Ordered::ResultSet
43     DBIx::Class::ResultSet
44     DBIx::Class
45     DBIx::Class::Componentised
46     Class::C3::Componentised
47     Class::Accessor::Grouped
48     )
49   ],
50   "MRO for class is correct"
51 );
52 done_testing();