summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/ci/bridge_presenter_spec.rb9
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb60
-rw-r--r--spec/presenters/gitlab/blame_presenter_spec.rb29
-rw-r--r--spec/presenters/issue_presenter_spec.rb61
-rw-r--r--spec/presenters/project_clusterable_presenter_spec.rb6
-rw-r--r--spec/presenters/projects/security/configuration_presenter_spec.rb1
6 files changed, 153 insertions, 13 deletions
diff --git a/spec/presenters/ci/bridge_presenter_spec.rb b/spec/presenters/ci/bridge_presenter_spec.rb
index 6291c3426e2..bd6c4777d0c 100644
--- a/spec/presenters/ci/bridge_presenter_spec.rb
+++ b/spec/presenters/ci/bridge_presenter_spec.rb
@@ -3,9 +3,10 @@
require 'spec_helper'
RSpec.describe Ci::BridgePresenter do
+ let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
- let_it_be(:bridge) { create(:ci_bridge, pipeline: pipeline, status: :failed) }
+ let_it_be(:bridge) { create(:ci_bridge, pipeline: pipeline, status: :failed, user: user) }
subject(:presenter) do
described_class.new(bridge)
@@ -14,4 +15,10 @@ RSpec.describe Ci::BridgePresenter do
it 'presents information about recoverable state' do
expect(presenter).to be_recoverable
end
+
+ it 'presents the detailed status for the user' do
+ expect(bridge).to receive(:detailed_status).with(user)
+
+ presenter.detailed_status
+ end
end
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index d25102532a7..ace65307321 100644
--- a/spec/presenters/ci/build_runner_presenter_spec.rb
+++ b/spec/presenters/ci/build_runner_presenter_spec.rb
@@ -78,16 +78,72 @@ RSpec.describe Ci::BuildRunnerPresenter do
artifact_format: Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(file_type),
paths: [filename],
when: 'always'
- }
+ }.compact
end
it 'presents correct hash' do
- expect(presenter.artifacts.first).to include(report_expectation)
+ expect(presenter.artifacts).to contain_exactly(report_expectation)
end
end
end
end
+ context 'when a specific coverage_report type is given' do
+ let(:coverage_format) { :cobertura }
+ let(:filename) { 'cobertura-coverage.xml' }
+ let(:coverage_report) { { path: filename, coverage_format: coverage_format } }
+ let(:report) { { coverage_report: coverage_report } }
+ let(:build) { create(:ci_build, options: { artifacts: { reports: report } }) }
+
+ let(:expected_coverage_report) do
+ {
+ name: filename,
+ artifact_type: coverage_format,
+ artifact_format: Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(coverage_format),
+ paths: [filename],
+ when: 'always'
+ }
+ end
+
+ it 'presents the coverage report hash with the coverage format' do
+ expect(presenter.artifacts).to contain_exactly(expected_coverage_report)
+ end
+ end
+
+ context 'when a specific coverage_report type is given with another report type' do
+ let(:coverage_format) { :cobertura }
+ let(:coverage_filename) { 'cobertura-coverage.xml' }
+ let(:coverage_report) { { path: coverage_filename, coverage_format: coverage_format } }
+ let(:ds_filename) { 'gl-dependency-scanning-report.json' }
+
+ let(:report) { { coverage_report: coverage_report, dependency_scanning: [ds_filename] } }
+ let(:build) { create(:ci_build, options: { artifacts: { reports: report } }) }
+
+ let(:expected_coverage_report) do
+ {
+ name: coverage_filename,
+ artifact_type: coverage_format,
+ artifact_format: Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(coverage_format),
+ paths: [coverage_filename],
+ when: 'always'
+ }
+ end
+
+ let(:expected_ds_report) do
+ {
+ name: ds_filename,
+ artifact_type: :dependency_scanning,
+ artifact_format: Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(:dependency_scanning),
+ paths: [ds_filename],
+ when: 'always'
+ }
+ end
+
+ it 'presents both reports' do
+ expect(presenter.artifacts).to contain_exactly(expected_coverage_report, expected_ds_report)
+ end
+ end
+
context "when option has both archive and reports specification" do
let(:report) { { junit: ['junit.xml'] } }
let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } }) }
diff --git a/spec/presenters/gitlab/blame_presenter_spec.rb b/spec/presenters/gitlab/blame_presenter_spec.rb
index b163926154b..ff128416692 100644
--- a/spec/presenters/gitlab/blame_presenter_spec.rb
+++ b/spec/presenters/gitlab/blame_presenter_spec.rb
@@ -27,6 +27,14 @@ RSpec.describe Gitlab::BlamePresenter do
end
end
+ describe '#first_line' do
+ it 'delegates #first_line call to the blame' do
+ expect(blame).to receive(:first_line).at_least(:once).and_call_original
+
+ subject.first_line
+ end
+ end
+
describe '#commit_data' do
it 'has the data necessary to render the view' do
commit = blame.groups.first[:commit]
@@ -37,9 +45,28 @@ RSpec.describe Gitlab::BlamePresenter do
expect(data.age_map_class).to include('blame-commit-age-')
expect(data.commit_link.to_s).to include '913c66a37b4a45b9769037c55c2d238bd0942d2e">Files, encoding and much more</a>'
expect(data.commit_author_link.to_s).to include('<a class="commit-author-link" href=')
- expect(data.project_blame_link.to_s).to include('<a title="View blame prior to this change"')
expect(data.time_ago_tooltip.to_s).to include('data-container="body">Feb 27, 2014</time>')
end
end
+
+ context 'renamed file' do
+ let(:path) { 'files/plain_text/renamed' }
+ let(:commit) { project.commit('blame-on-renamed') }
+
+ it 'does not generate link to previous blame on initial commit' do
+ commit = blame.groups[0][:commit]
+ data = subject.commit_data(commit)
+
+ expect(data.project_blame_link.to_s).to eq('')
+ end
+
+ it 'generates link link to previous blame' do
+ commit = blame.groups[1][:commit]
+ data = subject.commit_data(commit)
+
+ expect(data.project_blame_link.to_s).to include('<a title="View blame prior to this change"')
+ expect(data.project_blame_link.to_s).to include('/blame/405a45736a75e439bb059e638afaa9a3c2eeda79/files/plain_text/initial-commit')
+ end
+ end
end
end
diff --git a/spec/presenters/issue_presenter_spec.rb b/spec/presenters/issue_presenter_spec.rb
index 55a6b50ffa7..e17ae218cd3 100644
--- a/spec/presenters/issue_presenter_spec.rb
+++ b/spec/presenters/issue_presenter_spec.rb
@@ -5,19 +5,42 @@ require 'spec_helper'
RSpec.describe IssuePresenter do
include Gitlab::Routing.url_helpers
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:project) { create(:project, group: group) }
- let(:issue) { create(:issue, project: project) }
- let(:presenter) { described_class.new(issue, current_user: user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:task) { create(:issue, :task, project: project) }
- before do
+ let(:presented_issue) { issue }
+ let(:presenter) { described_class.new(presented_issue, current_user: user) }
+
+ before_all do
group.add_developer(user)
end
describe '#web_url' do
it 'returns correct path' do
- expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{issue.iid}")
+ expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
+ end
+
+ context 'when issue type is task' do
+ let(:presented_issue) { task }
+
+ context 'when work_items feature flag is enabled' do
+ it 'returns a work item url for the task' do
+ expect(presenter.web_url).to eq(project_work_items_url(project, work_items_path: presented_issue.id))
+ end
+ end
+
+ context 'when work_items feature flag is disabled' do
+ before do
+ stub_feature_flags(work_items: false)
+ end
+
+ it 'returns an issue url for the task' do
+ expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
+ end
+ end
end
end
@@ -29,7 +52,7 @@ RSpec.describe IssuePresenter do
end
it 'returns subscribed' do
- create(:subscription, user: user, project: project, subscribable: issue, subscribed: true)
+ create(:subscription, user: user, project: project, subscribable: presented_issue, subscribed: true)
is_expected.to be(true)
end
@@ -37,7 +60,27 @@ RSpec.describe IssuePresenter do
describe '#issue_path' do
it 'returns correct path' do
- expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{issue.iid}")
+ expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
+ end
+
+ context 'when issue type is task' do
+ let(:presented_issue) { task }
+
+ context 'when work_items feature flag is enabled' do
+ it 'returns a work item path for the task' do
+ expect(presenter.issue_path).to eq(project_work_items_path(project, work_items_path: presented_issue.id))
+ end
+ end
+
+ context 'when work_items feature flag is disabled' do
+ before do
+ stub_feature_flags(work_items: false)
+ end
+
+ it 'returns an issue path for the task' do
+ expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
+ end
+ end
end
end
diff --git a/spec/presenters/project_clusterable_presenter_spec.rb b/spec/presenters/project_clusterable_presenter_spec.rb
index 900630bb6e2..bd4319c9411 100644
--- a/spec/presenters/project_clusterable_presenter_spec.rb
+++ b/spec/presenters/project_clusterable_presenter_spec.rb
@@ -49,6 +49,12 @@ RSpec.describe ProjectClusterablePresenter do
it { is_expected.to eq(connect_project_clusters_path(project)) }
end
+ describe '#new_cluster_docs_path' do
+ subject { presenter.new_cluster_docs_path }
+
+ it { is_expected.to eq(new_cluster_docs_project_clusters_path(project)) }
+ end
+
describe '#authorize_aws_role_path' do
subject { presenter.authorize_aws_role_path }
diff --git a/spec/presenters/projects/security/configuration_presenter_spec.rb b/spec/presenters/projects/security/configuration_presenter_spec.rb
index 47ef0cf1192..779d6b88fd5 100644
--- a/spec/presenters/projects/security/configuration_presenter_spec.rb
+++ b/spec/presenters/projects/security/configuration_presenter_spec.rb
@@ -87,6 +87,7 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
expect(feature['configuration_path']).to be_nil
expect(feature['available']).to eq(true)
expect(feature['can_enable_by_merge_request']).to eq(true)
+ expect(feature['meta_info_path']).to be_nil
end
context 'when checking features configured status' do