Permalink
Browse files

set interest_count default to 0 as null + 1 = null in postgres :(

tests for the ui for interest_count as well
  • Loading branch information...
1 parent 2b0fc37 commit de3ec1fbef726e3794096d99cb1f3ca7066a5768 @struan struan committed Oct 9, 2012
Showing with 149 additions and 1 deletion.
  1. +1 −1 db/schema.sql
  2. +9 −0 db/schema_0026-change_interest_count_default.sql
  3. +139 −0 t/app/controller/report_interest_count.t
View
2 db/schema.sql
@@ -217,7 +217,7 @@ create table problem (
external_source_id text,
-- number of me toos
- interest_count integer
+ interest_count integer default 0
);
create index problem_state_latitude_longitude_idx on problem(state, latitude, longitude);
create index problem_user_id_idx on problem ( user_id );
View
9 db/schema_0026-change_interest_count_default.sql
@@ -0,0 +1,9 @@
+BEGIN;
+
+ ALTER TABLE problem
+ ALTER COLUMN interest_count SET DEFAULT 0;
+
+ UPDATE problem SET interest_count = 0
+ WHERE interest_count IS NULL;
+
+COMMIT;
View
139 t/app/controller/report_interest_count.t
@@ -0,0 +1,139 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+use Web::Scraper;
+use Path::Class;
+use DateTime;
+
+my $mech = FixMyStreet::TestMech->new;
+
+# create a test user and report
+$mech->delete_user('test@example.com');
+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 => 'Other User' } );
+ok $user2, "created test user";
+
+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',
+ council => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Test 2',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ }
+);
+my $report_id = $report->id;
+ok $report, "created test report - $report_id";
+
+for my $test (
+ {
+ desc => 'if not from council then no supporter button',
+ from_council => 0,
+ support_string => 'No supporters',
+ },
+ {
+ desc => 'from council user can increment supported count',
+ from_council => 2504,
+ support_string => 'No supporters',
+ updated_support => '1 supporter'
+ },
+ {
+ desc => 'correct grammar for more than one supporter',
+ from_council => 2504,
+ support_string => '1 supporter',
+ updated_support => '2 supporters'
+ },
+) {
+ subtest $test->{desc} => sub {
+ ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
+ $mech->log_in_ok( $user->email );
+ $user->from_council( $test->{from_council} );
+ $user->update;
+
+ $report->discard_changes;
+ $report->council( $test->{report_council} );
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains( $test->{support_string} );
+
+ if ( $test->{from_council} ) {
+ $mech->content_contains('Add support');
+ $mech->submit_form_ok( { form_number => 1 } );
+
+ is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+
+ $mech->content_contains($test->{updated_support});
+ } else {
+ $mech->content_lacks( 'Add support' );
+ }
+ };
+}
+
+subtest 'check non council user cannot increment support count' => sub {
+ ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
+ $report->discard_changes;
+ $report->interest_count(1);
+ ok $report->update(), 'updated interest count';
+
+ $report->discard_changes;
+ is $report->interest_count, 1, 'correct interest count';
+
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains( '1 supporter' );
+
+ $mech->post_ok("/report/support", { id => $report_id } );
+
+ is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+
+ $mech->content_contains( '1 supporter' );
+};
+
+subtest 'check support details not shown if not enabled in cobrand' => sub {
+ ok $mech->host('fixmystreet.com'), 'changed to fixmystreet';
+
+ $report->interest_count(1);
+ ok $report->update, 'updated interest count';
+
+ $mech->get_ok("/report/$report_id");
+ $mech->content_lacks( '1 supporter' );
+};
+
+$report->discard_changes;
+$report->council( 2504 );
+$report->update;
+
+# tidy up
+$mech->delete_user('test@example.com');
+done_testing();

0 comments on commit de3ec1f

Please sign in to comment.