aboutsummaryrefslogtreecommitdiff
blob: 3e7096f8341792a7a39732abc18de737d754aa3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper.rb'
describe EmailAnswer do
  it "should send email notification when parses answer for unrecognized question from known user" do
    recruit       = Factory(:recruit)
    question      = Factory(:question)
    mail          = TMail::Mail.new
    mail.subject  = "#{question.id + 1}-#{recruit.token}"
    mail.from     = recruit.email_address

    UserMailer.should_receive_delayed(:deliver_unrecognized_email, recruit, mail)
    EmailAnswer.answer_from_email(mail)
  end

  it "should send email notification when parses answer for non-email question from known user" do
    recruit       = Factory(:recruit)
    question      = Factory(:question)
    mail          = TMail::Mail.new
    mail.subject  = "#{question.id}-#{recruit.token}"
    mail.from     = recruit.email_address

    UserMailer.should_receive_delayed(:deliver_unrecognized_email, recruit, mail)
    EmailAnswer.answer_from_email(mail)
  end

  it "should properly recognize invalid answer" do
    recruit       = Factory(:recruit)
    question      = Factory(:question)
                    Factory(:question_content_email, :question => question, :req_text => "To : test@example.com")
    mail          = TMail::Mail.new
    mail.subject  = "#{question.id}-#{recruit.token}"
    mail.from     = recruit.email_address

    EmailAnswer.answer_from_email(mail)
    Answer.last.correct.should be_false
  end

  it "should properly recognize valid answer" do
    recruit       = Factory(:recruit)
    question      = Factory(:question)
                    Factory(:question_content_email, :question => question, :req_text => "To : test@example.com")
    mail          = TMail::Mail.new
    mail.subject  = "#{question.id}-#{recruit.token}"
    mail.from     = recruit.email_address
    mail.to       = "test@example.com"

    EmailAnswer.answer_from_email(mail)
    Answer.last.correct.should be_true
  end
end