-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include admins when editors are mentioned.
More specifically, now when you mention a role by name, members of that role and all roles higher than it will be notified. In practice right now that means when editors are mentioned, admins will be too. You cannot (and never have been able to) @mention curators as that's everyone on the site.
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'rails_helper' | ||
|
||
describe 'notifying mentioned users' do | ||
|
||
before :each do | ||
@editor = Fabricate(:user, role: 'editor') | ||
@admin = Fabricate(:user, role: 'admin') | ||
@curator = Fabricate(:user) | ||
@originating_user = Fabricate(:user) | ||
@event = Event.create(action: 'test', originating_user: @originating_user, subject: Fabricate(:gene)) | ||
end | ||
|
||
it 'should allow mentiions by username' do | ||
text = "hey @#{@curator.username}" | ||
NotifyMentioned.new.perform(text, @originating_user, @event) | ||
expect(Notification.where(notified_user: @curator).size).to eq 1 | ||
expect(Notification.count).to eq 1 | ||
end | ||
|
||
it 'should allow mentions by role' do | ||
text = "hey @admin" | ||
NotifyMentioned.new.perform(text, @originating_user, @event) | ||
expect(Notification.where(notified_user: @admin).size).to eq 1 | ||
expect(Notification.count).to eq 1 | ||
end | ||
|
||
it 'should not allow mentions by the role "curator"' do | ||
text = "hey @curator" | ||
NotifyMentioned.new.perform(text, @originating_user, @event) | ||
expect(Notification.count).to eq 0 | ||
end | ||
|
||
it 'should also allow plural role names to be mentioned' do | ||
text = "hey @admins" | ||
NotifyMentioned.new.perform(text, @originating_user, @event) | ||
expect(Notification.where(notified_user: @admin).size).to eq 1 | ||
expect(Notification.count).to eq 1 | ||
end | ||
|
||
it 'should include admins when editors are mentioned' do | ||
text = "hey @editors" | ||
NotifyMentioned.new.perform(text, @originating_user, @event) | ||
expect(Notification.where(notified_user: @admin).size).to eq 1 | ||
expect(Notification.where(notified_user: @editor).size).to eq 1 | ||
expect(Notification.count).to eq 2 | ||
end | ||
|
||
|
||
it 'should not send notifications to the user who generated the notification' do | ||
text = "hey @editors" | ||
NotifyMentioned.new.perform(text, @editor, @event) | ||
expect(Notification.where(notified_user: @admin).size).to eq 1 | ||
expect(Notification.where(notified_user: @editor).size).to eq 0 | ||
expect(Notification.count).to eq 1 | ||
end | ||
end |