Skip to content

Commit 1f292b9

Browse files
committed
allowed user pings to be made to users with negative ids
1 parent 737e382 commit 1f292b9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/models/comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Comment < ApplicationRecord
44
include SoftDeletable
55
include Timestamped
66

7-
USER_PING_REG_EXP = /@#(\d+)/
7+
USER_PING_REG_EXP = /@#(-?\d+)/
88

99
scope :by, ->(user) { where(user: user) }
1010

test/models/comment_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,18 @@ class CommentTest < ActiveSupport::TestCase
1919
assert_equal posts(:question_one).id, comments(:one).root.id
2020
assert_equal posts(:question_one).id, comments(:on_answer).root.id
2121
end
22+
23+
test 'USER_PING_REG_EXP should correctly match user mentions' do
24+
valid_mentions = ["@##{User.system.id}", "@##{users(:standard_user).id}"]
25+
26+
valid_mentions.each do |mention|
27+
assert Comment::USER_PING_REG_EXP.match?(mention)
28+
end
29+
30+
invalid_mentions = ['', '@', '@#', '@#system', "@##{users(:standard_user).name}"]
31+
32+
invalid_mentions.each do |mention|
33+
assert_not Comment::USER_PING_REG_EXP.match?(mention)
34+
end
35+
end
2236
end

0 commit comments

Comments
 (0)