use strict;
use warnings;
use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
my $secret = FixMyStreet::App->model('DB::Secret')->search();
# don't explode if there's nothing in the secret table
if ( $secret == 0 ) {
diag "You need to put an entry in the secret table for the admin tests to run";
plan skip_all => 'No entry in secret table';
}
my $user =
FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'test@example.com', name => 'Test User' } );
ok $user, "created test user";
my $user2 =
FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'test2@example.com', name => 'Test User 2' } );
ok $user2, "created second test user";
my $user3 =
FixMyStreet::App->model('DB::User')
->find( { email => 'test3@example.com', name => 'Test User 2' } );
if ( $user3 ) {
$mech->delete_user( $user3 );
}
my $dt = DateTime->new(
year => 2011,
month => 04,
day => 16,
hour => 15,
minute => 47,
second => 23
);
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Report to Edit',
detail => 'Detail for Report to Edit',
used_map => 't',
name => 'Test User',
anonymous => 'f',
external_id => '13',
state => 'confirmed',
confirmed => $dt->ymd . ' ' . $dt->hms,
lang => 'en-gb',
service => '',
cobrand => '',
cobrand_data => '',
send_questionnaire => 't',
latitude => '51.5016605453401',
longitude => '-0.142497580865087',
user_id => $user->id,
whensent => $dt->ymd . ' ' . $dt->hms,
}
);
my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
{
alert_type => 'new_updates',
parameter => $report->id,
confirmed => 1,
user => $user,
},
);
subtest 'check summary counts' => sub {
my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed closed investigating planned/, 'in progress', 'fixed - user', 'fixed - council'] } } );
ok $mech->host('www.fixmystreet.com');
my $problem_count = $problems->count;
$problems->update( { cobrand => '' } );
FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 2489 } )->update( { bodies_str => 1 } );
my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, });
$q->whensent( \'current_timestamp' );
$q->in_storage ? $q->update : $q->insert;
my $alerts = FixMyStreet::App->model('DB::Alert')->search( { confirmed => { '>' => 0 } } );
my $a_count = $alerts->count;
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixmystreet' ],
}, sub {
$mech->get_ok('/admin');
};
$mech->title_like(qr/Summary/);
$mech->content_contains( "$problem_count live problems" );
$mech->content_contains( "$a_count confirmed alerts" );
my $questionnaires = FixMyStreet::App->model('DB::Questionnaire')->search( { whensent => { -not => undef } } );
my $q_count = $questionnaires->count();
$mech->content_contains( "$q_count questionnaires sent" );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'barnet' ],
}, sub {
ok $mech->host('barnet.fixmystreet.com');
$mech->get_ok('/admin');
$mech->title_like(qr/Summary/);
my ($num_live) = $mech->content =~ /(\d+)<\/strong> live problems/;
my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/;
my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/;
$report->bodies_str(2489);
$report->cobrand('barnet');
$report->update;
$alert->cobrand('barnet');
$alert->update;
$mech->get_ok('/admin');
$mech->content_contains( ($num_live+1) . " live problems" );
$mech->content_contains( ($num_alerts+1) . " confirmed alerts" );
$mech->content_contains( ($num_qs+1) . " questionnaires sent" );
$report->bodies_str(2504);
$report->cobrand('');
$report->update;
$alert->cobrand('');
$alert->update;
};
FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 1 } )->update( { bodies_str => 2489 } );
ok $mech->host('www.fixmystreet.com');
};
# This override is wrapped around ALL the /admin/body tests
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.mysociety.org/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
}, sub {
my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Aberdeen City Council');
$mech->content_like(qr{AB\d\d});
$mech->content_contains("http://www.example.org/around");
subtest 'check contact creation' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->search(
{ body_id => $body->id, category => [ 'test category', 'test/category' ] }
);
$contact->delete_all;
my $history = FixMyStreet::App->model('DB::ContactsHistory')->search(
{ body_id => $body->id, category => [ 'test category', 'test/category' ] }
);
$history->delete_all;
$mech->get_ok('/admin/body/' . $body->id);
$mech->submit_form_ok( { with_fields => {
category => 'test category',
email => 'test@example.com',
note => 'test note',
non_public => undef,
} } );
$mech->content_contains( 'test category' );
$mech->content_contains( 'test@example.com' );
$mech->content_contains( '
test note' );
$mech->content_contains( 'Private: No' );
$mech->submit_form_ok( { with_fields => {
category => 'private category',
email => 'test@example.com',
note => 'test note',
non_public => 'on',
} } );
$mech->content_contains( 'private category' );
$mech->content_contains( 'Private: Yes' );
$mech->submit_form_ok( { with_fields => {
category => 'test/category',
email => 'test@example.com',
note => 'test/note',
non_public => 'on',
} } );
$mech->get_ok('/admin/body/' . $body->id . '/test/category');
};
subtest 'check contact editing' => sub {
$mech->get_ok('/admin/body/' . $body->id .'/test%20category');
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => undef,
} } );
$mech->content_contains( 'test category' );
$mech->content_contains( 'test2@example.com' );
$mech->content_contains( ' | test2 note' );
$mech->content_contains( 'Private: No' );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => 'on',
} } );
$mech->content_contains( 'Private: Yes' );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_contains( ' | test2@example.com' );
};
subtest 'check contact updating' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com[^<]* | [^<]*No}s);
$mech->get_ok('/admin/body/' . $body->id);
$mech->form_number( 1 );
$mech->tick( 'confirmed', 'test category' );
$mech->submit_form_ok({form_number => 1});
$mech->content_like(qr'test2@example.com | [^<]*\s*Confirmed: Yes's);
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com[^<]* | [^<]*Yes}s);
};
$body->update({ send_method => undef });
subtest 'check open311 configuring' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_lacks('Council contacts configured via Open311');
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'api key',
endpoint => 'http://example.com/open311',
jurisdiction => 'mySociety',
send_comments => 0,
send_method => 'Open311',
}
}
);
$mech->content_contains('Council contacts configured via Open311');
$mech->content_contains('Values updated');
my $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
is $conf->endpoint, 'http://example.com/open311', 'endpoint configured';
is $conf->api_key, 'api key', 'api key configured';
is $conf->jurisdiction, 'mySociety', 'jurisdiction configures';
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'new api key',
endpoint => 'http://example.org/open311',
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
}
}
);
$mech->content_contains('Values updated');
$conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
};
subtest 'check text output' => sub {
$mech->get_ok('/admin/body/' . $body->id . '?text=1');
is $mech->content_type, 'text/plain';
$mech->content_contains('test category');
};
}; # END of override wrap
my $log_entries = FixMyStreet::App->model('DB::AdminLog')->search(
{
object_type => 'problem',
object_id => $report->id
},
{
order_by => { -desc => 'id' },
}
);
is $log_entries->count, 0, 'no admin log entries';
my $report_id = $report->id;
ok $report, "created test report - $report_id";
foreach my $test (
{
description => 'edit report title',
fields => {
title => 'Report to Edit',
detail => 'Detail for Report to Edit',
state => 'confirmed',
name => 'Test User',
email => $user->email,
anonymous => 0,
flagged => undef,
non_public => undef,
},
changes => { title => 'Edited Report', },
log_count => 1,
log_entries => [qw/edit/],
resend => 0,
},
{
description => 'edit report description',
fields => {
title => 'Edited Report',
detail => 'Detail for Report to Edit',
state => 'confirmed',
name => 'Test User',
email => $user->email,
anonymous => 0,
flagged => undef,
non_public => undef,
},
changes => { detail => 'Edited Detail', },
log_count => 2,
log_entries => [qw/edit edit/],
resend => 0,
},
{
description => 'edit report user name',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Test User',
email => $user->email,
anonymous => 0,
flagged => undef,
non_public => undef,
},
changes => { name => 'Edited User', },
log_count => 3,
log_entries => [qw/edit edit edit/],
resend => 0,
user => $user,
},
{
description => 'edit report set flagged true',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Edited User',
email => $user->email,
anonymous => 0,
flagged => undef,
non_public => undef,
},
changes => {
flagged => 'on',
},
log_count => 4,
log_entries => [qw/edit edit edit edit/],
resend => 0,
user => $user,
},
{
description => 'edit report user email',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Edited User',
email => $user->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => { email => $user2->email, },
log_count => 5,
log_entries => [qw/edit edit edit edit edit/],
resend => 0,
user => $user2,
},
{
description => 'change state to unconfirmed',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Edited User',
email => $user2->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => { state => 'unconfirmed' },
log_count => 6,
log_entries => [qw/state_change edit edit edit edit edit/],
resend => 0,
},
{
description => 'change state to confirmed',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'unconfirmed',
name => 'Edited User',
email => $user2->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => { state => 'confirmed' },
log_count => 7,
log_entries => [qw/state_change state_change edit edit edit edit edit/],
resend => 0,
},
{
description => 'change state to fixed',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Edited User',
email => $user2->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => { state => 'fixed' },
log_count => 8,
log_entries =>
[qw/state_change state_change state_change edit edit edit edit edit/],
resend => 0,
},
{
description => 'change state to hidden',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'fixed',
name => 'Edited User',
email => $user2->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => { state => 'hidden' },
log_count => 9,
log_entries => [
qw/state_change state_change state_change state_change edit edit edit edit edit/
],
resend => 0,
},
{
description => 'edit and change state',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'hidden',
name => 'Edited User',
email => $user2->email,
anonymous => 0,
flagged => 'on',
non_public => undef,
},
changes => {
state => 'confirmed',
anonymous => 1,
},
log_count => 11,
log_entries => [
qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/
],
resend => 0,
},
{
description => 'resend',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => 'confirmed',
name => 'Edited User',
email => $user2->email,
anonymous => 1,
flagged => 'on',
non_public => undef,
},
changes => {},
log_count => 12,
log_entries => [
qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/
],
resend => 1,
},
{
description => 'non public',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
state => '= Spec::Rails
* http://rspec.info
* http://rubyforge.org/projects/rspec
* http://github.com/dchelimsky/rspec-rails
* http://wiki.github.com/dchelimsky/rspec/rails
* mailto:rspec-devel@rubyforge.org
== DESCRIPTION:
Behaviour Driven Development for Ruby on Rails.
rspec-rails is an RSpec extension that allows you to drive the development of
Ruby on Rails applications with RSpec.
This is the repository for rspec-rails-1.x. If you're looking
for rspec-rails-2 for rails-3, see http://github.com/rspec/rspec-rails.
== FEATURES:
* Use RSpec to independently specify Rails Models, Views, Controllers and Helpers
* Integrated fixture loading
* Special generators for Resources, Models, Views and Controllers that generate RSpec code examples.
== VISION:
For people for whom TDD is a brand new concept, the testing support built into
Ruby on Rails is a huge leap forward. The fact that it is built right in is
fantastic, and Ruby on Rails apps are generally much easier to maintain than
they might have been without such support.
For those of us coming from a history with TDD, and now BDD, the existing
support presents some problems related to dependencies across examples. To
that end, RSpec on Rails supports 4 types of examples. We’ve also built in
first class mocking and stubbing support in order to break dependencies across
these different concerns.
== MORE INFORMATION:
See Spec::Rails::Example for information about the different kinds of example
groups you can use to spec the different Rails components
See Spec::Rails::Matchers for information about Rails-specific
expectations you can set on responses and models, etc.
== INSTALL
* Visit http://wiki.github.com/dchelimsky/rspec/rails for installation instructions.
|