Very basic tests for DBIC:Positioned.
Aran Deltac [Sun, 19 Mar 2006 06:12:21 +0000 (06:12 +0000)]
t/helperrels/26positioned.t [new file with mode: 0644]
t/lib/DBICTest/Schema/Artist.pm
t/lib/sqlite.sql
t/run/04db.tl
t/run/26positioned.tl [new file with mode: 0644]

diff --git a/t/helperrels/26positioned.t b/t/helperrels/26positioned.t
new file mode 100644 (file)
index 0000000..8e42bbd
--- /dev/null
@@ -0,0 +1,7 @@
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBICTest::HelperRels;
+
+require "t/run/26positioned.tl";
+run_tests(DBICTest->schema);
index f4c6706..996f53c 100644 (file)
@@ -3,7 +3,7 @@ package # hide from PAUSE
 
 use base 'DBIx::Class::Core';
 
-__PACKAGE__->load_components('PK::Auto');
+__PACKAGE__->load_components('Positioned','PK::Auto');
 
 DBICTest::Schema::Artist->table('artist');
 DBICTest::Schema::Artist->add_columns(
@@ -16,12 +16,17 @@ DBICTest::Schema::Artist->add_columns(
     size      => 100,
     is_nullable => 1,
   },
+  position => {
+    data_type => 'integer',
+  },
 );
 DBICTest::Schema::Artist->set_primary_key('artistid');
+__PACKAGE__->position_column('position');
 
 __PACKAGE__->mk_classdata('field_name_for', {
     artistid    => 'primary key',
     name        => 'artist name',
+    position    => 'list position',
 });
 
 1;
index 391de14..7dde18e 100644 (file)
@@ -35,7 +35,8 @@ CREATE TABLE liner_notes (
 --
 CREATE TABLE artist (
   artistid INTEGER PRIMARY KEY NOT NULL,
-  name varchar
+  name varchar,
+  position INTEGER
 );
 
 --
index 424948c..2c91ed8 100644 (file)
@@ -39,7 +39,12 @@ my $test_type_info = {
         'data_type' => 'varchar',
         'is_nullable' => 0,
         'size' => undef,
-    }
+    },
+    'position' => {
+        'data_type' => 'INTEGER',
+        'is_nullable' => 0,
+        'size' => undef,
+    },
 };
 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
 
diff --git a/t/run/26positioned.tl b/t/run/26positioned.tl
new file mode 100644 (file)
index 0000000..8981ca1
--- /dev/null
@@ -0,0 +1,17 @@
+# vim: filetype=perl
+
+sub run_tests {
+
+    my $schema = shift;
+    my $artists = $schema->resultset("Artist")->search({},{order_by=>'position'});
+
+    plan tests => $artists->count();
+
+    my $expected_position = 0;
+    while (my $artist = $artists->next()) {
+        $expected_position ++;
+        ok( ($artist->position()==$expected_position), 'default positions set as expected' );
+    }
+}
+
+1;