plan
skip_all
=>
'set TEST_ONLINE to enable this test'
unless
$ENV
{TEST_ONLINE};
r->
connect
->repl;
r->db(
'test'
)->drop->run;
r->db(
'test'
)->create->run;
r->db(
'test'
)->table(
'marvel'
)->create(
primary_key
=>
'superhero'
)->run;
r->db(
'test'
)->table(
'marvel'
)->index_create(
'superpower'
)->run;
r->db(
'test'
)->table(
'marvel'
)->index_create(
'user_id'
)->run;
r->table(
'marvel'
)->insert(
[
{
user_id
=> 1,
superhero
=>
'Iron Man'
,
superpower
=>
'Arc Reactor'
,
active
=> 1,
age
=> 35
},
{
user_id
=> 8,
superhero
=>
'Wolverine'
,
superpower
=>
'Adamantium'
,
active
=> 0,
age
=> 35
},
{
user_id
=> 9,
superhero
=>
'Spider-Man'
,
superpower
=>
'Spidy Sense'
,
active
=> 0,
age
=> 20
}
]
)->run;
my
$res
= r->db(
'test'
)->table(
'marvel'
)->run;
my
$res2
= r->table(
'marvel'
)->run;
$res2
->token(
$res
->token );
is_deeply
$res
,
$res2
;
r->table(
'marvel'
)->insert(
[
{
user_id
=> 2,
superhero
=>
'Hulk'
,
superpower
=>
'Smash'
,
active
=> 1,
age
=> 35
},
{
user_id
=> 3,
superhero
=>
'Captain America'
,
superpower
=>
'Super Strength'
,
active
=> 1,
age
=> 135
},
{
user_id
=> 4,
superhero
=>
'Thor'
,
superpower
=>
'God-like powers'
,
active
=> 1,
age
=> 1035
},
{
user_id
=> 5,
superhero
=>
'Hawk-Eye'
,
superpower
=>
'Bow-n-arrow'
,
active
=> 0,
age
=> 35
},
{
user_id
=> 6,
superhero
=>
'Wasp'
,
superpower
=>
'Bio-lasers'
,
active
=> 0,
age
=> 35
},
{
user_id
=> 7,
superhero
=>
'Ant-Man'
,
superpower
=>
'Size'
,
active
=> 1,
age
=> 35
},
]
)->run;
$res
= r->db(
'test'
)->table(
'marvel'
, 1 )->run;
$res2
= r->db(
'test'
)->table(
'marvel'
, r->true )->run;
$res2
->token(
$res
->token );
is_deeply
$res
,
$res2
;
$res
= r->table(
'marvel'
)->get(
'Spider-Man'
)->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 1,
'Correct status code'
;
is
$res
->response->{superhero},
'Spider-Man'
,
'Correct response'
;
r->table(
'marvel'
)->index_wait(
'superpower'
)->run;
r->table(
'marvel'
)->index_wait(
'user_id'
)->run;
$res
= r->table(
'marvel'
)->get_all(
'Size'
,
'Smash'
, {
index
=>
'superpower'
} )
->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response'
;
is
scalar
@{
$res
->response }, 2,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)->between( 2, 7 )->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 18,
'Correct status code'
;
is
$res
->response->[0],
'Index `id` was not found on table `test.marvel`.'
;
$res
= r->table(
'marvel'
)->between( 2, 7,
'user_id'
)->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 5,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)->between( r->minval, 7,
'user_id'
)->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 6,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)->between( 2, r->maxval,
'user_id'
)->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 8,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)->between( 2, 7,
'user_id'
,
'open'
,
'closed'
)->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 5,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)
->between( 2, 7,
{
index
=>
'user_id'
,
left_bound
=>
'open'
,
right_bound
=>
'closed'
} )->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 5,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)->filter( {
active
=> 1 } )->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 5,
'Correct number of documents returned'
;
$res
= r->table(
'marvel'
)
->filter( {
active
=> 1,
age
=> 35,
superpower
=>
'Size'
} )->run;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct class'
;
is
$res
->type, 2,
'Correct status code'
;
isa_ok
$res
->response,
'ARRAY'
,
'Correct response type'
;
is
scalar
@{
$res
->response }, 1,
'Correct number of documents returned'
;
is
$res
->response->[0]->{superhero},
'Ant-Man'
,
'Correct document returned'
;
$res
= r->table(
'marvel'
)->filter( r->row->bracket(
'age'
)->gt(100) )->run;
is
$res
->type, 2,
'Correct status code'
;
is_deeply [
sort
{
$a
->{user_id} cmp
$b
->{user_id} } @{
$res
->response } ],
[
{
active
=>
'1'
,
superhero
=>
'Captain America'
,
user_id
=>
'3'
,
age
=>
'135'
,
superpower
=>
'Super Strength'
},
{
active
=>
'1'
,
superhero
=>
'Thor'
,
user_id
=>
'4'
,
age
=>
'1035'
,
superpower
=>
'God-like powers'
}
],
'Correct response type'
;
$res
= r->table(
'marvel'
)->filter(
sub
{
my
$hero
=
shift
;
return
$hero
->bracket(
'age'
)->gt(100);
}
)->order_by(
'user_id'
)->run;
is
$res
->type, 1,
'Correct status code'
;
is_deeply
$res
->response,
[
{
active
=>
'1'
,
superhero
=>
'Captain America'
,
user_id
=>
'3'
,
age
=>
'135'
,
superpower
=>
'Super Strength'
},
{
active
=>
'1'
,
superhero
=>
'Thor'
,
user_id
=>
'4'
,
age
=>
'1035'
,
superpower
=>
'God-like powers'
}
],
'Correct response type'
;
r->db(
'test'
)->drop->run;
done_testing();