Commit 310c2af688612dbf1391c653c5d488a03c9cfa25
1 parent
a03d6811
Exists in
master
and in
1 other branch
Adding rake task to check api consistency
Showing
5 changed files
with
85 additions
and
0 deletions
Show diff stats
... | ... | @@ -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 | ... | ... |
... | ... | @@ -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 | + | ... | ... |