diff options
Diffstat (limited to 'spec/helpers/projects/incidents_helper_spec.rb')
-rw-r--r-- | spec/helpers/projects/incidents_helper_spec.rb | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/spec/helpers/projects/incidents_helper_spec.rb b/spec/helpers/projects/incidents_helper_spec.rb index 7a8a6d5222f..d0dc18d56b0 100644 --- a/spec/helpers/projects/incidents_helper_spec.rb +++ b/spec/helpers/projects/incidents_helper_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Projects::IncidentsHelper do include Gitlab::Routing.url_helpers - let(:project) { create(:project) } + let(:user) { build_stubbed(:user) } + let(:project) { build_stubbed(:project) } let(:project_path) { project.full_path } let(:new_issue_path) { new_project_issue_path(project) } let(:issue_path) { project_issues_path(project) } @@ -17,21 +18,43 @@ RSpec.describe Projects::IncidentsHelper do } end + before do + allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive(:can?) + .with(user, :create_incident, project) + .and_return(can_create_incident) + end + describe '#incidents_data' do subject(:data) { helper.incidents_data(project, params) } - it 'returns frontend configuration' do - expect(data).to include( - 'project-path' => project_path, - 'new-issue-path' => new_issue_path, - 'incident-template-name' => 'incident', - 'incident-type' => 'incident', - 'issue-path' => issue_path, - 'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg'), - 'text-query': 'search text', - 'author-username-query': 'root', - 'assignee-username-query': 'max.power' - ) + shared_examples 'frontend configuration' do + it 'returns frontend configuration' do + expect(data).to include( + 'project-path' => project_path, + 'new-issue-path' => new_issue_path, + 'incident-template-name' => 'incident', + 'incident-type' => 'incident', + 'issue-path' => issue_path, + 'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg'), + 'text-query': 'search text', + 'author-username-query': 'root', + 'assignee-username-query': 'max.power', + 'can-create-incident': can_create_incident.to_s + ) + end + end + + context 'when user can create incidents' do + let(:can_create_incident) { true } + + include_examples 'frontend configuration' + end + + context 'when user cannot create incidents' do + let(:can_create_incident) { false } + + include_examples 'frontend configuration' end end end |