From a68b662381a1f6c019a4fcc610010fc142020765 Mon Sep 17 00:00:00 2001 From: Stevan Little Date: Sat, 22 Jan 2011 14:47:00 -0500 Subject: [PATCH] add in the fixtures --- lib/Test/Jackalope/Fixtures/Manager/REST.pm | 76 ++++++++++++ .../Jackalope/Fixtures/REST/resource.json | 110 ++++++++++++++++++ .../Jackalope/Fixtures/REST/resource_ref.json | 69 +++++++++++ .../Jackalope/Fixtures/REST/service_crud.json | 18 +++ t/030-REST/010-schema-spec.t | 7 +- 5 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 lib/Test/Jackalope/Fixtures/Manager/REST.pm create mode 100644 lib/Test/Jackalope/Fixtures/REST/resource.json create mode 100644 lib/Test/Jackalope/Fixtures/REST/resource_ref.json create mode 100644 lib/Test/Jackalope/Fixtures/REST/service_crud.json diff --git a/lib/Test/Jackalope/Fixtures/Manager/REST.pm b/lib/Test/Jackalope/Fixtures/Manager/REST.pm new file mode 100644 index 0000000..8e24e07 --- /dev/null +++ b/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 Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2011 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/Test/Jackalope/Fixtures/REST/resource.json b/lib/Test/Jackalope/Fixtures/REST/resource.json new file mode 100644 index 0000000..7e7dc11 --- /dev/null +++ b/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" : [] + } + ] + } +] \ No newline at end of file diff --git a/lib/Test/Jackalope/Fixtures/REST/resource_ref.json b/lib/Test/Jackalope/Fixtures/REST/resource_ref.json new file mode 100644 index 0000000..50dd6ca --- /dev/null +++ b/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" } + ] + } +] \ No newline at end of file diff --git a/lib/Test/Jackalope/Fixtures/REST/service_crud.json b/lib/Test/Jackalope/Fixtures/REST/service_crud.json new file mode 100644 index 0000000..266e5a1 --- /dev/null +++ b/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 ] + ] + } +] \ No newline at end of file diff --git a/t/030-REST/010-schema-spec.t b/t/030-REST/010-schema-spec.t index 5b3d3fc..6ebfbdc 100644 --- a/t/030-REST/010-schema-spec.t +++ b/t/030-REST/010-schema-spec.t @@ -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'); @@ -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 ] ) {