From bd286c6b5a5e113f6e10af2e44269f7dac774bfb Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Sun, 29 Mar 2015 16:04:23 +0100 Subject: [PATCH] Add sanity checker script --- scripts/sanity.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/sanity.rb diff --git a/scripts/sanity.rb b/scripts/sanity.rb new file mode 100644 index 0000000..75f6ffa --- /dev/null +++ b/scripts/sanity.rb @@ -0,0 +1,29 @@ +require_relative "../models" + +# We should be checking polls.seats not districts.seats +@res = repository(:default).adapter.select(" + SELECT c.election_id, + c.district_id, + c.party_id, + COUNT(c.*) AS qty_candidacies + + FROM candidacies c, + districts d + + WHERE c.district_id = d.id + + GROUP BY c.election_id, + c.district_id, + c.party_id, + d.seats + + HAVING COUNT(c.*) > d.seats +") + +if @res.size > 0 + puts "ERROR: %d districts have too many candidates standing for one party" % @res.size + exit 1 +else + puts "OK: All districts have no more candidates standing per party than there are seats." + exit 0 +end