Changeset 299

Show
Ignore:
Timestamp:
05/18/06 18:19:44 (6 years ago)
Author:
nick
Message:

Improve the node versions listing code and tests

Location:
wiki-toolkit/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm

    r298 r299  
    14641464    $sth->execute( $node_id ); 
    14651465 
     1466        # Need to hold onto the last row by hash ref, so we don't trash 
     1467        #  it every time 
     1468        my %first_data; 
     1469        my $dataref = \%first_data; 
     1470 
    14661471        # Haul out the data 
    14671472        my @versions; 
    14681473        while(my @results = $sth->fetchrow_array) { 
    1469                 # TODO: Support metadata multi-rows 
    1470                 my %data; 
     1474                my %data = %$dataref; 
     1475 
     1476                # Is it the same version as last time? 
     1477                if(%data && $data{'version'} != $results[2]) { 
     1478                        # New version 
     1479                        push @versions, $dataref; 
     1480                        %data = (); 
     1481                } else { 
     1482                        # Same version as last time, must be more metadata 
     1483                } 
     1484 
     1485                # Grab the core data (will be the same on multi-row for metadata) 
    14711486                @data{ qw( node_id name version last_modified ) } = @results; 
    14721487 
     
    14771492                } 
    14781493                if($with_metadata) { 
    1479                         warn("Not supported properly yet"); 
     1494                        my ($m_type,$m_value) = @results[$i,($i+1)]; 
     1495                        $data{'metadata'}->{$m_type} = $m_value; 
    14801496                } 
    14811497 
    1482                 push @versions, \%data; 
     1498                # Save where we've got to 
     1499                $dataref = \%data; 
     1500        } 
     1501 
     1502        # Handle final row saving 
     1503        if($dataref) { 
     1504                push @versions, $dataref; 
    14831505        } 
    14841506 
  • wiki-toolkit/trunk/t/025_list_node_all_versions.t

    r298 r299  
    66    plan skip_all => "no backends configured"; 
    77} else { 
    8     plan tests => ( 9 * scalar @Wiki::Toolkit::TestLib::wiki_info ); 
     8    plan tests => ( 22 * scalar @Wiki::Toolkit::TestLib::wiki_info ); 
    99} 
    1010 
     
    4545 
    4646        # Fetch with content too 
     47        @all_versions = $wiki->list_node_all_versions( 
     48                                                                name => "Cheese", 
     49                                                                with_content => 1 
     50        ); 
     51 
     52        is( scalar @all_versions, 4, "list_node_all_versions gives the right number back" ); 
     53 
     54        # Check them 
     55        is( $all_versions[0]->{'version'}, 4, "right ordering" ); 
     56        is( $all_versions[1]->{'version'}, 3, "right ordering" ); 
     57        is( $all_versions[2]->{'version'}, 2, "right ordering" ); 
     58        is( $all_versions[3]->{'version'}, 1, "right ordering" ); 
     59        is( $all_versions[0]->{'name'}, "Cheese", "right node" ); 
     60        is( $all_versions[1]->{'name'}, "Cheese", "right node" ); 
     61        is( $all_versions[2]->{'name'}, "Cheese", "right node" ); 
     62        is( $all_versions[3]->{'name'}, "Cheese", "right node" ); 
     63        is( $all_versions[0]->{'content'}, "Content v4", "right node" ); 
     64        is( $all_versions[1]->{'content'}, "Content v3", "right node" ); 
     65        is( $all_versions[2]->{'content'}, "Content v2", "right node" ); 
     66        is( $all_versions[3]->{'content'}, "content", "right node" ); 
    4767 
    4868        # With metadata