Skip to content

Commit

Permalink
add in the fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Jan 22, 2011
1 parent ec2ee8d commit a68b662
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 3 deletions.
76 changes: 76 additions & 0 deletions lib/Test/Jackalope/Fixtures/Manager/REST.pm
@@ -0,0 +1,76 @@
package Test::Jackalope::Fixtures::Manager::REST;
use Moose;
use Resource::Pack;

our $VERSION = '0.01';
our $AUTHORITY = 'cpan:STEVAN';

extends 'Test::Jackalope::Fixtures::Manager';

has '+name' => ( default => __PACKAGE__ );
has '+fixtures_root' => (
default => sub {
Path::Class::File->new( __FILE__ )->parent->parent
},
);

sub BUILD {
my $self = shift;
resource $self => as {
resource 'REST' => as {
install_from( $self->fixtures_root->subdir('REST') );

file 'resource' => 'resource.json';
file 'resource_ref' => 'resource_ref.json';
file 'service_crud' => 'service_crud.json';
};
};
}

__PACKAGE__->meta->make_immutable;

no Moose; no Resource::Pack; 1;


__END__
=pod
=head1 NAME
Test::Jackalope::Fixtures::Manager::REST - A Moosey solution to this problem
=head1 SYNOPSIS
use Test::Jackalope::Fixtures::Manager::REST;
=head1 DESCRIPTION
=head1 METHODS
=over 4
=item B<>
=back
=head1 BUGS
All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
=head1 AUTHOR
Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2011 Infinity Interactive, Inc.
L<http://www.iinteractive.com>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
110 changes: 110 additions & 0 deletions lib/Test/Jackalope/Fixtures/REST/resource.json
@@ -0,0 +1,110 @@
[
{
"schema" : { "$ref" : "jackalope/rest/resource" },
"pass" : [
{
"id" : "id:1010",
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
},
{
"id" : "id:1010",
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403"
},
{
"id" : "id:something",
"body" : {
"first_name" : "Stevan",
"last_name" : "Little",
"age" : 37
},
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : [
{ "rel" : "self", "href" : "/", "method" : "GET" },
{ "rel" : "create", "href" : "/", "method" : "POST" },
{ "rel" : "read", "href" : "/1", "method" : "GET" },
{ "rel" : "update", "href" : "/1", "method" : "PUT" },
{ "rel" : "delete", "href" : "/1", "method" : "DELETE" }
]
}
],
"fail" : [
{
"id" : "id:1010",
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : {}
},
{
"id" : [],
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
},
{
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
},
{
"id" : "id:1010",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
},
{
"id" : "id:1010",
"body" : "Data",
"links" : []
}
]
},
{
"schema" : {
"extends" : { "$ref" : "jackalope/rest/resource" },
"properties" : {
"body" : {
"type" : "object",
"properties" : {
"first_name" : { "type" : "string" },
"last_name" : { "type" : "string" },
"age" : { "type" : "integer", "greater_than" : 0 }
}
}
}
},
"pass" : [
{
"id" : "id:something",
"body" : {
"first_name" : "Stevan",
"last_name" : "Little",
"age" : 37
},
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : [
{ "rel" : "self", "href" : "/", "method" : "GET" },
{ "rel" : "create", "href" : "/", "method" : "POST" },
{ "rel" : "read", "href" : "/1", "method" : "GET" },
{ "rel" : "update", "href" : "/1", "method" : "PUT" },
{ "rel" : "delete", "href" : "/1", "method" : "DELETE" }
]
}
],
"fail" : [
{
"id" : "id:1010",
"body" : "Data",
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
},
{
"id" : "id:1012",
"body" : { "first_name" : "Stevan", "last_name" : "Little" },
"version" : "4162F712-1DD2-11B2-B17E-C09EFE1DC403",
"links" : []
}
]
}
]
69 changes: 69 additions & 0 deletions lib/Test/Jackalope/Fixtures/REST/resource_ref.json
@@ -0,0 +1,69 @@
[
{
"schema" : { "$ref" : "jackalope/rest/resource/ref" },
"pass" : [
{ "$id" : "1", "type_of" : "some/simple/schema" },
{ "$id" : "1", "type_of" : "some/simple/schema", "version" : "2i29219jkjklewioewjklewk" },
{
"$id" : "1",
"type_of" : "some/simple/schema",
"version" : "2i29219jkjklewioewjklewk",
"link" : { "rel" : "read", "method" : "GET", "href" : "some/simple/1" }
},
{
"$id" : "1",
"type_of" : "some/simple/schema",
"link" : { "rel" : "read", "method" : "GET", "href" : "some/simple/1" }
}
],
"fail" : [
{ "$id" : "1" },
{ "type_of" : "some/simple/schema" },
{
"$id" : "1",
"type_of" : "some/simple/schema",
"link" : { "rel" : "read", "method" : "POST", "href" : "some/simple/1" }
},
{
"$id" : "1",
"type_of" : "some/simple/schema",
"link" : { "rel" : "create", "method" : "GET", "href" : "some/simple/1" }
},
null,
true,
false,
1,
1.5,
"Hello",
[],
[ 1, 5, 6 ],
{ "foo" : "bar" }
]
},
{
"schema" : {
"extends" : { "$ref" : "jackalope/rest/resource/ref" },
"properties" : {
"type_of" : { "type" : "string", "literal" : "some/simple/schema" }
}
},
"pass" : [
{ "$id" : "1", "type_of" : "some/simple/schema" },
{ "$id" : "1", "type_of" : "some/simple/schema", "version" : "2i29219jkjklewioewjklewk" }
],
"fail" : [
{ "$id" : "1", "type_of" : "some/other/simple/schema" },
{ "$id" : "1" },
{ "type_of" : "some/simple/schema" },
null,
true,
false,
1,
1.5,
"Hello",
[],
[ 1, 5, 6 ],
{ "foo" : "bar" }
]
}
]
18 changes: 18 additions & 0 deletions lib/Test/Jackalope/Fixtures/REST/service_crud.json
@@ -0,0 +1,18 @@
[
{
"schema" : { "$ref" : "jackalope/rest/service/crud" },
"pass" : [
{ "foo" : "bar" }
],
"fail" : [
null,
true,
false,
1,
1.5,
"Hello",
[],
[ 1, 5, 6 ]
]
}
]
7 changes: 4 additions & 3 deletions t/030-REST/010-schema-spec.t
Expand Up @@ -2,12 +2,12 @@

use strict;
use warnings;
use FindBin;

use Test::More;
use Test::Fatal;
use Test::Jackalope;
use Test::Jackalope::Fixtures;
use Test::Jackalope::Fixtures::Manager::REST;

BEGIN {
use_ok('Jackalope::REST');
Expand All @@ -19,8 +19,9 @@ my $repo = Jackalope::REST->new->resolve(
isa_ok($repo, 'Jackalope::Schema::Repository');

my $fixtures = Test::Jackalope::Fixtures->new(
fixture_dir => [ $FindBin::Bin, '..', '..', 'tests', 'fixtures' ],
repo => $repo
fixture_manager => Test::Jackalope::Fixtures::Manager::REST->new,
fixture_set => 'REST',
repo => $repo
);

foreach my $type ( qw[ resource resource/ref service/crud ] ) {
Expand Down

0 comments on commit a68b662

Please sign in to comment.