Skip to content

Commit 720b95d

Browse files
Nick-RaalBilka2
andauthored
AO3-6956 Corrected error message for duplicate comments (#5135)
* AO3-6956 Corrected error message for duplicate comments * Updated to match suggestions * Added test case * Aligned with formatting guidelines * Fixed test * Update config/locales/models/en.yml Co-authored-by: Bilka <[email protected]> * Updated rspec test to only use partial matching * Normalized translations --------- Co-authored-by: Bilka <[email protected]>
1 parent 356d712 commit 720b95d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

app/models/comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def check_for_spam
7171
validates :comment_content, uniqueness: {
7272
scope: [:commentable_id, :commentable_type, :name, :email, :pseud_id],
7373
unless: :is_deleted?,
74-
message: ts("^This comment has already been left on this work. (It may not appear right away for performance reasons.)")
74+
message: :duplicate_comment
7575
}
7676

7777
scope :ordered_by_date, -> { order('created_at DESC') }

config/locales/models/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ en:
9090
required: can't be blank
9191
comment:
9292
attributes:
93+
comment_content:
94+
duplicate_comment: "^You've already left this comment here. (It may not appear right away for performance reasons.)"
9395
commentable:
9496
format: "%{message}"
9597
guest_replies_off: Sorry, this user doesn't allow non-Archive users to reply to their comments.

spec/models/comment_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,18 @@
9494
end
9595
end
9696

97-
context "with an existing comment from the same user" do
97+
context "with an existing comment from the same user" do
9898
let(:first_comment) { create(:comment) }
9999

100100
let(:second_comment) do
101101
attributes = %w[pseud_id commentable_id commentable_type comment_content name email]
102102
Comment.new(first_comment.attributes.slice(*attributes))
103103
end
104104

105-
it "should be invalid if exactly duplicated" do
105+
it "should be invalid if exactly duplicated" do
106106
expect(second_comment.valid?).to be_falsy
107107
expect(second_comment.errors.attribute_names).to include(:comment_content)
108+
expect(second_comment.errors.full_messages.first).to include("You've already")
108109
end
109110

110111
it "should not be invalid if in the process of being deleted" do

0 commit comments

Comments
 (0)