Escape range separator (#2593)

The char "-" in regexp defaults a a separator for a range of character, for example: "a-z", Ruby is smart enough to understand "-_" is no range but it does emit a warning, by properly escaping the char "-" we ensure that no warning or issues can arise in the future.
This commit is contained in:
rhymes 2019-04-29 20:27:26 +02:00 committed by Ben Halpern
parent d1b286a835
commit af83bab2d0
2 changed files with 2 additions and 2 deletions

View file

@ -24,7 +24,7 @@ class Article < ApplicationRecord
has_many :rating_votes
has_many :page_views
validates :slug, presence: { if: :published? }, format: /\A[0-9a-z-_]*\z/,
validates :slug, presence: { if: :published? }, format: /\A[0-9a-z\-_]*\z/,
uniqueness: { scope: :user_id }
validates :title, presence: true,
length: { maximum: 128 }

View file

@ -111,7 +111,7 @@ RSpec.describe Article, type: :model do
let(:article1) { build(:article, title: title, published: false) }
before do
article0.validate
article0.validate!
end
context "when unpublished" do