pools: disallow asterisks and numeric-only names.
This commit is contained in:
@@ -387,8 +387,12 @@ class Pool < ApplicationRecord
|
||||
errors[:name] << "cannot be any of the following names: any, none, series, collection"
|
||||
when /,/
|
||||
errors[:name] << "cannot contain commas"
|
||||
when /\*/
|
||||
errors[:name] << "cannot contain asterisks"
|
||||
when ""
|
||||
errors[:name] << "cannot be blank"
|
||||
when /\A[0-9]+\z/
|
||||
errors[:name] << "cannot contain only digits"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory(:pool) do
|
||||
name {(rand(1_000_000) + 100).to_s}
|
||||
name {"pool_" + (rand(1_000_000) + 100).to_s}
|
||||
association :creator, :factory => :user
|
||||
description {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
|
||||
@@ -263,6 +263,8 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "when validating names" do
|
||||
should_not allow_value("foo,bar").for(:name)
|
||||
should_not allow_value("foo*bar").for(:name)
|
||||
should_not allow_value("123").for(:name)
|
||||
should_not allow_value("___").for(:name)
|
||||
should_not allow_value(" ").for(:name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user