bug fix: candidate email encryption on empty email

This commit is contained in:
Mark Moser 2016-09-08 11:17:29 -05:00
parent 9f23a5d3ce
commit b74249a05f
2 changed files with 16 additions and 2 deletions

View File

@ -26,7 +26,7 @@ class CryptSerializer
raise "Attribute was supposed to be a `String`, but was instead a `#{value.class}`" raise "Attribute was supposed to be a `String`, but was instead a `#{value.class}`"
end end
return value if value.nil? return nil if value.blank?
cipher.encrypt cipher.encrypt
parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final] parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final]

View File

@ -78,7 +78,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
assert flash[:success] assert flash[:success]
end end
test "should fail creation with message" do test "should fail creation with improper email format" do
setup_auth setup_auth
assert_difference("ActionMailer::Base.deliveries.size", 0) do assert_difference("ActionMailer::Base.deliveries.size", 0) do
@ -91,4 +91,18 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
assert assigns(:candidate), "@candidate not present" assert assigns(:candidate), "@candidate not present"
assert_match(/failed.*save/i, flash[:error]) assert_match(/failed.*save/i, flash[:error])
end 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 end