Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/presenters
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/gitlab/blame_presenter_spec.rb45
-rw-r--r--spec/presenters/projects/prometheus/alert_presenter_spec.rb35
-rw-r--r--spec/presenters/snippet_presenter_spec.rb21
3 files changed, 87 insertions, 14 deletions
diff --git a/spec/presenters/gitlab/blame_presenter_spec.rb b/spec/presenters/gitlab/blame_presenter_spec.rb
new file mode 100644
index 00000000000..d2a173b557c
--- /dev/null
+++ b/spec/presenters/gitlab/blame_presenter_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BlamePresenter do
+ let(:project) { create(:project, :repository) }
+ let(:path) { 'files/ruby/popen.rb' }
+ let(:commit) { project.commit('master') }
+ let(:blob) { project.repository.blob_at(commit.id, path) }
+ let(:blame) { Gitlab::Blame.new(blob, commit) }
+
+ subject { described_class.new(blame, project: project, path: path) }
+
+ it 'precalculates necessary data on init' do
+ expect_any_instance_of(described_class)
+ .to receive(:precalculate_data_by_commit!)
+ .and_call_original
+
+ subject
+ end
+
+ describe '#groups' do
+ it 'delegates #groups call to the blame' do
+ expect(blame).to receive(:groups).and_call_original
+
+ subject.groups
+ end
+ end
+
+ describe '#commit_data' do
+ it 'has the data necessary to render the view' do
+ commit = blame.groups.first[:commit]
+ data = subject.commit_data(commit)
+
+ aggregate_failures do
+ expect(data.author_avatar.to_s).to include('src="https://www.gravatar.com/')
+ 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
+ end
+end
diff --git a/spec/presenters/projects/prometheus/alert_presenter_spec.rb b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
index 967a0fb2c09..8ee5a4d7b3f 100644
--- a/spec/presenters/projects/prometheus/alert_presenter_spec.rb
+++ b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
@@ -24,18 +24,25 @@ describe Projects::Prometheus::AlertPresenter do
it { is_expected.to eq(project.full_path) }
end
- describe '#starts_at' do
- subject { presenter.starts_at }
+ describe '#start_time' do
+ subject { presenter.start_time }
+
+ let(:starts_at) { '2020-10-31T14:02:04Z' }
before do
payload['startsAt'] = starts_at
end
- context 'with valid datetime' do
- let(:datetime) { Time.now }
- let(:starts_at) { datetime.rfc3339 }
+ context 'with valid utc datetime' do
+ it { is_expected.to eq('31 October 2020, 2:02PM (UTC)') }
- it { is_expected.to eq(datetime.rfc3339) }
+ context 'with admin time zone not UTC' do
+ before do
+ allow(Time).to receive(:zone).and_return(ActiveSupport::TimeZone.new('Perth'))
+ end
+
+ it { is_expected.to eq('31 October 2020, 2:02PM (UTC)') }
+ end
end
context 'with invalid datetime' do
@@ -56,7 +63,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}
+ **Start time:** #{presenter.start_time}
MARKDOWN
)
@@ -73,7 +80,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}
+ **Start time:** #{presenter.start_time}
#### Alert Details
@@ -94,7 +101,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `query`
MARKDOWN
@@ -122,7 +129,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
**Service:** service_name#{markdown_line_break}
**Monitoring tool:** monitoring_tool_name#{markdown_line_break}
**Hosts:** http://localhost:3000 http://localhost:3001
@@ -144,7 +151,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
**Hosts:** http://localhost:3000
MARKDOWN
@@ -161,7 +168,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0`
[](#{url})
@@ -253,7 +260,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0`
MARKDOWN
@@ -280,7 +287,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
- **Start time:** #{presenter.starts_at}
+ **Start time:** #{presenter.start_time}
MARKDOWN
end
diff --git a/spec/presenters/snippet_presenter_spec.rb b/spec/presenters/snippet_presenter_spec.rb
index 591d86652b6..423e9edc219 100644
--- a/spec/presenters/snippet_presenter_spec.rb
+++ b/spec/presenters/snippet_presenter_spec.rb
@@ -163,4 +163,25 @@ describe SnippetPresenter do
end
end
end
+
+ describe '#blobs' do
+ let(:snippet) { personal_snippet }
+
+ subject { presenter.blobs }
+
+ context 'when snippet does not have a repository' do
+ it 'returns an array with one SnippetBlob' do
+ expect(subject.size).to eq(1)
+ expect(subject.first).to eq(snippet.blob)
+ end
+ end
+
+ context 'when snippet has a repository' do
+ let(:snippet) { create(:snippet, :repository, author: user) }
+
+ it 'returns an array with all repository blobs' do
+ expect(subject).to match_array(snippet.blobs)
+ end
+ end
+ end
end