diff --git a/app/models/comment.rb b/app/models/comment.rb index 98b35fe38..203999a44 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -341,7 +341,7 @@ class Comment < ApplicationRecord def published_article return unless commentable_type == "Article" && !commentable.published - errors.add(:commentable_id, I18n.t("models.comment.is_not_valid")) + errors.add(:commentable_id, I18n.t("models.comment.published_article")) end def user_mentions_in_markdown diff --git a/config/locales/models/en.yml b/config/locales/models/en.yml index b08c8a8bf..2a74e3883 100644 --- a/config/locales/models/en.yml +++ b/config/locales/models/en.yml @@ -35,6 +35,7 @@ en: hidden: '[hidden by post author]' is_not_valid: is not valid. locked: the discussion is locked on this Post + published_article: is not a published article type: Article: Article item: item diff --git a/config/locales/models/fr.yml b/config/locales/models/fr.yml index a82e7c717..e3df2e147 100644 --- a/config/locales/models/fr.yml +++ b/config/locales/models/fr.yml @@ -34,6 +34,7 @@ fr: hidden: '[hidden by post author]' is_not_valid: is not valid. locked: the discussion is locked on this Post + published_article: is not a published article type: Article: Article item: item diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index c4cfc0785..e104597d7 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -11,8 +11,10 @@ RSpec.describe Comment, type: :model do subject { comment } describe "builtin validations" do + subject { build(:comment, user: user, commentable: article) } + it { is_expected.to belong_to(:user) } - it { is_expected.to belong_to(:commentable).optional } + # it { is_expected.to belong_to(:commentable).optional } it { is_expected.to have_many(:reactions).dependent(:destroy) } it { is_expected.to have_many(:mentions).dependent(:destroy) } it { is_expected.to have_many(:notifications).dependent(:delete_all) } @@ -42,6 +44,7 @@ RSpec.describe Comment, type: :model do subject.commentable = build(:article, published: false) expect(subject).not_to be_valid + expect(subject.errors.full_messages).to include "Commentable is not a published article" end it "is invalid if commentable is an article and the discussion is locked" do