diff options
author | Tuğçe Nur Taş <tas.tugcenur@gmail.com> | 2018-07-18 09:58:21 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-07-18 09:58:21 +0300 |
commit | 742cf277785eb2c0700ce0abf21bc25aee50a2c3 (patch) | |
tree | 6688f8dc61e933852a0abb5d177c5181297e90f5 /spec/views | |
parent | 9bdc9b1ae69a62ad764d8ae59baa43a4a0be1d3a (diff) |
Features/show project id on home panel
Diffstat (limited to 'spec/views')
-rw-r--r-- | spec/views/projects/_home_panel.html.haml_spec.rb | 121 |
1 files changed, 87 insertions, 34 deletions
diff --git a/spec/views/projects/_home_panel.html.haml_spec.rb b/spec/views/projects/_home_panel.html.haml_spec.rb index 15fce65979b..b56940a9613 100644 --- a/spec/views/projects/_home_panel.html.haml_spec.rb +++ b/spec/views/projects/_home_panel.html.haml_spec.rb @@ -1,55 +1,48 @@ require 'spec_helper' describe 'projects/_home_panel' do - let(:group) { create(:group) } - let(:project) { create(:project, :public, namespace: group) } + context 'notifications' do + let(:project) { create(:project) } - let(:notification_settings) do - user&.notification_settings_for(project) - end + before do + assign(:project, project) - before do - assign(:project, project) - assign(:notification_setting, notification_settings) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:can?).with(user, :read_project, project).and_return(false) + end - 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) } - context 'when user is signed in' do - let(:user) { create(:user) } + before do + notification_settings = user.notification_settings_for(project) + assign(:notification_setting, notification_settings) + end - it 'makes it possible to set notification level' do - render + 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') + expect(view).to render_template('shared/notifications/_button') + expect(rendered).to have_selector('.notification-dropdown') + end end - end - - context 'when user is signed out' do - let(:user) { nil } - it 'is not possible to set notification level' do - render + context 'when user is signed out' do + let(:user) { nil } - expect(rendered).not_to have_selector('.notification_dropdown') - end - end - - context 'when project' do - let!(:user) { create(:user) } - let(:badges) { project.badges } + before do + assign(:notification_setting, nil) + end - context 'has no badges' do - it 'should not render any badge' do + it 'is not possible to set notification level' do render - expect(rendered).to have_selector('.project-badges') - expect(rendered).not_to have_selector('.project-badges > a') + expect(rendered).not_to have_selector('.notification_dropdown') end end + end + context 'badges' do shared_examples 'show badges' do it 'should render the all badges' do render @@ -62,7 +55,31 @@ describe 'projects/_home_panel' do end end + 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) + end + + context 'has no badges' do + let(:project) { create(:project) } + + 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 + context 'only has group badges' do + let(:group) { create(:group) } + let(:project) { create(:project, namespace: group) } + before do create(:group_badge, group: project.group) end @@ -71,6 +88,8 @@ describe 'projects/_home_panel' do end context 'only has project badges' do + let(:project) { create(:project) } + before do create(:project_badge, project: project) end @@ -79,6 +98,9 @@ describe 'projects/_home_panel' do end context 'has both group and project badges' do + let(:group) { create(:group) } + let(:project) { create(:project, namespace: group) } + before do create(:project_badge, project: project) create(:group_badge, group: project.group) @@ -87,4 +109,35 @@ describe 'projects/_home_panel' do it_behaves_like 'show badges' end end + + 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) + 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 end |