Commit | Line | Data |
c1a04675 |
1 | #!perl |
2 | |
3 | use DBIx::Class::Fixtures; |
8ce68ce4 |
4 | use Test::More tests => 17; |
08a9f84c |
5 | use lib qw(t/lib); |
c1a04675 |
6 | use DBICTest; |
7 | use Path::Class; |
8 | use Data::Dumper; |
66d02e24 |
9 | use IO::All; |
c1a04675 |
10 | |
11 | # set up and populate schema |
12 | ok(my $schema = DBICTest->init_schema(), 'got schema'); |
13 | |
66d02e24 |
14 | my $config_dir = io->catfile(qw't var configs')->name; |
c1a04675 |
15 | |
8ce68ce4 |
16 | { |
17 | # do dump |
18 | ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); |
66d02e24 |
19 | ok($fixtures->dump({ config => 'simple.json', schema => $schema, directory => io->catfile(qw't var fixtures')->name }), 'simple dump executed okay'); |
c1a04675 |
20 | |
8ce68ce4 |
21 | # check dump is okay |
66d02e24 |
22 | my $dir = dir(io->catfile(qw't var fixtures artist')->name); |
23 | ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created'); |
c1a04675 |
24 | |
8ce68ce4 |
25 | my @children = $dir->children; |
26 | is(scalar(@children), 1, 'right number of fixtures created'); |
c1a04675 |
27 | |
8ce68ce4 |
28 | my $fix_file = $children[0]; |
29 | my $HASH1; eval($fix_file->slurp()); |
30 | is(ref $HASH1, 'HASH', 'fixture evals into hash'); |
c1a04675 |
31 | |
8ce68ce4 |
32 | is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys'); |
c1a04675 |
33 | |
8ce68ce4 |
34 | my $artist = $schema->resultset('Artist')->find($HASH1->{artistid}); |
35 | is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row'); |
c1a04675 |
36 | |
8ce68ce4 |
37 | $schema->resultset('Artist')->delete; # so we can create the row again on the next line |
38 | ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture'); |
39 | } |
40 | |
41 | { |
42 | # do dump with hashref config |
43 | ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); |
44 | ok($fixtures->dump({ |
45 | config => { |
46 | "might_have" => { |
47 | "fetch" => 0 |
48 | }, |
49 | "has_many" => { |
50 | "fetch" => 0 |
51 | }, |
52 | "sets" => [{ |
53 | "class" => "Artist", |
54 | "quantity" => 1 |
55 | }] |
56 | }, |
57 | schema => $schema, |
66d02e24 |
58 | directory => io->catfile(qw't var fixtures')->name, |
8ce68ce4 |
59 | }), 'simple dump executed okay'); |
60 | |
61 | # check dump is okay |
66d02e24 |
62 | my $dir = dir(io->catfile(qw't var fixtures artist')->name); |
63 | ok(-e io->catfile(qw't var fixtures artist')->name, 'artist directory created'); |
8ce68ce4 |
64 | |
65 | my @children = $dir->children; |
66 | is(scalar(@children), 1, 'right number of fixtures created'); |
67 | |
68 | my $fix_file = $children[0]; |
69 | my $HASH1; eval($fix_file->slurp()); |
70 | is(ref $HASH1, 'HASH', 'fixture evals into hash'); |
71 | |
72 | is_deeply([sort $schema->source('Artist')->columns], [sort keys %{$HASH1}], 'fixture has correct keys'); |
73 | |
74 | my $artist = $schema->resultset('Artist')->find($HASH1->{artistid}); |
75 | is_deeply({$artist->get_columns}, $HASH1, 'dumped fixture is equivalent to artist row'); |
76 | |
77 | $schema->resultset('Artist')->delete; # so we can create the row again on the next line |
78 | ok($schema->resultset('Artist')->create($HASH1), 'new dbic row created from fixture'); |
79 | } |