From b74249a05f564cf762df2b279473485f51d21949 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 8 Sep 2016 11:17:29 -0500 Subject: [PATCH] bug fix: candidate email encryption on empty email --- app/services/crypt_serializer.rb | 2 +- test/controllers/recruiter_controller_test.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/services/crypt_serializer.rb b/app/services/crypt_serializer.rb index 74a5ad9..07ff30e 100644 --- a/app/services/crypt_serializer.rb +++ b/app/services/crypt_serializer.rb @@ -26,7 +26,7 @@ class CryptSerializer raise "Attribute was supposed to be a `String`, but was instead a `#{value.class}`" end - return value if value.nil? + return nil if value.blank? cipher.encrypt parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final] diff --git a/test/controllers/recruiter_controller_test.rb b/test/controllers/recruiter_controller_test.rb index 1398f11..1f8828f 100644 --- a/test/controllers/recruiter_controller_test.rb +++ b/test/controllers/recruiter_controller_test.rb @@ -78,7 +78,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest assert flash[:success] end - test "should fail creation with message" do + test "should fail creation with improper email format" do setup_auth assert_difference("ActionMailer::Base.deliveries.size", 0) do @@ -91,4 +91,18 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest assert assigns(:candidate), "@candidate not present" assert_match(/failed.*save/i, flash[:error]) end + + test "should fail creation gracefully with empty email" do + setup_auth + + assert_difference("ActionMailer::Base.deliveries.size", 0) do + assert_difference("Candidate.count", 0) do + post create_candidate_path, params: { candidate: + { name: 'new name', email: "", experience: '0-3', quiz_id: quizzes(:fed).id } } + end + end + assert :success + assert assigns(:candidate), "@candidate not present" + assert_match(/failed.*save/i, flash[:error]) + end end