Update Firebird ODBC driver download URL
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 50rt59849.t
CommitLineData
0f21885a 1# test for loading additional methods from file-defined packages
2# by Mark Hedges ( hedges -at| scriptdolphin.com )
3
4use strict;
f8c2ca5e 5use warnings;
0f21885a 6use Test::More tests => 7 * 5;
7use Test::Exception;
8
9use lib 't/lib';
10
11use make_dbictest_db;
12
13use DBIx::Class::Schema::Loader;
14
15$ENV{SCHEMA_LOADER_BACKCOMPAT} = 1;
16
17# In the first test run, then, Foo should be a DBICTestMethods::Namespaces::Schema::Result::Foo
18
19run_test_sequence(
20 testname => "naming => 'current'",
21 schema_class => 'DBICTestMethods::Namespaces::Schema',
22 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
23 schema_opts => {
24 naming => 'current',
25 },
26);
27
28# In the second test run with use_namespaces => 0 (backcompat), Foo should be a DBICTestMethods::Backcompat::Schema
29
30run_test_sequence(
31 testname => "naming => 'current', use_namespaces => 0",
32 schema_class => 'DBICTestMethods::Backcompat::Schema',
33 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
34 schema_opts => {
35 naming => 'current',
36 use_namespaces => 0,
37 },
38);
39
40# In the third test, with use_namespaces => 1, Foo gets the explicit Result class again
41
42run_test_sequence(
43 testname => "naming => 'current', use_namespaces => 1",
44 schema_class => 'DBICTestMethods::Namespaces::Schema',
45 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
46 schema_opts => {
47 naming => 'current',
48 use_namespaces => 1,
49 },
50);
51
52# try it in full backcompat 0.04006 mode with no schema options
53
54run_test_sequence(
55 testname => "no naming or namespaces options (0.04006 mode)",
56 schema_class => 'DBICTestMethods::Backcompat::Schema',
57 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
58 schema_opts => {
59 },
60);
61
62# try it in backcompat mode (no naming option) but with use_namespaces => 1
63
64run_test_sequence(
65 testname => "no naming, but with use_namespaces options (0.04006 mode)",
66 schema_class => 'DBICTestMethods::Namespaces::Schema',
67 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
68 schema_opts => {
69 use_namespaces => 1,
70 },
71);
72
73sub run_test_sequence {
74 my %p = @_;
494e0205 75 die "specify a $_ test param" for grep !$p{$_},
0f21885a 76 qw( testname schema_opts schema_class foo_class );
77
494e0205 78 my $schema;
0f21885a 79 lives_ok { $schema = make_schema_with(%p) } "($p{testname}) get schema";
80
81 SKIP: {
82 skip 'no point in checking if schema could not be connected', 6 unless defined $schema;
83
84 # well, if that worked, try to get a ResultSet
85 my $foo_rs;
86 lives_ok {
87 $foo_rs = $schema->resultset('Foo')->search();
88 } "($p{testname}) get a ResultSet for Foo";
494e0205 89
0f21885a 90 # get a foo
91 my $foo;
92 lives_ok {
93 $foo = $foo_rs->first();
94 } "($p{testname}) get the first foo";
494e0205 95
0f21885a 96 ok(defined $foo, "($p{testname}) \$foo is defined");
494e0205 97
0f21885a 98 SKIP: {
99 skip 'foo is not defined', 3 unless defined $foo;
494e0205 100
0f21885a 101 isa_ok $foo, $p{foo_class};
494e0205 102
0f21885a 103 # call the file-defined method
104 my $biz;
105 lives_ok {
106 $biz = $foo->biz();
107 } "($p{testname}) call the file-defined Foo->biz method";
494e0205 108
0f21885a 109 SKIP: {
110 skip 'no point in checking value if method was not found', 1 unless defined $biz;
494e0205 111
0f21885a 112 ok(
494e0205 113 $biz eq 'foo bar biz baz boz noz schnozz',
0f21885a 114 "($p{testname}) biz() method returns correct string"
115 );
116 }
117 }
118 }
119}
494e0205 120
0f21885a 121sub make_schema_with {
122 my %p = @_;
123 return DBIx::Class::Schema::Loader::make_schema_at(
124 $p{schema_class},
125 $p{schema_opts},
126 [ $make_dbictest_db::dsn ],
127 );
128}