set_related_objects_column method
[blog.pm-common-perl-mods.git] / Common-RDBO-Helpers / t / get_objects_cloud.t
blob8e19c301eb05675c2fc38abb183fd398809a6e4f
1 #! /usr/bin/perl
3 use lib 't/lib';
5 use Test::More 'tests' => 2;
7 use NewDB;
8 use Post;
9 use Post::Manager;
10 use Tag;
11 use Tag::Manager;
13 my $db = NewDB->new();
15 $db->init();
17 my @data = (
19 addtime => time,
20 title => 'Linux',
21 content => 'blah-blah',
22 tags => [ { name => 'linux' }, { name => 'unix' }, { name => 'bsd' }, ]
25 addtime => time + 5,
26 title => 'Unix',
27 content => 'blah-blah',
28 tags => [ { name => 'linux' }, { name => 'unix' }, ]
31 addtime => time + 10,
32 title => 'BSD',
33 content => 'blah-blah',
34 tags => [ { name => 'linux' }, ]
38 foreach my $data ( @data ) {
39 my $tags = delete $data->{ tags };
41 my $tag = Post->new( %$data );
43 $tag->tags( $tags );
45 $tag->save( cascade => 1 );
48 my $tags = Tag::Manager->get_tags();
50 is( scalar @$tags, 3 );
52 $cloud = Tag::Manager->get_objects_cloud(
53 rel_name => 'post_tag_map',
54 active_column => 'name',
55 count_method => 'count'
58 is_deeply(
59 $cloud,
62 'level' => 0,
63 'count' => 1,
64 'name' => 'bsd',
65 'id' => '3'
68 'level' => 3,
69 'count' => 3,
70 'name' => 'linux',
71 'id' => '1'
74 'level' => 1,
75 'count' => 2,
76 'name' => 'unix',
77 'id' => '2'
83 my $posts = Post::Manager->get_objects();
84 $_->delete( cascade => 1 ) foreach @$posts;