File: ToJSON.t

package info (click to toggle)
libdbix-class-helpers-perl 2.036000-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,008 kB
  • sloc: perl: 5,041; sql: 537; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Deep;

use TestSchema;
my $schema = TestSchema->deploy_or_connect();
$schema->prepopulate;

SIMPLE_JSON: {
   my $datas = [
      map $_->TO_JSON,
         $schema->resultset('Bar')->search(undef, { order_by => 'id' })->all
      ];

   cmp_deeply($datas, [map superhashof($_), {
         id => 1,
         foo_id => 1,
      },{
         id => 2,
         foo_id => 2,
      },{
         id => 3,
         foo_id => 3,
      },{
         id => 4,
         foo_id => 4,
      },{
         id => 5,
         foo_id => 5,
   }], 'simple TO_JSON works');
}

MORE_COMPLEX_JSON: {
   my $datas = [
      map $_->TO_JSON,
         $schema->resultset('Gnarly')->search(undef, { order_by => 'id' })->all
      ];

   cmp_deeply($datas, [{
         id => 1,
         name => 'frew',
         your_mom => undef,
      },{
         id => 2,
         name => 'frioux',
         your_mom => undef,
      },{
         id => 3,
         name => 'frooh',
         your_mom => undef,
   }], 'complex TO_JSON works');
}

ACCESSOR_CLASS: {
   my $datas = [
      map $_->TO_JSON,
         $schema->resultset('HasAccessor')->search(undef, { order_by => 'id' })->all
      ];

   cmp_deeply($datas, [{
         id => 1,
         usable_column => 'aa',
         alternate_name => 'bb',
      },{
         id => 2,
         usable_column => 'cc',
         alternate_name => 'dd',
      },{
         id => 3,
         usable_column => 'ee',
         alternate_name => 'ff',
   }], 'accessor fields with TO_JSON works');
}

SERIALIZE_ALL_DATA_TYPES: {
   my $datas = [
      map $_->TO_JSON,
         $schema->resultset('SerializeAll')->search(undef, { order_by => 'id' })->all
      ];

   cmp_deeply($datas, [{
         id => 1,
         text_column => 'frew',
      },{
         id => 2,
         text_column => 'frioux',
      },{
         id => 3,
         text_column => 'frooh',
   }], 'serialize all data types with TO_JSON');
}

done_testing;