Ticket #23: decline_null_change.patch

File decline_null_change.patch, 4.8 KB (added by tgj, 13 years ago)
  • t/401.null_change.t

     
     1use strict;
     2use Wiki::Toolkit::TestLib;
     3use Test::More;
     4
     5if ( scalar @Wiki::Toolkit::TestLib::wiki_info == 0 ) {
     6    plan skip_all => "no backends configured";
     7} else {
     8    plan tests => ( 4 * scalar @Wiki::Toolkit::TestLib::wiki_info );
     9}
     10
     11my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker;
     12
     13my $metadata_orig = { foo => [ 7 ], bar => [ 9 ] };
     14my $metadata_changed = { foo => [ "changed" ], bar => [ 9 ] };
     15my $content_orig = "Node content.";
     16my $content_changed = "Node content -- changed";
     17my $id = "A Node";
     18
     19while ( my $wiki = $iterator->new_wiki ) {
     20    $wiki->write_node($id, $content_orig, undef, $metadata_orig );
     21
     22    my %node_data = $wiki->retrieve_node($id);
     23
     24    is( $wiki->write_node(
     25            $id, $content_orig, $node_data{checksum},
     26            $metadata_orig,
     27        ),
     28        -1,
     29        "refuses to update if new content and metadata is the same",
     30    );
     31
     32    %node_data = $wiki->retrieve_node($id);
     33
     34    ok( $wiki->write_node(
     35            $id, $content_orig, $node_data{checksum},
     36            $metadata_changed,
     37        ) >= 1,
     38        "still updates if metadata is different",
     39    );
     40   
     41    %node_data = $wiki->retrieve_node($id);
     42
     43    ok( $wiki->write_node(
     44            $id, $content_changed, $node_data{checksum},
     45            $metadata_changed,
     46        ) >= 1,
     47        "still updates if content is different",
     48    );
     49
     50    %node_data = $wiki->retrieve_node($id);
     51
     52    is( $wiki->write_node(
     53            $id, $content_changed, $node_data{checksum},
     54            $metadata_changed,
     55        ),
     56        -1,
     57        "... and refuses again when nothing changed",
     58    );
     59}
  • lib/Wiki/Toolkit/Store/Database.pm

     
    450450Making sure that locking/unlocking/transactions happen is left up to
    451451you (or your chosen subclass). This method shouldn't really be used
    452452directly as it might overwrite someone else's changes. Croaks on error
    453 but otherwise returns the version number of the update just made.
     453but otherwise returns the version number of the update just made.  A
     454return value of -1 indicates that the change was not applied.  This
     455may be because the plugins voted against the change, or because the
     456content and metadata in the proposed new version were identical to the
     457current version (a "null" change).
    454458
    455459Supplying a ref to an array of nodes that this ones links to is
    456460optional, but if you do supply it then this node will be returned when
     
    513517        return -1;
    514518    }
    515519
     520    if( $self->_checksum(%args) eq $args{checksum} ) {
     521        # Refuse to commit as nothing has changed
     522        return -1;
     523    }
     524
    516525    # Either inserting a new page or updating an old one.
    517526    my $sql = "SELECT count(*) FROM node WHERE name=" . $dbh->quote($node);
    518527    my $exists = @{ $dbh->selectcol_arrayref($sql) }[0] || 0;
  • lib/Wiki/Toolkit/Store/MySQL.pm

     
    4646Locks the node, verifies the checksum, calls
    4747C<write_node_post_locking> with all supplied arguments, unlocks the
    4848node. Returns the version of the updated node on successful writing, 0 if
    49 checksum doesn't match, croaks on error.
     49checksum doesn't match, -1 if the change was not applied, croaks on error.
    5050
    5151Note:  Uses MySQL's user level locking, so any locks are released when
    5252the database handle disconnects.  Doing it like this because I can't seem
  • lib/Wiki/Toolkit/Store/Pg.pm

     
    4646Locks the node, verifies the checksum, calls
    4747C<write_node_post_locking> with all supplied arguments, unlocks the
    4848node. Returns the version of the updated node on successful writing, 0 if
    49 checksum doesn't match, croaks on error.
     49checksum doesn't match, -1 if the change was not applied, croaks on error.
    5050
    5151=cut
    5252
  • lib/Wiki/Toolkit/Store/SQLite.pm

     
    5757Locks the node, verifies the checksum, calls
    5858C<write_node_post_locking> with all supplied arguments, unlocks the
    5959node. Returns the version of the updated node on successful writing, 0 if
    60 checksum doesn't match, croaks on error.
     60checksum doesn't match, -1 if the change was not applied, croaks on error.
    6161
    6262=cut
    6363