diff --git a/app/models/article.rb b/app/models/article.rb index 29dff2879..bf5355371 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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 } diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 1e03a0769..2e13b9dca 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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