* Updating valid domain registration Prior to this commit, our regular expression did not account for the `-` character as valid within the domain. The `-` character cannot be the first nor last character of the domain (e.g. `-hello.com` nor `hello-.com` are invalid but `hell-o.com` is valid). In addition I tidied up the default value of the `blocked_registration_email_domains` to match it's sibling `allowed_registration_email_domains`. This relates to the spammer seo-hunt.com * Adding validator domain validator spec * Moving request spec to unit spec This change does two things: 1) Allows for 2 character domains 2) Moves the spec for 2 character domains from an expensive spec to a cheaper to run spec (e.g., request-cycle to unit-test validator) It preserves PR #12268
41 lines
994 B
Ruby
41 lines
994 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe ValidDomainCsvValidator do
|
|
let(:validatable) do
|
|
Class.new do
|
|
def self.name
|
|
"Validatable"
|
|
end
|
|
include ActiveModel::Validations
|
|
attr_accessor :domains
|
|
|
|
validates :domains, valid_domain_csv: true
|
|
end
|
|
end
|
|
let(:model) { validatable.new }
|
|
|
|
it "marks valid a domain with dashes in the middle" do
|
|
model.domains = ["seo-hunt.com"]
|
|
expect(model).to be_valid
|
|
end
|
|
|
|
it "marks valid a two character domain" do
|
|
model.domains = ["2u.com"]
|
|
expect(model).to be_valid
|
|
end
|
|
|
|
it "marks invalid a domain with a dash as a prefix" do
|
|
model.domains = ["-seo-hunt.com"]
|
|
expect(model).to be_invalid
|
|
end
|
|
|
|
it "marks valid an array of domains" do
|
|
model.domains = ["hello.com", "world.org"]
|
|
expect(model).to be_valid
|
|
end
|
|
|
|
it "marks invalid an array of domains if one is invalid" do
|
|
model.domains = ["hello.com", "world.org", "notadomain"]
|
|
expect(model).to be_invalid
|
|
end
|
|
end
|