New test which attempts to add a new relationship to an existing class, after
Toby Corkindale [Thu, 4 Jun 2009 08:35:57 +0000 (08:35 +0000)]
the schema has been initialised.
Currently the test fails, as the relationship is not added.
Discussion on IRC indicates this probably *should* work.

t/relationship/afterthought.t [new file with mode: 0644]

diff --git a/t/relationship/afterthought.t b/t/relationship/afterthought.t
new file mode 100644 (file)
index 0000000..fb2bd82
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;  
+
+use Test::More tests => 2;
+use lib qw(t/lib);
+use DBICTest;
+
+=head1 DESCRIPTION
+
+Attempt to add a relationship to a class *after* they've been initialised..
+
+=cut
+
+my $schema = DBICTest->init_schema();
+
+my @previous_rels = sort $schema->source('Artist')->relationships;
+
+my $class = $schema->class('Artist');
+$class->belongs_to('rank' => $schema->class('Lyrics'));
+
+# Now check we have the relationship:
+my $source = $schema->source('Artist');
+
+is_deeply(
+    [sort $source->relationships],
+    [sort(@previous_rels, 'rank')],
+    'Found rank in relationships'
+);
+
+ok($source->relationship_info('rank'), "We have relationship info for rank");
+