diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-02 00:24:38 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-13 21:51:11 +0300 |
commit | e60999ec5c789f1e4e91dd5c71f7c28348164b03 (patch) | |
tree | 986840c9691539e5d75c6dbab718a455ece624ba /spec/services | |
parent | 2979d3ca1b6fdf8ba2e1b0a6f92f03bd458911d4 (diff) |
Improve notification settings event keys and add some specs
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/notification_service_spec.rb | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index b99e02ba678..49eaeabb8f4 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -46,6 +46,7 @@ describe NotificationService, services: true do project.team << [issue.assignee, :master] project.team << [note.author, :master] create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@subscribed_participant cc this guy') + update_custom_notification(:new_note) end describe :new_note do @@ -66,6 +67,7 @@ describe NotificationService, services: true do should_email(@subscriber) should_email(@watcher_and_subscriber) should_email(@subscribed_participant) + should_not_email(@u_guest_custom) should_not_email(@u_guest_watcher) should_not_email(note.author) should_not_email(@u_participating) @@ -116,6 +118,7 @@ describe NotificationService, services: true do should_email(note.noteable.author) should_email(note.noteable.assignee) should_email(@u_mentioned) + should_not_email(@u_guest_custom) should_not_email(@u_guest_watcher) should_not_email(@u_watcher) should_not_email(note.author) @@ -238,13 +241,14 @@ describe NotificationService, services: true do build_team(note.project) ActionMailer::Base.deliveries.clear allow_any_instance_of(Commit).to receive(:author).and_return(@u_committer) + update_custom_notification(:new_note) end describe '#new_note, #perform_enqueued_jobs' do it do notification.new_note(note) - should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_committer) should_email(@u_watcher) should_not_email(@u_mentioned) @@ -285,6 +289,7 @@ describe NotificationService, services: true do build_team(issue.project) add_users_with_subscription(issue.project, issue) ActionMailer::Base.deliveries.clear + update_custom_notification(:new_issue) end describe '#new_issue' do @@ -294,6 +299,7 @@ describe NotificationService, services: true do should_email(issue.assignee) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_not_email(@u_mentioned) should_not_email(@u_participating) @@ -349,12 +355,15 @@ describe NotificationService, services: true do end describe '#reassigned_issue' do + before { update_custom_notification(:reassign_issue) } + it 'emails new assignee' do notification.reassigned_issue(issue, @u_disabled) should_email(issue.assignee) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_not_email(@unsubscriber) @@ -371,6 +380,7 @@ describe NotificationService, services: true do should_email(@u_mentioned) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_not_email(@unsubscriber) @@ -387,6 +397,7 @@ describe NotificationService, services: true do should_email(issue.assignee) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_not_email(@unsubscriber) @@ -403,6 +414,7 @@ describe NotificationService, services: true do should_email(issue.assignee) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_not_email(@unsubscriber) @@ -418,6 +430,7 @@ describe NotificationService, services: true do expect(issue.assignee).to be @u_mentioned should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_not_email(issue.assignee) @@ -518,6 +531,8 @@ describe NotificationService, services: true do end describe '#close_issue' do + before { update_custom_notification(:close_issue) } + it 'should sent email to issue assignee and issue author' do notification.close_issue(issue, @u_disabled) @@ -525,6 +540,7 @@ describe NotificationService, services: true do should_email(issue.author) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_email(@watcher_and_subscriber) @@ -564,6 +580,8 @@ describe NotificationService, services: true do end describe '#reopen_issue' do + before { update_custom_notification(:reopen_issue) } + it 'should send email to issue assignee and issue author' do notification.reopen_issue(issue, @u_disabled) @@ -571,6 +589,7 @@ describe NotificationService, services: true do should_email(issue.author) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_email(@watcher_and_subscriber) @@ -620,6 +639,8 @@ describe NotificationService, services: true do end describe '#new_merge_request' do + before { update_custom_notification(:new_merge_request) } + it do notification.new_merge_request(merge_request, @u_disabled) @@ -628,6 +649,7 @@ describe NotificationService, services: true do should_email(@watcher_and_subscriber) should_email(@u_participant_mentioned) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_not_email(@u_participating) should_not_email(@u_disabled) should_not_email(@u_lazy_participant) @@ -674,6 +696,8 @@ describe NotificationService, services: true do end describe '#reassigned_merge_request' do + before { update_custom_notification(:reassign_merge_request) } + it do notification.reassigned_merge_request(merge_request, merge_request.author) @@ -683,6 +707,7 @@ describe NotificationService, services: true do should_email(@subscriber) should_email(@watcher_and_subscriber) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_not_email(@unsubscriber) should_not_email(@u_participating) should_not_email(@u_disabled) @@ -750,12 +775,15 @@ describe NotificationService, services: true do end describe '#closed_merge_request' do + before { update_custom_notification(:close_merge_request) } + it do notification.close_mr(merge_request, @u_disabled) should_email(merge_request.assignee) should_email(@u_watcher) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_email(@u_participant_mentioned) should_email(@subscriber) should_email(@watcher_and_subscriber) @@ -796,6 +824,8 @@ describe NotificationService, services: true do end describe '#merged_merge_request' do + before { update_custom_notification(:merge_merge_request) } + it do notification.merge_mr(merge_request, @u_disabled) @@ -805,6 +835,7 @@ describe NotificationService, services: true do should_email(@subscriber) should_email(@watcher_and_subscriber) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_not_email(@unsubscriber) should_not_email(@u_participating) should_not_email(@u_disabled) @@ -842,6 +873,8 @@ describe NotificationService, services: true do end describe '#reopen_merge_request' do + before { update_custom_notification(:reopen_merge_request) } + it do notification.reopen_mr(merge_request, @u_disabled) @@ -851,6 +884,7 @@ describe NotificationService, services: true do should_email(@subscriber) should_email(@watcher_and_subscriber) should_email(@u_guest_watcher) + should_email(@u_guest_custom) should_not_email(@unsubscriber) should_not_email(@u_participating) should_not_email(@u_disabled) @@ -904,6 +938,7 @@ describe NotificationService, services: true do should_email(@u_participating) should_email(@u_lazy_participant) should_not_email(@u_guest_watcher) + should_not_email(@u_guest_custom) should_not_email(@u_disabled) end end @@ -924,7 +959,8 @@ describe NotificationService, services: true do # It should be treated with a :participating notification_level @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_participating, :master] @@ -944,10 +980,18 @@ describe NotificationService, services: true do user end - def create_guest_watcher - @u_guest_watcher = create(:user, username: 'guest_watching') - setting = @u_guest_watcher.notification_settings_for(project) - setting.level = :watch + def create_user_with_notification(level, username) + user = create(:user, username: username) + setting = user.notification_settings_for(project) + 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 end |