Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make updates "just work"; add a delete method
- Loading branch information
Showing
3 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 7; | ||
|
||
use Directory::Scratch; | ||
use MooseX::Storage::Directory; | ||
|
||
{ | ||
package Test; | ||
use Moose; | ||
use MooseX::Storage; | ||
with 'MooseX::Storage::Directory::Id'; | ||
|
||
has 'id' => ( is => 'ro', isa => 'Int', required => 1 ); | ||
has 'foo' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
|
||
sub get_id { return shift->id } | ||
} | ||
|
||
my $tmp = Directory::Scratch->new; | ||
|
||
my $dir = MooseX::Storage::Directory->new( | ||
directory => qq{$tmp}, | ||
class => Test->meta, | ||
); | ||
|
||
ok $dir, 'created directory'; | ||
|
||
|
||
my $foo = Test->new( id => 1, foo => 'Hello' ); | ||
$dir->store($foo); | ||
|
||
is [$dir->search({ foo => 'Hello' })]->[0]->id, 1; | ||
|
||
$foo = Test->new( id => 1, foo => 'Not hello' ); | ||
$dir->store($foo); | ||
|
||
ok !eval { [$dir->search({ foo => 'Hello' })]->[0]->id }, 'didnt get old object'; | ||
is [$dir->search({ foo => 'Not hello' })]->[0]->id, 1, 'did get new object'; | ||
|
||
ok $tmp->exists('1.json'); | ||
$dir->delete($foo); | ||
ok !$tmp->exists('1.json'); | ||
|
||
my @id = $dir->index->query_with_prototype({ foo => 'Not hello'}); | ||
is scalar @id, 0, 'no matching records'; |