mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 22:26:29 +08:00
6ecf37c482
Parsing a URL with `URI` is not sufficient as the following cases are considered valid: URI.parse("http://https://google.com") => #<URI::HTTP http://https//google.com>
34 lines
928 B
Ruby
34 lines
928 B
Ruby
require 'rails_helper'
|
|
require 'validators/topic_title_length_validator'
|
|
|
|
RSpec.describe UrlValidator do
|
|
let(:record) { Fabricate.build(:user_profile, user: Fabricate.build(:user)) }
|
|
let(:validator) { described_class.new(attributes: :website) }
|
|
subject(:validate) { validator.validate_each(record, :website, record.website) }
|
|
|
|
[
|
|
"http://https://google.com",
|
|
"http://google/",
|
|
"ftp://ftp.google.com",
|
|
"http:///what.is.this",
|
|
'http://meta.discourse.org TEST'
|
|
].each do |invalid_url|
|
|
it "#{invalid_url} should not be valid" do
|
|
record.website = invalid_url
|
|
validate
|
|
expect(record.errors[:website]).to be_present
|
|
end
|
|
end
|
|
|
|
[
|
|
"http://discourse.productions",
|
|
"https://google.com",
|
|
].each do |valid_url|
|
|
it "#{valid_url} should be valid" do
|
|
record.website = valid_url
|
|
validate
|
|
expect(record.errors[:website]).to_not be_present
|
|
end
|
|
end
|
|
end
|