[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] find_or_create() your own test data



:)  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");