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