FIX: validate user website
This commit is contained in:
parent
ea0e63b150
commit
8a7868be07
|
@ -2,6 +2,7 @@ class UserProfile < ActiveRecord::Base
|
||||||
belongs_to :user, inverse_of: :user_profile
|
belongs_to :user, inverse_of: :user_profile
|
||||||
|
|
||||||
validates :bio_raw, length: { maximum: 3000 }
|
validates :bio_raw, length: { maximum: 3000 }
|
||||||
|
validates :website, format: { with: /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,9}(([0-9]{1,5})?\/.*)?$)/ix }, allow_blank: true
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
before_save :cook
|
before_save :cook
|
||||||
after_save :trigger_badges
|
after_save :trigger_badges
|
||||||
|
|
|
@ -104,6 +104,7 @@ class UserUpdater
|
||||||
attr_reader :user, :guardian
|
attr_reader :user, :guardian
|
||||||
|
|
||||||
def format_url(website)
|
def format_url(website)
|
||||||
|
return nil if website.blank?
|
||||||
website =~ /^http/ ? website : "http://#{website}"
|
website =~ /^http/ ? website : "http://#{website}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,6 +37,18 @@ describe UserProfile do
|
||||||
expect(user_profile).not_to be_valid
|
expect(user_profile).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't support invalid website" do
|
||||||
|
user_profile = Fabricate.build(:user_profile, website: "http://https://google.com")
|
||||||
|
user_profile.user = Fabricate.build(:user)
|
||||||
|
expect(user_profile).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports valid website" do
|
||||||
|
user_profile = Fabricate.build(:user_profile, website: "https://google.com")
|
||||||
|
user_profile.user = Fabricate.build(:user)
|
||||||
|
expect(user_profile.valid?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
describe 'after save' do
|
describe 'after save' do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue