Merge pull request #650 from AyuntamientoMadrid/verification-code
Check letter verification codes as integers
This commit is contained in:
@@ -28,7 +28,7 @@ class Verification::Letter
|
|||||||
|
|
||||||
def validate_correct_code
|
def validate_correct_code
|
||||||
return if errors.include?(:verification_code)
|
return if errors.include?(:verification_code)
|
||||||
if user.try(:letter_verification_code) != verification_code
|
if user.try(:letter_verification_code).to_i != verification_code.to_i
|
||||||
errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code'))
|
errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -68,6 +68,23 @@ feature 'Verify Letter' do
|
|||||||
expect(current_path).to eq(account_path)
|
expect(current_path).to eq(account_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Valid verification of user failing to add trailing zeros" do
|
||||||
|
user = create(:user, residence_verified_at: Time.now,
|
||||||
|
confirmed_phone: "611111111",
|
||||||
|
letter_verification_code: "012345")
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit edit_letter_path
|
||||||
|
|
||||||
|
fill_in "verification_letter_email", with: user.email
|
||||||
|
fill_in "verification_letter_password", with: user.password
|
||||||
|
fill_in "verification_letter_verification_code", with: "12345"
|
||||||
|
click_button "Verify my account"
|
||||||
|
|
||||||
|
expect(page).to have_content "Your account has been verified"
|
||||||
|
expect(current_path).to eq(account_path)
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Valid verification user not logged in" do
|
scenario "Valid verification user not logged in" do
|
||||||
user = create(:user, residence_verified_at: Time.now,
|
user = create(:user, residence_verified_at: Time.now,
|
||||||
confirmed_phone: "611111111",
|
confirmed_phone: "611111111",
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ describe 'Verification::Letter' do
|
|||||||
expect(letter.valid?).to eq(true)
|
expect(letter.valid?).to eq(true)
|
||||||
expect(letter.errors).to be_empty
|
expect(letter.errors).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ignores trailing zeros" do
|
||||||
|
letter.user.update(letter_verification_code: "003456")
|
||||||
|
letter.verification_code = "3456"
|
||||||
|
|
||||||
|
expect(letter.valid?).to eq(true)
|
||||||
|
expect(letter.errors).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user