make it impossible to have a locked working tag

This commit is contained in:
Paul Driver 2010-04-16 15:24:34 -07:00
parent 7c7136f02a
commit 1a77fce843
2 changed files with 45 additions and 12 deletions

View file

@ -438,15 +438,15 @@ sub getWorking {
#First see if there is already a version tag
$tag = $stow->get(q{versionTag});
return $tag if $tag;
return $tag if ($tag && !$tag->isLocked);
$tagId = $session->scratch()->get(q{versionTag});
if ($tagId) {
$tag = $class->new($session, $tagId);
$stow->set(q{versionTag}, $tag);
return $tag;
unless ($tag->isLocked) {
$stow->set(q{versionTag}, $tag);
return $tag;
}
}
#No tag found. Create or reclaim one?
@ -475,10 +475,10 @@ sub getWorking {
# For now, we only reclaim if 1 tag open.
if (scalar @openTags == 1) {
$tag = $openTags[0];
$tag->setWorking();
return $tag;
unless ($tag->isLocked) {
$tag->setWorking();
return $tag;
}
}
}
elsif ($mode eq q{siteWide}) {
@ -486,7 +486,7 @@ sub getWorking {
OPENTAG:
foreach my $openTag (@{WebGUI::VersionTag->getOpenTags($session)}) {
if ($openTag->get(q{isSiteWide})) {
if ($openTag->get(q{isSiteWide}) && !$openTag->isLocked) {
$tag = $openTag;
@ -515,6 +515,16 @@ sub getWorking {
#-------------------------------------------------------------------
=head2 isLocked ( )
Returns boolean value indicating whether tag is locked
=cut
sub isLocked { $_[0]{_data}{isLocked} }
#-------------------------------------------------------------------
=head2 leaveTag ( )
Make the user leave their current tag.
@ -734,6 +744,7 @@ Sets this tag as the working tag for the current user.
sub setWorking {
my $self = shift;
return if $self->isLocked;
$self->session->scratch->set("versionTag",$self->getId);
$self->session->stow->set("versionTag", $self);
}

View file

@ -14,7 +14,7 @@ use lib "$FindBin::Bin/lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::VersionTag;
use Test::More tests => 74; # increment this value for each test you create
use Test::More tests => 81; # increment this value for each test you create
my $session = WebGUI::Test->session;
@ -105,14 +105,36 @@ $tag->clearWorking;
ok(!defined getWorking(1), 'working tag unset');
ok(!scalar $tag->get('isLocked'), 'tag is initially unlocked');
ok(!$tag->isLocked,'accessor for isLocked works on false');
$tag->lock;
ok(scalar $tag->get('isLocked'), 'tag is locked');
ok($tag->isLocked, 'accessor for isLocked works on true');
ok_open($tag->getId, 0, 'locked tag');
$tag->unlock;
ok(!scalar $tag->get('isLocked'), 'tag is again unlocked');
ok_open($tag->getId, 1, 'unlocked tag');
# TODO: test interaction between lock/unlock and working tags
# test interaction between lock/unlock and working tags
my $locker = WebGUI::VersionTag->create($session);
$locker->setWorking();
is getWorking(1), $locker, 'working tag is the one we are about to lock';
$locker->lock();
ok !defined getWorking(1), 'lock clears working';
my $unlocked = WebGUI::VersionTag->create($session);
$unlocked->setWorking();
is getWorking(1), $unlocked, 'working tag is fresh';
$locker->setWorking();
is getWorking(1), $unlocked, 'setWorking on locked tag does nothing';
$unlocked->clearWorking;
$unlocked->rollback;
$session->stow->set(versionTag => $locker);
$session->scratch->set(versionTag => $locker->getId);
isnt getWorking(1), $locker, 'getWorking never returns locked tag';
$locker->clearWorking;
$locker->rollback;
my $tagAgain1 = WebGUI::VersionTag->new($session, $tag->getId);
isa_ok($tagAgain1, 'WebGUI::VersionTag', 'tag retrieved again while valid');