Remove profile validations from user (#10257)
* Remove profile validations from user * Update specs
This commit is contained in:
parent
aa40d5ffdb
commit
099e416d35
2 changed files with 0 additions and 271 deletions
|
|
@ -36,27 +36,12 @@ class User < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
BEHANCE_URL_REGEXP = %r{\A(http(s)?://)?(www.behance.net|behance.net)/.*\z}.freeze
|
||||
COLOR_HEX_REGEXP = /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/.freeze
|
||||
DRIBBBLE_URL_REGEXP = %r{\A(http(s)?://)?(www.dribbble.com|dribbble.com)/.*\z}.freeze
|
||||
EDITORS = %w[v1 v2].freeze
|
||||
FACEBOOK_URL_REGEXP = %r{\A(http(s)?://)?(www.facebook.com|facebook.com)/.*\z}.freeze
|
||||
FONTS = %w[serif sans_serif monospace comic_sans open_dyslexic].freeze
|
||||
GITLAB_URL_REGEXP = %r{\A(http(s)?://)?(www.gitlab.com|gitlab.com)/.*\z}.freeze
|
||||
INBOXES = %w[open private].freeze
|
||||
INSTAGRAM_URL_REGEXP =
|
||||
%r{\A(http(s)?://)?(?:www.)?instagram.com/(?=.{1,30}/?$)([a-zA-Z\d_]\.?)*[a-zA-Z\d_]+/?\z}.freeze
|
||||
|
||||
LINKEDIN_URL_REGEXP = %r{\A(http(s)?://)?(www.linkedin.com|linkedin.com|[A-Za-z]{2}.linkedin.com)/.*\z}.freeze
|
||||
MEDIUM_URL_REGEXP = %r{\A(http(s)?://)?(www.medium.com|medium.com)/.*\z}.freeze
|
||||
NAVBARS = %w[default static].freeze
|
||||
STACKOVERFLOW_URL_REGEXP =
|
||||
%r{\A(http(s)?://)?(((www|pt|ru|es|ja).)?stackoverflow.com|(www.)?stackexchange.com)/.*\z}.freeze
|
||||
|
||||
YOUTUBE_URL_REGEXP = %r{\A(http(s)?://)?(www.youtube.com|youtube.com)/.*\z}.freeze
|
||||
STREAMING_PLATFORMS = %w[twitch].freeze
|
||||
THEMES = %w[default night_theme pink_theme minimal_light_theme ten_x_hacker_theme].freeze
|
||||
TWITCH_URL_REGEXP = %r{\A(http(s)?://)?(www.twitch.tv|twitch.tv)/.*\z}.freeze
|
||||
USERNAME_MAX_LENGTH = 30
|
||||
USERNAME_REGEXP = /\A[a-zA-Z0-9_]+\z/.freeze
|
||||
MESSAGES = {
|
||||
|
|
@ -154,42 +139,23 @@ class User < ApplicationRecord
|
|||
devise :invitable, :omniauthable, :registerable, :database_authenticatable, :confirmable, :rememberable,
|
||||
:recoverable, :lockable
|
||||
|
||||
validates :behance_url, length: { maximum: 100 }, allow_blank: true, format: BEHANCE_URL_REGEXP
|
||||
validates :bg_color_hex, format: COLOR_HEX_REGEXP, allow_blank: true
|
||||
validates :config_font, inclusion: { in: FONTS + ["default".freeze], message: MESSAGES[:invalid_config_font] }
|
||||
validates :config_navbar, inclusion: { in: NAVBARS, message: MESSAGES[:invalid_config_navbar] }
|
||||
validates :config_theme, inclusion: { in: THEMES, message: MESSAGES[:invalid_config_theme] }
|
||||
validates :currently_streaming_on, inclusion: { in: STREAMING_PLATFORMS }, allow_nil: true
|
||||
validates :dribbble_url, length: { maximum: 100 }, allow_blank: true, format: DRIBBBLE_URL_REGEXP
|
||||
validates :editor_version, inclusion: { in: EDITORS, message: MESSAGES[:invalid_editor_version] }
|
||||
validates :email, length: { maximum: 50 }, email: true, allow_nil: true
|
||||
validates :email, uniqueness: { allow_nil: true, case_sensitive: false }, if: :email_changed?
|
||||
validates :employer_name, :employer_url, length: { maximum: 100 }
|
||||
validates :employment_title, :education, :location, length: { maximum: 100 }
|
||||
validates :experience_level, numericality: { less_than_or_equal_to: 10 }, allow_blank: true
|
||||
validates :facebook_url, length: { maximum: 1000 }, format: FACEBOOK_URL_REGEXP, allow_blank: true
|
||||
validates :feed_referential_link, inclusion: { in: [true, false] }
|
||||
validates :feed_url, length: { maximum: 500 }, allow_nil: true
|
||||
validates :gitlab_url, length: { maximum: 100 }, allow_blank: true, format: GITLAB_URL_REGEXP
|
||||
validates :inbox_guidelines, length: { maximum: 250 }, allow_nil: true
|
||||
validates :inbox_type, inclusion: { in: INBOXES }
|
||||
validates :instagram_url, length: { maximum: 100 }, allow_blank: true, format: INSTAGRAM_URL_REGEXP
|
||||
validates :linkedin_url, length: { maximum: 350 }, allow_blank: true, format: LINKEDIN_URL_REGEXP
|
||||
validates :mastodon_url, length: { maximum: 100 }
|
||||
validates :medium_url, length: { maximum: 200 }, allow_blank: true, format: MEDIUM_URL_REGEXP
|
||||
validates :mostly_work_with, :currently_learning, :currently_hacking_on, :available_for, length: { maximum: 500 }
|
||||
validates :name, length: { in: 1..100 }
|
||||
validates :password, length: { in: 8..100 }, allow_nil: true
|
||||
validates :stackoverflow_url, length: { maximum: 150 }, allow_blank: true, format: STACKOVERFLOW_URL_REGEXP
|
||||
validates :summary, length: { maximum: 1300 }, allow_nil: true
|
||||
validates :text_color_hex, format: COLOR_HEX_REGEXP, allow_blank: true
|
||||
validates :twitch_url, length: { maximum: 100 }, allow_blank: true, format: TWITCH_URL_REGEXP
|
||||
validates :username, presence: true, exclusion: { in: ReservedWords.all, message: MESSAGES[:invalid_username] }
|
||||
validates :username, length: { in: 2..USERNAME_MAX_LENGTH }, format: USERNAME_REGEXP
|
||||
validates :username, uniqueness: { case_sensitive: false }, if: :username_changed?
|
||||
validates :website_url, :employer_url, url: { allow_blank: true, no_local: true }
|
||||
validates :website_url, length: { maximum: 100 }, allow_nil: true
|
||||
validates :youtube_url, length: { maximum: 1000 }, format: YOUTUBE_URL_REGEXP, allow_blank: true
|
||||
|
||||
# add validators for provider related usernames
|
||||
Authentication::Providers.username_fields.each do |username_field|
|
||||
|
|
|
|||
|
|
@ -152,35 +152,16 @@ RSpec.describe User, type: :model do
|
|||
end
|
||||
# rubocop:enable RSpec/NamedSubject
|
||||
|
||||
it { is_expected.not_to allow_value("#xyz").for(:bg_color_hex) }
|
||||
it { is_expected.not_to allow_value("#xyz").for(:text_color_hex) }
|
||||
it { is_expected.not_to allow_value("AcMe_1%").for(:username) }
|
||||
it { is_expected.to allow_value("#aabbcc").for(:bg_color_hex) }
|
||||
it { is_expected.to allow_value("#aabbcc").for(:text_color_hex) }
|
||||
it { is_expected.to allow_value("#abc").for(:bg_color_hex) }
|
||||
it { is_expected.to allow_value("#abc").for(:text_color_hex) }
|
||||
it { is_expected.to allow_value("AcMe_1").for(:username) }
|
||||
|
||||
it { is_expected.to validate_inclusion_of(:inbox_type).in_array(%w[open private]) }
|
||||
it { is_expected.to validate_length_of(:available_for).is_at_most(500).allow_nil }
|
||||
it { is_expected.to validate_length_of(:behance_url).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:currently_hacking_on).is_at_most(500).allow_nil }
|
||||
it { is_expected.to validate_length_of(:currently_learning).is_at_most(500).allow_nil }
|
||||
it { is_expected.to validate_length_of(:education).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:email).is_at_most(50).allow_nil }
|
||||
it { is_expected.to validate_length_of(:employer_name).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:employer_url).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:employment_title).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:inbox_guidelines).is_at_most(250).allow_nil }
|
||||
it { is_expected.to validate_length_of(:location).is_at_most(100).allow_nil }
|
||||
it { is_expected.to validate_length_of(:mostly_work_with).is_at_most(500).allow_nil }
|
||||
it { is_expected.to validate_length_of(:name).is_at_most(100).is_at_least(1) }
|
||||
it { is_expected.to validate_length_of(:password).is_at_most(100).is_at_least(8) }
|
||||
it { is_expected.to validate_length_of(:summary).is_at_most(1300).allow_nil }
|
||||
it { is_expected.to validate_length_of(:username).is_at_most(30).is_at_least(2) }
|
||||
it { is_expected.to validate_uniqueness_of(:username).case_insensitive }
|
||||
it { is_expected.to validate_url_of(:employer_url) }
|
||||
it { is_expected.to validate_url_of(:website_url) }
|
||||
|
||||
Authentication::Providers.username_fields.each do |username_field|
|
||||
it { is_expected.to validate_uniqueness_of(username_field).allow_nil }
|
||||
|
|
@ -315,224 +296,6 @@ RSpec.describe User, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#website_url" do
|
||||
it "does not accept invalid website url" do
|
||||
user.website_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "accepts valid http website url" do
|
||||
user.website_url = "http://ben.com"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mastodon_url" do
|
||||
it "accepts valid https mastodon url" do
|
||||
user.mastodon_url = "https://mastodon.social/@test"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
|
||||
it "does not accept a denied mastodon instance" do
|
||||
user.mastodon_url = "https://SpammyMcSpamface.com/"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not accept invalid mastodon url" do
|
||||
user.mastodon_url = "mastodon.social/@test"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not accept an invalid url" do
|
||||
user.mastodon_url = "ben .com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#facebook_url" do
|
||||
it "accepts valid https facebook url", :aggregate_failures do
|
||||
%w[thepracticaldev thepracticaldev/ the.practical.dev].each do |username|
|
||||
user.facebook_url = "https://facebook.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid facebook url" do
|
||||
user.facebook_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#youtube_url" do
|
||||
it "accepts valid https youtube url", :aggregate_failures do
|
||||
%w[thepracticaldev thepracticaldev/ the.practical.dev].each do |username|
|
||||
user.youtube_url = "https://youtube.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid youtube url" do
|
||||
user.youtube_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#behance_url" do
|
||||
it "accepts valid https behance url", :aggregate_failures do
|
||||
%w[jess jess/ je-ss jes_ss].each do |username|
|
||||
user.behance_url = "https://behance.net/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid behance url" do
|
||||
user.behance_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#twitch_url" do
|
||||
it "does not accept invalid twitch url" do
|
||||
user.twitch_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "accepts valid https twitch url", :aggregate_failures do
|
||||
%w[pandyzhao pandyzhao/ PandyZhao_ pandy_Zhao].each do |username|
|
||||
user.twitch_url = "https://twitch.tv/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#stackoverflow_url" do
|
||||
it "accepts valid https stackoverflow url", :aggregate_failures do
|
||||
%w[pandyzhao pandyzhao/ pandy-zhao].each do |username|
|
||||
user.stackoverflow_url = "https://stackoverflow.com/users/7381391/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid stackoverflow url" do
|
||||
user.stackoverflow_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "accepts valid stackoverflow sub community url", :aggregate_failures do
|
||||
%w[pt ru es ja].each do |subcommunity|
|
||||
user.stackoverflow_url = "https://#{subcommunity}.stackoverflow.com/users/7381391/mazen"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid stackoverflow sub community url" do
|
||||
user.stackoverflow_url = "https://fr.stackoverflow.com/users/7381391/mazen"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#linkedin_url" do
|
||||
it "accepts valid https linkedin url", :aggregate_failures do
|
||||
%w[jessleenyc jessleenyc/ jess-lee-nyc].each do |username|
|
||||
user.linkedin_url = "https://linkedin.com/in/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "accepts valid country specific https linkedin url" do
|
||||
user.linkedin_url = "https://mx.linkedin.com/in/jessleenyc"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
|
||||
it "does not accept three letters country codes in http linkedin url" do
|
||||
user.linkedin_url = "http://mex.linkedin.com/in/jessleenyc"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not accept three letters country codes in https linkedin url" do
|
||||
user.linkedin_url = "https://mex.linkedin.com/in/jessleenyc"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not accept invalid linkedin url" do
|
||||
user.linkedin_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#dribbble_url", :aggregate_failures do
|
||||
it "accepts valid https dribbble url" do
|
||||
%w[jess jess/ je-ss je_ss].each do |username|
|
||||
user.dribbble_url = "https://dribbble.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid dribbble url" do
|
||||
user.dribbble_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#medium_url" do
|
||||
it "accepts valid https medium url", :aggregate_failures do
|
||||
%w[jess jess/ je-ss je_ss].each do |username|
|
||||
user.medium_url = "https://medium.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid medium url" do
|
||||
user.medium_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#instagram_url" do
|
||||
it "does not accept invalid instagram url" do
|
||||
user.instagram_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "accepts valid instagram url", :aggregate_failures do
|
||||
%w[jess je_ss je_ss.tt A.z.E.r.T.y].each do |username|
|
||||
user.instagram_url = "https://instagram.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#gitlab_url" do
|
||||
it "accepts valid https gitlab url", :aggregate_failures do
|
||||
%w[jess jess/ je-ss je_ss].each do |username|
|
||||
user.gitlab_url = "https://gitlab.com/#{username}"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "does not accept invalid gitlab url" do
|
||||
user.gitlab_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#employer_url" do
|
||||
it "does not accept invalid employer url" do
|
||||
user.employer_url = "ben.com"
|
||||
expect(user).not_to be_valid
|
||||
end
|
||||
|
||||
it "does accept valid http employer url" do
|
||||
user.employer_url = "http://ben.com"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
|
||||
it "does accept valid https employer url" do
|
||||
user.employer_url = "https://ben.com"
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#config_theme" do
|
||||
it "accepts valid theme" do
|
||||
user.config_theme = "night theme"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue