Showing 2 changed files with 66 additions and 68 deletions
+66
t/common.t
... ...
@@ -3787,6 +3787,72 @@ $result = $dbi->select(
3787 3787
 );
3788 3788
 is_deeply($result->all, [{'table2.key3' => 4}]);
3789 3789
 
3790
+test 'Model class';
3791
+use MyDBI1;
3792
+$dbi = MyDBI1->connect;
3793
+eval { $dbi->execute('drop table table1') };
3794
+$dbi->execute($create_table1);
3795
+$model = $dbi->model('table1');
3796
+$model->insert({key1 => 'a', key2 => 'b'});
3797
+is_deeply($model->list->all, [{key1 => 'a', key2 => 'b'}], 'basic');
3798
+eval { $dbi->execute('drop table table2') };
3799
+$dbi->execute($create_table2);
3800
+$model = $dbi->model('table2');
3801
+$model->insert({key1 => 'a'});
3802
+is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'basic');
3803
+is($dbi->models->{'table1'}, $dbi->model('table1'));
3804
+is($dbi->models->{'table2'}, $dbi->model('table2'));
3805
+
3806
+$dbi = MyDBI4->connect;
3807
+eval { $dbi->execute('drop table table1') };
3808
+$dbi->execute($create_table1);
3809
+$model = $dbi->model('table1');
3810
+$model->insert({key1 => 'a', key2 => 'b'});
3811
+is_deeply($model->list->all, [{key1 => 'a', key2 => 'b'}], 'basic');
3812
+eval { $dbi->execute('drop table table2') };
3813
+$dbi->execute($create_table2);
3814
+$model = $dbi->model('table2');
3815
+$model->insert({key1 => 'a'});
3816
+is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'basic');
3817
+
3818
+$dbi = MyDBI5->connect;
3819
+eval { $dbi->execute('drop table table1') };
3820
+eval { $dbi->execute('drop table table2') };
3821
+$dbi->execute($create_table1);
3822
+$dbi->execute($create_table2);
3823
+$model = $dbi->model('table2');
3824
+$model->insert({key1 => 'a'});
3825
+is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'include all model');
3826
+$dbi->insert(table => 'table1', param => {key1 => 1});
3827
+$model = $dbi->model('table1');
3828
+is_deeply($model->list->all, [{key1 => 1, key2 => undef}], 'include all model');
3829
+
3830
+test 'primary_key';
3831
+use MyDBI1;
3832
+$dbi = MyDBI1->connect;
3833
+$model = $dbi->model('table1');
3834
+$model->primary_key(['key1', 'key2']);
3835
+is_deeply($model->primary_key, ['key1', 'key2']);
3836
+
3837
+test 'columns';
3838
+use MyDBI1;
3839
+$dbi = MyDBI1->connect;
3840
+$model = $dbi->model('table1');
3841
+$model->columns(['key1', 'key2']);
3842
+is_deeply($model->columns, ['key1', 'key2']);
3843
+
3844
+test 'setup_model';
3845
+use MyDBI1;
3846
+$dbi = MyDBI1->connect;
3847
+eval { $dbi->execute('drop table table1') };
3848
+eval { $dbi->execute('drop table table2') };
3849
+
3850
+$dbi->execute($create_table1);
3851
+$dbi->execute($create_table2);
3852
+$dbi->setup_model;
3853
+is_deeply([sort @{$dbi->model('table1')->columns}], ['key1', 'key2']);
3854
+is_deeply([sort @{$dbi->model('table2')->columns}], ['key1', 'key3']);
3855
+
3790 3856
 
3791 3857
 
3792 3858
 1;
-68
t/sqlite.t
... ...
@@ -178,74 +178,6 @@ my $binary;
178 178
 # Prepare table
179 179
 $dbi = DBIx::Custom->connect;
180 180
 
181
-### a little complex test
182
-
183
-test 'Model class';
184
-use MyDBI1;
185
-$dbi = MyDBI1->connect;
186
-eval { $dbi->execute('drop table table1') };
187
-$dbi->execute($create_table1);
188
-$model = $dbi->model('table1');
189
-$model->insert({key1 => 'a', key2 => 'b'});
190
-is_deeply($model->list->all, [{key1 => 'a', key2 => 'b'}], 'basic');
191
-eval { $dbi->execute('drop table table2') };
192
-$dbi->execute($create_table2);
193
-$model = $dbi->model('table2');
194
-$model->insert({key1 => 'a'});
195
-is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'basic');
196
-is($dbi->models->{'table1'}, $dbi->model('table1'));
197
-is($dbi->models->{'table2'}, $dbi->model('table2'));
198
-
199
-$dbi = MyDBI4->connect;
200
-eval { $dbi->execute('drop table table1') };
201
-$dbi->execute($create_table1);
202
-$model = $dbi->model('table1');
203
-$model->insert({key1 => 'a', key2 => 'b'});
204
-is_deeply($model->list->all, [{key1 => 'a', key2 => 'b'}], 'basic');
205
-$dbi->execute($create_table2);
206
-$model = $dbi->model('table2');
207
-$model->insert({key1 => 'a'});
208
-is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'basic');
209
-
210
-$dbi = MyDBI5->connect;
211
-eval { $dbi->execute('drop table table1') };
212
-eval { $dbi->execute('drop table table2') };
213
-$dbi->execute($create_table1);
214
-$dbi->execute($create_table2);
215
-$model = $dbi->model('table2');
216
-$model->insert({key1 => 'a'});
217
-is_deeply($model->list->all, [{key1 => 'a', key3 => undef}], 'include all model');
218
-$dbi->insert(table => 'table1', param => {key1 => 1});
219
-$model = $dbi->model('table1');
220
-is_deeply($model->list->all, [{key1 => 1, key2 => undef}], 'include all model');
221
-
222
-test 'primary_key';
223
-use MyDBI1;
224
-$dbi = MyDBI1->connect;
225
-$model = $dbi->model('table1');
226
-$model->primary_key(['key1', 'key2']);
227
-is_deeply($model->primary_key, ['key1', 'key2']);
228
-
229
-test 'columns';
230
-use MyDBI1;
231
-$dbi = MyDBI1->connect;
232
-$model = $dbi->model('table1');
233
-$model->columns(['key1', 'key2']);
234
-is_deeply($model->columns, ['key1', 'key2']);
235
-
236
-test 'setup_model';
237
-use MyDBI1;
238
-$dbi = MyDBI1->connect;
239
-eval { $dbi->execute('drop table table1') };
240
-eval { $dbi->execute('drop table table2') };
241
-
242
-$dbi->execute($create_table1);
243
-$dbi->execute($create_table2);
244
-$dbi->setup_model;
245
-is_deeply($dbi->model('table1')->columns, ['key1', 'key2']);
246
-is_deeply($dbi->model('table2')->columns, ['key1', 'key3']);
247
-
248
-
249 181
 ### SQLite only test
250 182
 test 'prefix';
251 183
 $dbi = DBIx::Custom->connect;