Commit 08b3d7f6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor notification helper and fix notification service

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 855b2820
...@@ -16,8 +16,8 @@ module NotificationsHelper ...@@ -16,8 +16,8 @@ module NotificationsHelper
end end
end end
def notification_icon(level) def notification_icon(level, text = nil)
icon("#{notification_icon_class(level)} fw") icon("#{notification_icon_class(level)} fw", text: text)
end end
def notification_title(level) def notification_title(level)
...@@ -39,14 +39,10 @@ module NotificationsHelper ...@@ -39,14 +39,10 @@ module NotificationsHelper
notification_title: title notification_title: title
} }
content_tag(:li, class: active_level_for(setting, level)) do content_tag(:li, class: ('active' if setting.level == level)) do
link_to '#', class: 'update-notification', data: data do link_to '#', class: 'update-notification', data: data do
icon("#{notification_icon_class(level)} fw", text: title) notification_icon(level, title)
end end
end end
end end
def active_level_for(setting, level)
'active' if setting.level == level
end
end end
...@@ -352,7 +352,7 @@ class NotificationService ...@@ -352,7 +352,7 @@ class NotificationService
setting = user.notification_settings.find_by(source: project) setting = user.notification_settings.find_by(source: project)
if !setting && project.group if !setting && project.group
setting = user.notification_settings.find_by(source: group) setting = user.notification_settings.find_by(source: project.group)
end end
# reject users who globally set mention notification and has no setting per project/group # reject users who globally set mention notification and has no setting per project/group
......
...@@ -2,34 +2,15 @@ require 'spec_helper' ...@@ -2,34 +2,15 @@ require 'spec_helper'
describe NotificationsHelper do describe NotificationsHelper do
describe 'notification_icon' do describe 'notification_icon' do
let(:notification) { double(disabled?: false, participating?: false, watch?: false) } it { expect(notification_icon(:disabled)).to match('class="fa fa-microphone-slash fa-fw"') }
it { expect(notification_icon(:participating)).to match('class="fa fa-volume-up fa-fw"') }
context "disabled notification" do it { expect(notification_icon(:mention)).to match('class="fa fa-at fa-fw"') }
before { allow(notification).to receive(:disabled?).and_return(true) } it { expect(notification_icon(:global)).to match('class="fa fa-globe fa-fw"') }
it { expect(notification_icon(:watch)).to match('class="fa fa-eye fa-fw"') }
it "has a red icon" do end
expect(notification_icon(notification)).to match('class="fa fa-volume-off ns-mute"')
end
end
context "participating notification" do
before { allow(notification).to receive(:participating?).and_return(true) }
it "has a blue icon" do
expect(notification_icon(notification)).to match('class="fa fa-volume-down ns-part"')
end
end
context "watched notification" do
before { allow(notification).to receive(:watch?).and_return(true) }
it "has a green icon" do
expect(notification_icon(notification)).to match('class="fa fa-volume-up ns-watch"')
end
end
it "has a blue icon" do describe 'notification_title' do
expect(notification_icon(notification)).to match('class="fa fa-circle-o ns-default"') it { expect(notification_title(:watch)).to match('Watch') }
end it { expect(notification_title(:mention)).to match('On mention') }
end end
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