Raise a clearer error message when the user tries to comment on a draft post (#18588)
* Raise a clearer error message when the user tries to comment on a draft post. * Apply suggestions from code review Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com> Co-authored-by: Fernando Valverde <fernando@fdo.cr> Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
This commit is contained in:
parent
ba4118dcda
commit
038c889432
4 changed files with 7 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue