aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-08-11 22:23:18 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-08-14 13:15:31 +0200
commit72423701b62174c29ff74874950ceeb78a19426c (patch)
tree3c8ce22e778cf61171a76ec7ef8fdcd9b00e7b4c
parentBugfix: spec for email answer was named improperly (and one test broke) (diff)
downloadrecruiting-webapp-72423701b62174c29ff74874950ceeb78a19426c.tar.gz
recruiting-webapp-72423701b62174c29ff74874950ceeb78a19426c.tar.bz2
recruiting-webapp-72423701b62174c29ff74874950ceeb78a19426c.zip
Improve EmailAnswer model coverage
-rw-r--r--spec/factories.rb3
-rw-r--r--spec/models/email_answer_spec.rb25
2 files changed, 28 insertions, 0 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index ac91eae..49c9093 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -113,3 +113,6 @@
Factory.define :question_content_multiple_choice do |q|
end
+
+ Factory.define :question_content_email do |q|
+ end
diff --git a/spec/models/email_answer_spec.rb b/spec/models/email_answer_spec.rb
index c066be8..d4ec177 100644
--- a/spec/models/email_answer_spec.rb
+++ b/spec/models/email_answer_spec.rb
@@ -21,4 +21,29 @@ describe EmailAnswer do
UserMailer.should_receive(:deliver_unrecognized_email).with(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