| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | |
|---|
| 4 | use HTTP::Request::Common; |
|---|
| 5 | use Test::More 'no_plan'; |
|---|
| 6 | |
|---|
| 7 | BEGIN { $ENV{CATALYST_DEBUG} = 0; } |
|---|
| 8 | BEGIN { $ENV{VEEKUN_USE_TEMP_DB} = 1; } |
|---|
| 9 | BEGIN { use_ok 'Catalyst::Test', 'Vee' } |
|---|
| 10 | BEGIN { use_ok 'Vee::Controller::Shoutbox' } |
|---|
| 11 | |
|---|
| 12 | # TODO put this stuff in Veekun::Test somewhere, create_fake_user |
|---|
| 13 | # FIXME I can't seem to get this to create a cookie and stay cookied! |
|---|
| 14 | #my $password = random_string( '.' x (6 + int rand 6) ); |
|---|
| 15 | #my $user = Vee->model('DBIC::Users')->create( { |
|---|
| 16 | # name => 'testuser', |
|---|
| 17 | # password => sha1_hex($password), |
|---|
| 18 | #} ); |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | my $posted_res = request( POST '/shoutbox/post' => { |
|---|
| 22 | name => 'Tester', |
|---|
| 23 | content => 'Test message', |
|---|
| 24 | } ); |
|---|
| 25 | ok $posted_res->is_redirect, 'Shoutbox post results in redirect'; |
|---|
| 26 | |
|---|
| 27 | my $shout = Vee->model('DBIC::Shoutbox')->search( undef, { |
|---|
| 28 | order_by => 'id DESC', |
|---|
| 29 | } )->first; |
|---|
| 30 | |
|---|
| 31 | ok defined $shout, 'Shoutbox table contains a shout'; |
|---|
| 32 | is $shout->name, 'Tester', 'Shout name is correct'; |
|---|
| 33 | is $shout->content, 'Test message', 'Shout message is correct'; |
|---|
| 34 | ok !defined $shout->user_id, 'Shout user is NULL'; |
|---|
| 35 | ok abs($shout->time - time) < 3, 'Shout time is reasonably close to now'; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | my $shoutbox = request('/shoutbox'); |
|---|
| 40 | ok $shoutbox->is_success, 'Shoutbox history request'; |
|---|