Commit 8784b014 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '338151-add-validation-to-website-url' into 'master'

Validate user website_url

See merge request gitlab-org/gitlab!69436
parents b09be454 ad4dbad7
......@@ -253,6 +253,8 @@ class User < ApplicationRecord
validates :color_scheme_id, allow_nil: true, inclusion: { in: Gitlab::ColorSchemes.valid_ids,
message: _("%{placeholder} is not a valid color scheme") % { placeholder: '%{value}' } }
validates :website_url, allow_blank: true, url: true
before_validation :sanitize_attrs
before_validation :reset_secondary_emails, if: :email_changed?
before_save :default_private_profile_to_false
......
......@@ -32,7 +32,7 @@ RSpec.describe 'User edit profile' do
fill_in 'user_skype', with: 'testskype'
fill_in 'user_linkedin', with: 'testlinkedin'
fill_in 'user_twitter', with: 'testtwitter'
fill_in 'user_website_url', with: 'testurl'
fill_in 'user_website_url', with: 'http://testurl.com'
fill_in 'user_location', with: 'Ukraine'
fill_in 'user_bio', with: 'I <3 GitLab :tada:'
fill_in 'user_job_title', with: 'Frontend Engineer'
......@@ -43,7 +43,7 @@ RSpec.describe 'User edit profile' do
skype: 'testskype',
linkedin: 'testlinkedin',
twitter: 'testtwitter',
website_url: 'testurl',
website_url: 'http://testurl.com',
bio: 'I <3 GitLab :tada:',
bio_html: '<p data-sourcepos="1:1-1:18" dir="auto">I &lt;3 GitLab <gl-emoji title="party popper" data-name="tada" data-unicode-version="6.0">🎉</gl-emoji></p>',
job_title: 'Frontend Engineer',
......@@ -65,6 +65,17 @@ RSpec.describe 'User edit profile' do
end
end
it 'shows an error if the website url is not valid' do
fill_in 'user_website_url', with: 'admin@gitlab.com'
submit_settings
expect(user.reload).to have_attributes(
website_url: ''
)
expect(page).to have_content('Website url is not a valid URL')
end
describe 'when I change my email' do
before do
user.send_reset_password_instructions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment