diff --git a/app/helpers/mention_helper.rb b/app/helpers/mention_helper.rb index 2d28b5a..cbbd542 100644 --- a/app/helpers/mention_helper.rb +++ b/app/helpers/mention_helper.rb @@ -1,6 +1,6 @@ module MentionHelper def mention_search_regex - /(?:^\s?|\s)@([^\s?:^\.]+)/m + /(?:^\s?|\s)@([^\s?:^\.?:^\,]+)/m end def has_mentions? text="" diff --git a/test/unit/notify_mentioned_users_job_test.rb b/test/unit/notify_mentioned_users_job_test.rb new file mode 100644 index 0000000..b792d70 --- /dev/null +++ b/test/unit/notify_mentioned_users_job_test.rb @@ -0,0 +1,96 @@ +require_relative "../test_helper" + +class NotifyMentionedUsersJobTest < ActiveSupport::TestCase + + def setup + @person1 = fast_create(Person, :identifier => "tester") + @person2 = fast_create(Person, :identifier => "friend") + @person3 = fast_create(Person, :identifier => "third") + @person1.add_friend @person2 + @person1.add_friend @person3 + + process_delayed_job_queue + ProfileFollower.delete_all + ActionTrackerNotification.delete_all + end + + should 'create notify mentioned uses job if scrap content has mentioned users' do + s = Scrap.new + s.sender = @person1 + s.receiver = @person2 + s.content = "Run @third, run!!!" + s.save! + + action_tracker = ActionTracker::Record.create(:user => @person1, :target => s, + :verb => 'notify_mentioned_users', + :params => {"content" => s.content, "url"=>s.receiver.url}) + + job = NotifyMentionedUsersJob.new(action_tracker.id) + job.perform + process_delayed_job_queue + + assert_equal 2, ActionTrackerNotification.count + + notification = ActionTrackerNotification.find_by profile_id: @person3.id + assert_equal action_tracker, notification.action_tracker + end + + should 'create notify mentioned uses job if comment body has mentioned users' do + a = fast_create(Article, :profile_id => @person1.id, :name => "Zombiesss") + + comment = Comment.create!(:author => @person1, :body => 'Run @third, run!!!', :source => a) + action_tracker = ActionTracker::Record.create(:user => @person1, :target => comment, + :verb => 'notify_mentioned_users', + :params => {"body" => comment.body, "url" => comment.url}) + + job = NotifyMentionedUsersJob.new(action_tracker.id) + job.perform + process_delayed_job_queue + + assert_equal 1, ActionTrackerNotification.count + + notification = ActionTrackerNotification.find_by profile_id: @person3.id + assert_equal action_tracker, notification.action_tracker + end + + should 'not create notify mentioned users job if scrap content has no mentioned users' do + s = Scrap.new + s.sender = @person1 + s.receiver = @person2 + s.content = "Run third, run!!!" + s.save! + + action_tracker = ActionTracker::Record.create(:user => @person1, :target => s, + :verb => 'notify_mentioned_users', + :params => {"content" => s.content, "url"=>s.receiver.url}) + + job = NotifyMentionedUsersJob.new(action_tracker.id) + job.perform + process_delayed_job_queue + + assert_equal 1, ActionTrackerNotification.count + assert_not_includes ActionTrackerNotification.all.map{|a|a.action_tracker.verb}, "notify_mentioned_users" + end + + should 'not create notify mentioned users job if comment body has no mentioned users' do + a = fast_create(Article, :profile_id => @person1.id, :name => "Zombiesss") + + comment = Comment.create!(:author => @person1, :body => 'Run third, run!!!', :source => a) + action_tracker = ActionTracker::Record.create(:user => @person1, :target => comment, + :verb => 'notify_mentioned_users', + :params => {"body" => comment.body, "url" => comment.url}) + + job = NotifyMentionedUsersJob.new(action_tracker.id) + job.perform + process_delayed_job_queue + + assert_empty ActionTrackerNotification.all + end + + should 'not create notification from mention if the mentioned users are also followers' do + end + + should 'not show notification from mention on the authors wall' do + end + +end -- libgit2 0.21.2