1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'spec_helper'
describe 'projects/_home_panel' do
let(:group) { create(:group) }
let(:project) { create(:project, :public, namespace: group) }
let(:notification_settings) do
user&.notification_settings_for(project)
end
before do
assign(:project, project)
assign(:notification_setting, notification_settings)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:can?).and_return(false)
end
context 'when user is signed in' do
let(:user) { create(:user) }
it 'makes it possible to set notification level' do
render
expect(view).to render_template('shared/notifications/_button')
expect(rendered).to have_selector('.notification-dropdown')
end
end
context 'when user is signed out' do
let(:user) { nil }
it 'is not possible to set notification level' do
render
expect(rendered).not_to have_selector('.notification_dropdown')
end
end
context 'when project' do
let!(:user) { create(:user) }
let(:badges) { project.badges }
context 'has no badges' do
it 'should not render any badge' do
render
expect(rendered).to have_selector('.project-badges')
expect(rendered).not_to have_selector('.project-badges > a')
end
end
shared_examples 'show badges' do
it 'should render the all badges' do
render
expect(rendered).to have_selector('.project-badges a')
badges.each do |badge|
expect(rendered).to have_link(href: badge.rendered_link_url)
end
end
end
context 'only has group badges' do
before do
create(:group_badge, group: project.group)
end
it_behaves_like 'show badges'
end
context 'only has project badges' do
before do
create(:project_badge, project: project)
end
it_behaves_like 'show badges'
end
context 'has both group and project badges' do
before do
create(:project_badge, project: project)
create(:group_badge, group: project.group)
end
it_behaves_like 'show badges'
end
end
end