Convert underscores in article slugs properly (#2472)
This commit is contained in:
parent
f17d0f34e1
commit
4e8787f606
2 changed files with 11 additions and 1 deletions
|
|
@ -563,7 +563,7 @@ class Article < ApplicationRecord
|
|||
end
|
||||
|
||||
def title_to_slug
|
||||
title.to_s.downcase.parameterize + "-" + rand(100_000).to_s(26)
|
||||
title.to_s.downcase.parameterize.tr("_", "") + "-" + rand(100_000).to_s(26)
|
||||
end
|
||||
|
||||
def bust_cache
|
||||
|
|
|
|||
|
|
@ -123,6 +123,11 @@ RSpec.describe Article, type: :model do
|
|||
article1.validate
|
||||
expect(article1.slug).not_to start_with(article0.slug)
|
||||
end
|
||||
|
||||
it "properly converts underscores and still has a valid slug" do
|
||||
underscored_article = build(:article, title: "hey_hey_hey node_modules", published: false)
|
||||
expect(underscored_article.valid?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context "when published" do
|
||||
|
|
@ -136,6 +141,11 @@ RSpec.describe Article, type: :model do
|
|||
article0.update(title: "New title.")
|
||||
expect(article0.slug).to start_with("hey-this-is-a-slug")
|
||||
end
|
||||
|
||||
it "properly converts underscores and still has a valid slug" do
|
||||
underscored_article = build(:article, title: "hey_hey_hey node_modules", published: true)
|
||||
expect(underscored_article.valid?).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue