Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created September 24, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/f675a1725422c9fb4bd01c919ce12b19 to your computer and use it in GitHub Desktop.
Save j1n3l0/f675a1725422c9fb4bd01c919ce12b19 to your computer and use it in GitHub Desktop.
use 5.026;
use DBIx::RunSQL;
use DBIx::Class::Schema::Loader 'make_schema_at';
BEGIN {
my $sql = <<'SQL';
BEGIN;
CREATE TABLE request (
id INTEGER NOT NULL,
email TEXT NOT NULL,
created TEXT NOT NULL
);
COMMIT;
SQL
my $test_dbh = DBIx::RunSQL->create(
dsn => 'dbi:SQLite:dbname=:memory:',
sql => \$sql,
force => 1,
# verbose => 1,
);
make_schema_at( 'MyApp::Schema',
{
components => [ 'InflateColumn::DateTime', 'TimeStamp' ],
# debug => 1,
dump_directory => './lib' ,
},
[ sub { $test_dbh }, { unsafe => 1 } ]
);
}
use JSONAPI::Document;
use Test::DBIx::Class { schema_class => 'MyApp::Schema' };
use Test::Most;
my $jsonapi = new_ok 'JSONAPI::Document', [ api_url => 'http://example.com/api' ];
my $schema = Schema;
$schema->resultset('Request')->create(
{
id => 1,
email => 'me@home.com',
created => 'now',
},
);
cmp_deeply(
$jsonapi->resource_documents( $schema->resultset('Request') ),
{
data => [
{
attributes => ignore,
id => 1,
type => 'requests',
},
],
},
'data is as expected',
);
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment