debian-mirror-gitlab/spec/views/projects/_home_panel.html.haml_spec.rb

146 lines
3.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe 'projects/_home_panel' do
2018-11-18 11:00:15 +05:30
context 'notifications' do
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
before do
assign(:project, project)
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
2018-11-20 20:47:30 +05:30
allow(project).to receive(:license_anchor_data).and_return(false)
2018-11-18 11:00:15 +05:30
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
context 'when user is signed in' do
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
before do
notification_settings = user.notification_settings_for(project)
assign(:notification_setting, notification_settings)
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
it 'makes it possible to set notification level' do
render
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
expect(view).to render_template('shared/notifications/_new_button')
2018-11-18 11:00:15 +05:30
expect(rendered).to have_selector('.notification-dropdown')
end
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
context 'when user is signed out' do
let(:user) { nil }
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
before do
assign(:notification_setting, nil)
end
2018-03-27 19:54:05 +05:30
2018-11-18 11:00:15 +05:30
it 'is not possible to set notification level' do
2018-03-27 19:54:05 +05:30
render
2018-11-18 11:00:15 +05:30
expect(rendered).not_to have_selector('.notification_dropdown')
2018-03-27 19:54:05 +05:30
end
end
2018-11-18 11:00:15 +05:30
end
2018-03-27 19:54:05 +05:30
2018-11-18 11:00:15 +05:30
context 'badges' do
2018-03-27 19:54:05 +05:30
shared_examples 'show badges' do
2019-05-18 00:54:41 +05:30
it 'renders the all badges' do
2018-03-27 19:54:05 +05:30
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
2018-11-18 11:00:15 +05:30
let(:user) { create(:user) }
let(:badges) { project.badges }
before do
assign(:project, project)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
2018-11-20 20:47:30 +05:30
allow(project).to receive(:license_anchor_data).and_return(false)
2018-11-18 11:00:15 +05:30
end
context 'has no badges' do
let(:project) { create(:project) }
2019-05-18 00:54:41 +05:30
it 'does not render any badge' do
2018-11-18 11:00:15 +05:30
render
2018-11-20 20:47:30 +05:30
expect(rendered).not_to have_selector('.project-badges')
2018-11-18 11:00:15 +05:30
end
end
2018-03-27 19:54:05 +05:30
context 'only has group badges' do
2018-11-18 11:00:15 +05:30
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
2018-03-27 19:54:05 +05:30
before do
create(:group_badge, group: project.group)
end
it_behaves_like 'show badges'
end
context 'only has project badges' do
2018-11-18 11:00:15 +05:30
let(:project) { create(:project) }
2018-03-27 19:54:05 +05:30
before do
create(:project_badge, project: project)
end
it_behaves_like 'show badges'
end
context 'has both group and project badges' do
2018-11-18 11:00:15 +05:30
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
2018-03-27 19:54:05 +05:30
before do
create(:project_badge, project: project)
create(:group_badge, group: project.group)
end
it_behaves_like 'show badges'
end
end
2018-11-18 11:00:15 +05:30
context 'project id' do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
assign(:project, project)
allow(view).to receive(:current_user).and_return(user)
2018-11-20 20:47:30 +05:30
allow(project).to receive(:license_anchor_data).and_return(false)
2018-11-18 11:00:15 +05:30
end
context 'user can read project' do
it 'is shown' do
allow(view).to receive(:can?).with(user, :read_project, project).and_return(true)
render
expect(rendered).to have_content("Project ID: #{project.id}")
end
end
context 'user cannot read project' do
it 'is not shown' do
allow(view).to receive(:can?).with(user, :read_project, project).and_return(false)
render
expect(rendered).not_to have_content("Project ID: #{project.id}")
end
end
end
2017-08-17 22:00:37 +05:30
end