kentfredric (owner)

Revisions

gist: 222958 Download_button fork
public
Public Clone URL: git://gist.github.com/222958.git
Embed All Files: show embed
Diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Index: t/03crosstable_leak.t
===================================================================
--- t/03crosstable_leak.t (revision 0)
+++ t/03crosstable_leak.t (revision 0)
@@ -0,0 +1,44 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+use Digest;
+
+use File::Spec;
+use FindBin '$Bin';
+use lib File::Spec->catdir( $Bin, 'lib' );
+
+#1
+use_ok("DigestTest");
+
+# ABOUT THIS TEST;
+#
+# TableA is not encoded.
+# TableB is encoded.
+#
+# Both share a field with the same name.
+#
+# This test is to demonstrate, that one is inheriting the encoding options wrongly from the other.
+#
+
+my $schema = DigestTest->init_schema;
+my $tablea = $schema->resultset('TableA');
+my $tableb = $schema->resultset('TableB');
+
+my $objecta = $tablea->create( { conflicting_name => 'foo' } );
+my $objectb = $tableb->create( { conflicting_name => 'bar' } );
+
+is( $objecta->conflicting_name, 'foo', 'Table requested to not be encoded is not encoded' );
+unlike( $objectb->conflicting_name, qr/^(bar|foo)$/, 'Table requested to be encoded is encoded' );
+
+is( $objecta->can('check_conflict'), undef, 'Table that is requested to not be encoded has no check_conflict method' );
+ok( $objectb->can('check_conflict'), 'Table that is requested encoded has check_conflict method' );
+
+END {
+
+ # In the END section so that the test DB file gets closed before we attempt to unlink it
+ DigestTest::clear($schema);
+}
+
+1;
Index: t/lib/DigestTest/Schema/TableA.pm
===================================================================
--- t/lib/DigestTest/Schema/TableA.pm (revision 0)
+++ t/lib/DigestTest/Schema/TableA.pm (revision 0)
@@ -0,0 +1,25 @@
+package # hide from PAUSE
+ DigestTest::Schema::TableA;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/EncodedColumn Core/);
+__PACKAGE__->table('tablea');
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'int',
+ is_nullable => 0,
+ is_auto_increment => 1
+ },
+ conflicting_name => {
+ data_type => 'char',
+ size => 43,
+ encode_column => 0,
+ encode_class => 'Digest',
+ encode_check_method => 'check_conflict',
+ },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
Index: t/lib/DigestTest/Schema/TableB.pm
===================================================================
--- t/lib/DigestTest/Schema/TableB.pm (revision 0)
+++ t/lib/DigestTest/Schema/TableB.pm (revision 0)
@@ -0,0 +1,25 @@
+package # hide from PAUSE
+ DigestTest::Schema::TableB;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/EncodedColumn Core/);
+__PACKAGE__->table('tableb');
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'int',
+ is_nullable => 0,
+ is_auto_increment => 1
+ },
+ conflicting_name => {
+ data_type => 'char',
+ size => 43,
+ encode_column => 1,
+ encode_class => 'Digest',
+ encode_check_method => 'check_conflict',
+ },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
Index: t/lib/DigestTest/Schema.pm
===================================================================
--- t/lib/DigestTest/Schema.pm (revision 7824)
+++ t/lib/DigestTest/Schema.pm (working copy)
@@ -3,6 +3,6 @@
 
 use base qw/DBIx::Class::Schema/;
 
-__PACKAGE__->load_classes(qw/Test/);
+__PACKAGE__->load_classes(qw/Test TableA TableB/);
 
 1;