[Omaha.pm] find_or_create() your own test data
Jay Hannah
jhannah at omnihotels.com
Mon May 24 18:00:10 PDT 2010
:) This is pretty cute, and I haven't done it in a while.
I need to run a bunch of tests against a fake hotel we have called
'SEED'. But that row was missing from one of our cross-reference tables
(XfHotelcode). So I wrote a 00_SEED_setup.t, which runs before any of
the real tests, which uses DBIx::Class to find or create the row in the
database table that I need.
Omni2::Model::DB2 is our own wrapper than just returns a
properly-connected DBIx::Class::Schema object.
Pretty slick.
j
$ perl 00_SEED_setup.t
1..1
ok 1 - OM SEED is in xf_hotelCode
$ cat 00_SEED_setup.t
use Test::More tests => 1;
use strict;
use Omni2::Model::DB2;
my $schema = Omni2::Model::DB2::connect( system => 'dal_repl', method =>
'DBIC' );
my $row = $schema->resultset('XfHotelcode')->find_or_create(
chaincode => 'OM',
hotelcode => 'SEED',
status => 'A',
long_descr => 'Test Hotel',
);
is_deeply([ $row->id ], [ 'OM', 'SEED' ], "OM SEED is in
xf_hotelCode");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20100524/5d13c8f6/attachment.html>
More information about the Omaha-pm
mailing list