Commit 310c2af688612dbf1391c653c5d488a03c9cfa25

Authored by Dhruv Kapadia
1 parent a03d6811

Adding rake task to check api consistency

app/models/cron_mailer.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class CronMailer < ActionMailer::Base
  2 +
  3 + def error_message(subject, message, sent_at= Time.now)
  4 + @from = 'cronjob@allourideas.org'
  5 + @recipients = "dhruv@dkapadia.com"
  6 + @subject ="[All Our Ideas] " + subject
  7 + @sent_on = sent_at
  8 + @body[:message] = message
  9 + @body[:host] = "www.allourideas.org"
  10 + end
  11 +
  12 +
  13 +
  14 +
  15 +end
... ...
app/views/cron_mailer/error_message.erb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +Hi,
  2 +
  3 +A cron job has sent an error message. Find the hopefully relevant message below:
  4 +
  5 +<%= @message %>
  6 +
  7 +Thanks,
  8 +All Our Ideas
  9 +145 Wallace Hall
  10 +Princeton, NJ 08544
  11 +info@allourideas.org
... ...
app/views/cron_mailer/error_message.haml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +Hi,
  2 +
  3 += "A cron job has sent an error message. Find the hopefully relevant message below:\n"
  4 +
  5 += @message`
  6 +
  7 +Thanks,
  8 +All Our Ideas
  9 +145 Wallace Hall
  10 +Princeton, NJ 08544
  11 +info@allourideas.org
... ...
lib/tasks/test_api.rake 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +namespace :test_api do
  2 +
  3 + desc "Description here"
  4 + task(:question_vote_consistency => :environment) do
  5 + questions = Question.find(:all)
  6 +
  7 + error_msg = ""
  8 + questions.each do |question|
  9 +
  10 + total_wins =0
  11 + total_votes =0
  12 + question.choices.each do |choice|
  13 +
  14 + if choice.wins
  15 + total_wins += choice.wins
  16 + total_votes += choice.wins
  17 + end
  18 +
  19 + if choice.losses
  20 + total_votes += choice.losses
  21 + end
  22 + end
  23 +
  24 +
  25 + if (2*total_wins != total_votes)
  26 + error_msg += "Error:"
  27 + end
  28 +
  29 + if(total_votes % 2 != 0)
  30 + error_msg += "ERROR"
  31 + end
  32 +
  33 + error_msg += "Question #{question.id}: 2*wins = #{2*total_wins}, total votes = #{total_votes}\n"
  34 + end
  35 +
  36 + CronMailer.deliver_error_message("This is a test", "")
  37 +
  38 + end
  39 +end
  40 +
... ...
test/unit/cron_mailer_test.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +require 'test_helper'
  2 +
  3 +class CronMailerTest < ActionMailer::TestCase
  4 + # replace this with your real tests
  5 + test "the truth" do
  6 + assert true
  7 + end
  8 +end
... ...