Add user send notifcation web condition

This commit is contained in:
Rei
2014-04-12 21:52:24 +08:00
parent 59e5daf0e3
commit 2e72fb10ee
2 changed files with 32 additions and 8 deletions

View File

@@ -14,9 +14,11 @@ class CommentNotificationJob
end
users.each do |user|
Notification.create(user: user,
subject: comment,
name: 'mention')
if user.send_mention_web?
Notification.create(user: user,
subject: comment,
name: 'mention')
end
end
end
@@ -25,9 +27,11 @@ class CommentNotificationJob
users = comment.commentable.subscribed_users - comment.mention_users - [comment.user]
users.each do |user|
Notification.create(user: user,
subject: comment,
name: 'comment')
if user.send_comment_web
Notification.create(user: user,
subject: comment,
name: 'comment')
end
end
end
end

View File

@@ -1,7 +1,7 @@
require 'test_helper'
class CommentNotificationJobTest < ActiveSupport::TestCase
test "should create_mention_notifications" do
test "should create mention notifications" do
user = create(:user)
comment = create(:comment, body: "@#{user.username}")
@@ -10,7 +10,16 @@ class CommentNotificationJobTest < ActiveSupport::TestCase
end
end
test "shuold create_comment_notifications for subscribed_users" do
test "should no create mention notification if use ignore" do
user = create(:user, send_mention_web: false)
comment = create(:comment, body: "@#{user.username}")
assert_no_difference "user.notifications.named('mention').count" do
CommentNotificationJob.create_mention_notification(comment)
end
end
test "shuold create comment notifications for subscribed_users" do
user = create(:user)
topic = create(:topic)
topic.subscribe_by user
@@ -20,4 +29,15 @@ class CommentNotificationJobTest < ActiveSupport::TestCase
CommentNotificationJob.create_comment_notification(comment)
end
end
test "shuold not create comment notifications for subscribed_users if user ignore" do
user = create(:user, send_comment_web: false)
topic = create(:topic)
topic.subscribe_by user
comment = create(:comment, commentable: topic)
assert_no_difference "user.notifications.named('comment').count" do
CommentNotificationJob.create_comment_notification(comment)
end
end
end