From 3b3abac8f602836674d36657762725c41ef56763 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 10 Aug 2017 18:37:22 -0500 Subject: [PATCH] pools: disallow asterisks and numeric-only names. --- app/models/pool.rb | 4 ++++ test/factories/pool.rb | 2 +- test/unit/pool_test.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/pool.rb b/app/models/pool.rb index 47d201552..a24668b87 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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 diff --git a/test/factories/pool.rb b/test/factories/pool.rb index 2b080c50c..ea468bdf6 100644 --- a/test/factories/pool.rb +++ b/test/factories/pool.rb @@ -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 diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index 09abb1623..fc4f3ec3f 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -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)