Commit e60999ec authored by Felipe Artur's avatar Felipe Artur

Improve notification settings event keys and add some specs

parent 2979d3ca
...@@ -15,23 +15,21 @@ class NotificationSetting < ActiveRecord::Base ...@@ -15,23 +15,21 @@ class NotificationSetting < ActiveRecord::Base
scope :for_groups, -> { where(source_type: 'Namespace') } scope :for_groups, -> { where(source_type: 'Namespace') }
scope :for_projects, -> { where(source_type: 'Project') } scope :for_projects, -> { where(source_type: 'Project') }
serialize :events
EMAIL_EVENTS = [ EMAIL_EVENTS = [
:new_issue_email, :new_note,
:new_note_email, :new_issue,
:closed_issue_email, :reopen_issue,
:reassigned_issue_email, :closed_issue,
:relabeled_issue_email, :reassign_issue,
:new_merge_request_email, :new_merge_request,
:reassigned_merge_request_email, :reopen_merge_request,
:relabeled_merge_request_email, :close_merge_request,
:closed_merge_request_email, :reassign_merge_request,
:issue_status_changed_email, :merge_merge_request
:merged_merge_request_email,
:merge_request_status_email
] ]
store :events, accessors: EMAIL_EVENTS, coder: JSON
before_save :set_events before_save :set_events
def self.find_or_create_for(source) def self.find_or_create_for(source)
...@@ -44,7 +42,13 @@ class NotificationSetting < ActiveRecord::Base ...@@ -44,7 +42,13 @@ class NotificationSetting < ActiveRecord::Base
setting setting
end end
# Set all event attributes as true when level is not custom
def set_events def set_events
self.events = EMAIL_EVENTS if level == "watch" # Level is a ENUM cannot compare to symbol
return if level == "custom"
EMAIL_EVENTS.each do |event|
self.send("#{event}=", true)
end
end end
end end
...@@ -153,6 +153,9 @@ class NotificationService ...@@ -153,6 +153,9 @@ class NotificationService
# Merge project watchers # Merge project watchers
recipients = add_project_watchers(recipients, note.project) recipients = add_project_watchers(recipients, note.project)
# Merge project with custom notification
recipients = add_project_custom_notifications(recipients, note.project, :new_note)
# Reject users with Mention notification level, except those mentioned in _this_ note. # Reject users with Mention notification level, except those mentioned in _this_ note.
recipients = reject_mention_users(recipients - mentioned_users, note.project) recipients = reject_mention_users(recipients - mentioned_users, note.project)
recipients = recipients + mentioned_users recipients = recipients + mentioned_users
...@@ -248,21 +251,22 @@ class NotificationService ...@@ -248,21 +251,22 @@ class NotificationService
protected protected
# Get project/group users with CUSTOM notification level
def add_project_custom_notifications(recipients, project, action) def add_project_custom_notifications(recipients, project, action)
user_ids = [] user_ids = []
user_ids += project_member_notification(project, :custom, action) user_ids += notification_settings_for(project, :custom, action)
user_ids += group_member_notification(project, :custom, action) user_ids += notification_settings_for(project.group, :custom, action)
recipients.concat(User.find(user_ids)) recipients.concat(User.find(user_ids))
end end
# Get project users with WATCH notification level # Get project users with WATCH notification level
def project_watchers(project) def project_watchers(project)
project_members = project_member_notification(project) project_members = notification_settings_for(project)
users_with_project_level_global = project_member_notification(project, :global) users_with_project_level_global = notification_settings_for(project, :global)
users_with_group_level_global = group_member_notification(project, :global) users_with_group_level_global = notification_settings_for(project, :global)
users = users_with_global_level_watch([users_with_project_level_global, users_with_group_level_global].flatten.uniq) users = users_with_global_level_watch([users_with_project_level_global, users_with_group_level_global].flatten.uniq)
users_with_project_setting = select_project_member_setting(project, users_with_project_level_global, users) users_with_project_setting = select_project_member_setting(project, users_with_project_level_global, users)
...@@ -271,23 +275,15 @@ class NotificationService ...@@ -271,23 +275,15 @@ class NotificationService
User.where(id: users_with_project_setting.concat(users_with_group_setting).uniq).to_a User.where(id: users_with_project_setting.concat(users_with_group_setting).uniq).to_a
end end
def project_member_notification(project, notification_level=nil, action=nil) def notification_settings_for(resource, notification_level = nil, action = nil)
if notification_level return [] unless resource
settings = project.notification_settings.where(level: NotificationSetting.levels[notification_level])
settings = settings.where(events: action.to_yaml) if action.present?
settings.pluck(:user_id)
else
project.notification_settings.pluck(:user_id)
end
end
def group_member_notification(project, notification_level, action=nil) if notification_level
if project.group settings = resource.notification_settings.where(level: NotificationSetting.levels[notification_level])
settings = project.group.notification_settings.where(level: NotificationSetting.levels[notification_level]) settings = settings.select { |setting| setting.events[action] } if action.present?
settings = settings.where(events: action.to_yaml) if action.present? settings.map(&:user_id)
settings.pluck(:user_id)
else else
[] resource.notification_settings.pluck(:user_id)
end end
end end
...@@ -301,7 +297,7 @@ class NotificationService ...@@ -301,7 +297,7 @@ class NotificationService
# Build a list of users based on project notifcation settings # Build a list of users based on project notifcation settings
def select_project_member_setting(project, global_setting, users_global_level_watch) def select_project_member_setting(project, global_setting, users_global_level_watch)
users = project_member_notification(project, :watch) users = notification_settings_for(project, :watch)
# If project setting is global, add to watch list if global setting is watch # If project setting is global, add to watch list if global setting is watch
global_setting.each do |user_id| global_setting.each do |user_id|
...@@ -315,7 +311,7 @@ class NotificationService ...@@ -315,7 +311,7 @@ class NotificationService
# Build a list of users based on group notification settings # Build a list of users based on group notification settings
def select_group_member_setting(project, project_members, global_setting, users_global_level_watch) def select_group_member_setting(project, project_members, global_setting, users_global_level_watch)
uids = group_member_notification(project, :watch) uids = notification_settings_for(project, :watch)
# Group setting is watch, add to users list if user is not project member # Group setting is watch, add to users list if user is not project member
users = [] users = []
...@@ -421,7 +417,7 @@ class NotificationService ...@@ -421,7 +417,7 @@ class NotificationService
end end
def new_resource_email(target, project, method) def new_resource_email(target, project, method)
recipients = build_recipients(target, project, target.author, action: method) recipients = build_recipients(target, project, target.author, action: "new")
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id).deliver_later mailer.send(method, recipient.id, target.id).deliver_later
...@@ -429,7 +425,8 @@ class NotificationService ...@@ -429,7 +425,8 @@ class NotificationService
end end
def close_resource_email(target, project, current_user, method) def close_resource_email(target, project, current_user, method)
recipients = build_recipients(target, project, current_user, action: method) action = method == :merged_merge_request_email ? "merge" : "close"
recipients = build_recipients(target, project, current_user, action: action)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, current_user.id).deliver_later mailer.send(method, recipient.id, target.id, current_user.id).deliver_later
...@@ -440,7 +437,7 @@ class NotificationService ...@@ -440,7 +437,7 @@ class NotificationService
previous_assignee_id = previous_record(target, 'assignee_id') previous_assignee_id = previous_record(target, 'assignee_id')
previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
recipients = build_recipients(target, project, current_user, action: method, previous_assignee: previous_assignee) recipients = build_recipients(target, project, current_user, action: "reassign", previous_assignee: previous_assignee)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send( mailer.send(
...@@ -463,7 +460,7 @@ class NotificationService ...@@ -463,7 +460,7 @@ class NotificationService
end end
def reopen_resource_email(target, project, current_user, method, status) def reopen_resource_email(target, project, current_user, method, status)
recipients = build_recipients(target, project, current_user, action: method) recipients = build_recipients(target, project, current_user, action: "reopen")
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, status, current_user.id).deliver_later mailer.send(method, recipient.id, target.id, status, current_user.id).deliver_later
...@@ -471,9 +468,11 @@ class NotificationService ...@@ -471,9 +468,11 @@ class NotificationService
end end
def build_recipients(target, project, current_user, action: nil, previous_assignee: nil) def build_recipients(target, project, current_user, action: nil, previous_assignee: nil)
custom_action = build_custom_key(action, target)
recipients = target.participants(current_user) recipients = target.participants(current_user)
recipients = add_project_watchers(recipients, project) recipients = add_project_watchers(recipients, project)
recipients = add_project_custom_notifications(recipients, project, action) recipients = add_project_custom_notifications(recipients, project, custom_action)
recipients = reject_mention_users(recipients, project) recipients = reject_mention_users(recipients, project)
recipients = recipients.uniq recipients = recipients.uniq
...@@ -481,7 +480,7 @@ class NotificationService ...@@ -481,7 +480,7 @@ class NotificationService
# Re-assign is considered as a mention of the new assignee so we add the # Re-assign is considered as a mention of the new assignee so we add the
# new assignee to the list of recipients after we rejected users with # new assignee to the list of recipients after we rejected users with
# the "on mention" notification level # the "on mention" notification level
if [:reassigned_merge_request_email, :reassigned_issue_email].include?(action) if [:reassign_merge_request, :reassign_issue].include?(custom_action)
recipients << previous_assignee if previous_assignee recipients << previous_assignee if previous_assignee
recipients << target.assignee recipients << target.assignee
end end
...@@ -489,7 +488,7 @@ class NotificationService ...@@ -489,7 +488,7 @@ class NotificationService
recipients = reject_muted_users(recipients, project) recipients = reject_muted_users(recipients, project)
recipients = add_subscribed_users(recipients, target) recipients = add_subscribed_users(recipients, target)
if [:new_issue_email, :new_merge_request_email].include?(action) if [:new_issue, :new_merge_request].include?(custom_action)
recipients = add_labels_subscribers(recipients, target) recipients = add_labels_subscribers(recipients, target)
end end
...@@ -519,4 +518,9 @@ class NotificationService ...@@ -519,4 +518,9 @@ class NotificationService
end end
end end
end end
# Builds key to be used if user has custom notification setting
def build_custom_key(action, object)
"#{action}_#{object.class.name.underscore}".to_sym
end
end end
...@@ -46,6 +46,7 @@ describe NotificationService, services: true do ...@@ -46,6 +46,7 @@ describe NotificationService, services: true do
project.team << [issue.assignee, :master] project.team << [issue.assignee, :master]
project.team << [note.author, :master] project.team << [note.author, :master]
create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@subscribed_participant cc this guy') create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@subscribed_participant cc this guy')
update_custom_notification(:new_note)
end end
describe :new_note do describe :new_note do
...@@ -66,6 +67,7 @@ describe NotificationService, services: true do ...@@ -66,6 +67,7 @@ describe NotificationService, services: true do
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@subscribed_participant) should_email(@subscribed_participant)
should_not_email(@u_guest_custom)
should_not_email(@u_guest_watcher) should_not_email(@u_guest_watcher)
should_not_email(note.author) should_not_email(note.author)
should_not_email(@u_participating) should_not_email(@u_participating)
...@@ -116,6 +118,7 @@ describe NotificationService, services: true do ...@@ -116,6 +118,7 @@ describe NotificationService, services: true do
should_email(note.noteable.author) should_email(note.noteable.author)
should_email(note.noteable.assignee) should_email(note.noteable.assignee)
should_email(@u_mentioned) should_email(@u_mentioned)
should_not_email(@u_guest_custom)
should_not_email(@u_guest_watcher) should_not_email(@u_guest_watcher)
should_not_email(@u_watcher) should_not_email(@u_watcher)
should_not_email(note.author) should_not_email(note.author)
...@@ -238,13 +241,14 @@ describe NotificationService, services: true do ...@@ -238,13 +241,14 @@ describe NotificationService, services: true do
build_team(note.project) build_team(note.project)
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
allow_any_instance_of(Commit).to receive(:author).and_return(@u_committer) allow_any_instance_of(Commit).to receive(:author).and_return(@u_committer)
update_custom_notification(:new_note)
end end
describe '#new_note, #perform_enqueued_jobs' do describe '#new_note, #perform_enqueued_jobs' do
it do it do
notification.new_note(note) notification.new_note(note)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_committer) should_email(@u_committer)
should_email(@u_watcher) should_email(@u_watcher)
should_not_email(@u_mentioned) should_not_email(@u_mentioned)
...@@ -285,6 +289,7 @@ describe NotificationService, services: true do ...@@ -285,6 +289,7 @@ describe NotificationService, services: true do
build_team(issue.project) build_team(issue.project)
add_users_with_subscription(issue.project, issue) add_users_with_subscription(issue.project, issue)
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
update_custom_notification(:new_issue)
end end
describe '#new_issue' do describe '#new_issue' do
...@@ -294,6 +299,7 @@ describe NotificationService, services: true do ...@@ -294,6 +299,7 @@ describe NotificationService, services: true do
should_email(issue.assignee) should_email(issue.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_not_email(@u_mentioned) should_not_email(@u_mentioned)
should_not_email(@u_participating) should_not_email(@u_participating)
...@@ -349,12 +355,15 @@ describe NotificationService, services: true do ...@@ -349,12 +355,15 @@ describe NotificationService, services: true do
end end
describe '#reassigned_issue' do describe '#reassigned_issue' do
before { update_custom_notification(:reassign_issue) }
it 'emails new assignee' do it 'emails new assignee' do
notification.reassigned_issue(issue, @u_disabled) notification.reassigned_issue(issue, @u_disabled)
should_email(issue.assignee) should_email(issue.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
...@@ -371,6 +380,7 @@ describe NotificationService, services: true do ...@@ -371,6 +380,7 @@ describe NotificationService, services: true do
should_email(@u_mentioned) should_email(@u_mentioned)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
...@@ -387,6 +397,7 @@ describe NotificationService, services: true do ...@@ -387,6 +397,7 @@ describe NotificationService, services: true do
should_email(issue.assignee) should_email(issue.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
...@@ -403,6 +414,7 @@ describe NotificationService, services: true do ...@@ -403,6 +414,7 @@ describe NotificationService, services: true do
should_email(issue.assignee) should_email(issue.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
...@@ -418,6 +430,7 @@ describe NotificationService, services: true do ...@@ -418,6 +430,7 @@ describe NotificationService, services: true do
expect(issue.assignee).to be @u_mentioned expect(issue.assignee).to be @u_mentioned
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_not_email(issue.assignee) should_not_email(issue.assignee)
...@@ -518,6 +531,8 @@ describe NotificationService, services: true do ...@@ -518,6 +531,8 @@ describe NotificationService, services: true do
end end
describe '#close_issue' do describe '#close_issue' do
before { update_custom_notification(:close_issue) }
it 'should sent email to issue assignee and issue author' do it 'should sent email to issue assignee and issue author' do
notification.close_issue(issue, @u_disabled) notification.close_issue(issue, @u_disabled)
...@@ -525,6 +540,7 @@ describe NotificationService, services: true do ...@@ -525,6 +540,7 @@ describe NotificationService, services: true do
should_email(issue.author) should_email(issue.author)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
...@@ -564,6 +580,8 @@ describe NotificationService, services: true do ...@@ -564,6 +580,8 @@ describe NotificationService, services: true do
end end
describe '#reopen_issue' do describe '#reopen_issue' do
before { update_custom_notification(:reopen_issue) }
it 'should send email to issue assignee and issue author' do it 'should send email to issue assignee and issue author' do
notification.reopen_issue(issue, @u_disabled) notification.reopen_issue(issue, @u_disabled)
...@@ -571,6 +589,7 @@ describe NotificationService, services: true do ...@@ -571,6 +589,7 @@ describe NotificationService, services: true do
should_email(issue.author) should_email(issue.author)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
...@@ -620,6 +639,8 @@ describe NotificationService, services: true do ...@@ -620,6 +639,8 @@ describe NotificationService, services: true do
end end
describe '#new_merge_request' do describe '#new_merge_request' do
before { update_custom_notification(:new_merge_request) }
it do it do
notification.new_merge_request(merge_request, @u_disabled) notification.new_merge_request(merge_request, @u_disabled)
...@@ -628,6 +649,7 @@ describe NotificationService, services: true do ...@@ -628,6 +649,7 @@ describe NotificationService, services: true do
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
should_not_email(@u_lazy_participant) should_not_email(@u_lazy_participant)
...@@ -674,6 +696,8 @@ describe NotificationService, services: true do ...@@ -674,6 +696,8 @@ describe NotificationService, services: true do
end end
describe '#reassigned_merge_request' do describe '#reassigned_merge_request' do
before { update_custom_notification(:reassign_merge_request) }
it do it do
notification.reassigned_merge_request(merge_request, merge_request.author) notification.reassigned_merge_request(merge_request, merge_request.author)
...@@ -683,6 +707,7 @@ describe NotificationService, services: true do ...@@ -683,6 +707,7 @@ describe NotificationService, services: true do
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
...@@ -750,12 +775,15 @@ describe NotificationService, services: true do ...@@ -750,12 +775,15 @@ describe NotificationService, services: true do
end end
describe '#closed_merge_request' do describe '#closed_merge_request' do
before { update_custom_notification(:close_merge_request) }
it do it do
notification.close_mr(merge_request, @u_disabled) notification.close_mr(merge_request, @u_disabled)
should_email(merge_request.assignee) should_email(merge_request.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
...@@ -796,6 +824,8 @@ describe NotificationService, services: true do ...@@ -796,6 +824,8 @@ describe NotificationService, services: true do
end end
describe '#merged_merge_request' do describe '#merged_merge_request' do
before { update_custom_notification(:merge_merge_request) }
it do it do
notification.merge_mr(merge_request, @u_disabled) notification.merge_mr(merge_request, @u_disabled)
...@@ -805,6 +835,7 @@ describe NotificationService, services: true do ...@@ -805,6 +835,7 @@ describe NotificationService, services: true do
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
...@@ -842,6 +873,8 @@ describe NotificationService, services: true do ...@@ -842,6 +873,8 @@ describe NotificationService, services: true do
end end
describe '#reopen_merge_request' do describe '#reopen_merge_request' do
before { update_custom_notification(:reopen_merge_request) }
it do it do
notification.reopen_mr(merge_request, @u_disabled) notification.reopen_mr(merge_request, @u_disabled)
...@@ -851,6 +884,7 @@ describe NotificationService, services: true do ...@@ -851,6 +884,7 @@ describe NotificationService, services: true do
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@u_guest_watcher) should_email(@u_guest_watcher)
should_email(@u_guest_custom)
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
...@@ -904,6 +938,7 @@ describe NotificationService, services: true do ...@@ -904,6 +938,7 @@ describe NotificationService, services: true do
should_email(@u_participating) should_email(@u_participating)
should_email(@u_lazy_participant) should_email(@u_lazy_participant)
should_not_email(@u_guest_watcher) should_not_email(@u_guest_watcher)
should_not_email(@u_guest_custom)
should_not_email(@u_disabled) should_not_email(@u_disabled)
end end
end end
...@@ -924,7 +959,8 @@ describe NotificationService, services: true do ...@@ -924,7 +959,8 @@ describe NotificationService, services: true do
# It should be treated with a :participating notification_level # It should be treated with a :participating notification_level
@u_lazy_participant = create(:user, username: 'lazy-participant') @u_lazy_participant = create(:user, username: 'lazy-participant')
create_guest_watcher @u_guest_watcher = create_user_with_notification(:watch, 'guest_watching')
@u_guest_custom = create_user_with_notification(:custom, 'guest_custom')
project.team << [@u_watcher, :master] project.team << [@u_watcher, :master]
project.team << [@u_participating, :master] project.team << [@u_participating, :master]
...@@ -944,10 +980,18 @@ describe NotificationService, services: true do ...@@ -944,10 +980,18 @@ describe NotificationService, services: true do
user user
end end
def create_guest_watcher def create_user_with_notification(level, username)
@u_guest_watcher = create(:user, username: 'guest_watching') user = create(:user, username: username)
setting = @u_guest_watcher.notification_settings_for(project) setting = user.notification_settings_for(project)
setting.level = :watch setting.level = level
setting.save
user
end
def update_custom_notification(event)
setting = @u_guest_custom.notification_settings_for(project)
setting.events[event] = true
setting.save setting.save
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment