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
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/blob_edit/blob_bundle_spec.js (renamed from spec/javascripts/blob_edit/blob_bundle_spec.js)3
-rw-r--r--spec/frontend/vue_shared/components/issue/related_issuable_mock_data.js121
-rw-r--r--spec/javascripts/vue_shared/components/issue/related_issuable_mock_data.js117
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb20
-rw-r--r--spec/models/group_spec.rb10
-rw-r--r--spec/models/project_spec.rb13
-rw-r--r--spec/models/snippet_spec.rb22
7 files changed, 189 insertions, 117 deletions
diff --git a/spec/javascripts/blob_edit/blob_bundle_spec.js b/spec/frontend/blob_edit/blob_bundle_spec.js
index 06c6a603155..be438781850 100644
--- a/spec/javascripts/blob_edit/blob_bundle_spec.js
+++ b/spec/frontend/blob_edit/blob_bundle_spec.js
@@ -1,9 +1,10 @@
import $ from 'jquery';
import blobBundle from '~/blob_edit/blob_bundle';
+jest.mock('~/blob_edit/edit_blob');
+
describe('BlobBundle', () => {
beforeEach(() => {
- spyOnDependency(blobBundle, 'EditBlob').and.stub();
setFixtures(`
<div class="js-edit-blob-form" data-blob-filename="blah">
<button class="js-commit-button"></button>
diff --git a/spec/frontend/vue_shared/components/issue/related_issuable_mock_data.js b/spec/frontend/vue_shared/components/issue/related_issuable_mock_data.js
new file mode 100644
index 00000000000..5f69d761fdf
--- /dev/null
+++ b/spec/frontend/vue_shared/components/issue/related_issuable_mock_data.js
@@ -0,0 +1,121 @@
+export const defaultProps = {
+ endpoint: '/foo/bar/issues/1/related_issues',
+ currentNamespacePath: 'foo',
+ currentProjectPath: 'bar',
+};
+
+export const issuable1 = {
+ id: 200,
+ epicIssueId: 1,
+ confidential: false,
+ reference: 'foo/bar#123',
+ displayReference: '#123',
+ title: 'some title',
+ path: '/foo/bar/issues/123',
+ relationPath: '/foo/bar/issues/123/relation',
+ state: 'opened',
+ linkType: 'relates_to',
+ dueDate: '2010-11-22',
+ weight: 5,
+};
+
+export const issuable2 = {
+ id: 201,
+ epicIssueId: 2,
+ confidential: false,
+ reference: 'foo/bar#124',
+ displayReference: '#124',
+ title: 'some other thing',
+ path: '/foo/bar/issues/124',
+ relationPath: '/foo/bar/issues/124/relation',
+ state: 'opened',
+ linkType: 'blocks',
+};
+
+export const issuable3 = {
+ id: 202,
+ epicIssueId: 3,
+ confidential: false,
+ reference: 'foo/bar#125',
+ displayReference: '#125',
+ title: 'some other other thing',
+ path: '/foo/bar/issues/125',
+ relationPath: '/foo/bar/issues/125/relation',
+ state: 'opened',
+ linkType: 'is_blocked_by',
+};
+
+export const issuable4 = {
+ id: 203,
+ epicIssueId: 4,
+ confidential: false,
+ reference: 'foo/bar#126',
+ displayReference: '#126',
+ title: 'some other other other thing',
+ path: '/foo/bar/issues/126',
+ relationPath: '/foo/bar/issues/126/relation',
+ state: 'opened',
+};
+
+export const issuable5 = {
+ id: 204,
+ epicIssueId: 5,
+ confidential: false,
+ reference: 'foo/bar#127',
+ displayReference: '#127',
+ title: 'some other other other thing',
+ path: '/foo/bar/issues/127',
+ relationPath: '/foo/bar/issues/127/relation',
+ state: 'opened',
+};
+
+export const defaultMilestone = {
+ id: 1,
+ state: 'active',
+ title: 'Milestone title',
+ start_date: '2018-01-01',
+ due_date: '2019-12-31',
+};
+
+export const defaultAssignees = [
+ {
+ id: 1,
+ name: 'Administrator',
+ username: 'root',
+ state: 'active',
+ avatar_url: `${gl.TEST_HOST}`,
+ web_url: `${gl.TEST_HOST}/root`,
+ status_tooltip_html: null,
+ path: '/root',
+ },
+ {
+ id: 13,
+ name: 'Brooks Beatty',
+ username: 'brynn_champlin',
+ state: 'active',
+ avatar_url: `${gl.TEST_HOST}`,
+ web_url: `${gl.TEST_HOST}/brynn_champlin`,
+ status_tooltip_html: null,
+ path: '/brynn_champlin',
+ },
+ {
+ id: 6,
+ name: 'Bryce Turcotte',
+ username: 'melynda',
+ state: 'active',
+ avatar_url: `${gl.TEST_HOST}`,
+ web_url: `${gl.TEST_HOST}/melynda`,
+ status_tooltip_html: null,
+ path: '/melynda',
+ },
+ {
+ id: 20,
+ name: 'Conchita Eichmann',
+ username: 'juliana_gulgowski',
+ state: 'active',
+ avatar_url: `${gl.TEST_HOST}`,
+ web_url: `${gl.TEST_HOST}/juliana_gulgowski`,
+ status_tooltip_html: null,
+ path: '/juliana_gulgowski',
+ },
+];
diff --git a/spec/javascripts/vue_shared/components/issue/related_issuable_mock_data.js b/spec/javascripts/vue_shared/components/issue/related_issuable_mock_data.js
index d3dc169ddab..3c42f0c2aa9 100644
--- a/spec/javascripts/vue_shared/components/issue/related_issuable_mock_data.js
+++ b/spec/javascripts/vue_shared/components/issue/related_issuable_mock_data.js
@@ -1,116 +1 @@
-export const defaultProps = {
- endpoint: '/foo/bar/issues/1/related_issues',
- currentNamespacePath: 'foo',
- currentProjectPath: 'bar',
-};
-
-export const issuable1 = {
- id: 200,
- epicIssueId: 1,
- confidential: false,
- reference: 'foo/bar#123',
- displayReference: '#123',
- title: 'some title',
- path: '/foo/bar/issues/123',
- state: 'opened',
- linkType: 'relates_to',
- dueDate: '2010-11-22',
- weight: 5,
-};
-
-export const issuable2 = {
- id: 201,
- epicIssueId: 2,
- confidential: false,
- reference: 'foo/bar#124',
- displayReference: '#124',
- title: 'some other thing',
- path: '/foo/bar/issues/124',
- state: 'opened',
- linkType: 'blocks',
-};
-
-export const issuable3 = {
- id: 202,
- epicIssueId: 3,
- confidential: false,
- reference: 'foo/bar#125',
- displayReference: '#125',
- title: 'some other other thing',
- path: '/foo/bar/issues/125',
- state: 'opened',
- linkType: 'is_blocked_by',
-};
-
-export const issuable4 = {
- id: 203,
- epicIssueId: 4,
- confidential: false,
- reference: 'foo/bar#126',
- displayReference: '#126',
- title: 'some other other other thing',
- path: '/foo/bar/issues/126',
- state: 'opened',
-};
-
-export const issuable5 = {
- id: 204,
- epicIssueId: 5,
- confidential: false,
- reference: 'foo/bar#127',
- displayReference: '#127',
- title: 'some other other other thing',
- path: '/foo/bar/issues/127',
- state: 'opened',
-};
-
-export const defaultMilestone = {
- id: 1,
- state: 'active',
- title: 'Milestone title',
- start_date: '2018-01-01',
- due_date: '2019-12-31',
-};
-
-export const defaultAssignees = [
- {
- id: 1,
- name: 'Administrator',
- username: 'root',
- state: 'active',
- avatar_url: `${gl.TEST_HOST}`,
- web_url: `${gl.TEST_HOST}/root`,
- status_tooltip_html: null,
- path: '/root',
- },
- {
- id: 13,
- name: 'Brooks Beatty',
- username: 'brynn_champlin',
- state: 'active',
- avatar_url: `${gl.TEST_HOST}`,
- web_url: `${gl.TEST_HOST}/brynn_champlin`,
- status_tooltip_html: null,
- path: '/brynn_champlin',
- },
- {
- id: 6,
- name: 'Bryce Turcotte',
- username: 'melynda',
- state: 'active',
- avatar_url: `${gl.TEST_HOST}`,
- web_url: `${gl.TEST_HOST}/melynda`,
- status_tooltip_html: null,
- path: '/melynda',
- },
- {
- id: 20,
- name: 'Conchita Eichmann',
- username: 'juliana_gulgowski',
- state: 'active',
- avatar_url: `${gl.TEST_HOST}`,
- web_url: `${gl.TEST_HOST}/juliana_gulgowski`,
- status_tooltip_html: null,
- path: '/juliana_gulgowski',
- },
-];
+export * from '../../../../frontend/vue_shared/components/issue/related_issuable_mock_data';
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index 06d12c14793..697a9e98505 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -230,6 +230,26 @@ describe CacheMarkdownField, :clean_gitlab_redis_cache do
end
end
end
+
+ describe '#rendered_field_content' do
+ let(:thing) { klass.new(description: markdown, description_html: nil, cached_markdown_version: cache_version) }
+
+ context 'when a field can be cached' do
+ it 'returns the html' do
+ thing.description = updated_markdown
+
+ expect(thing.rendered_field_content(:description)).to eq updated_html
+ end
+ end
+
+ context 'when a field cannot be cached' do
+ it 'returns nil' do
+ allow(thing).to receive(:can_cache_field?).with(:description).and_return false
+
+ expect(thing.rendered_field_content(:description)).to eq nil
+ end
+ end
+ end
end
context 'for Active record classes' do
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 3531c695236..b5ed29189fd 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -911,6 +911,16 @@ describe Group do
subject { group.ci_variables_for('ref', project) }
+ it 'memoizes the result by ref', :request_store do
+ expect(project).to receive(:protected_for?).with('ref').once.and_return(true)
+ expect(project).to receive(:protected_for?).with('other').once.and_return(false)
+
+ 2.times do
+ expect(group.ci_variables_for('ref', project)).to contain_exactly(ci_variable, protected_variable)
+ expect(group.ci_variables_for('other', project)).to contain_exactly(ci_variable)
+ end
+ end
+
shared_examples 'ref is protected' do
it 'contains all the variables' do
is_expected.to contain_exactly(ci_variable, protected_variable)
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index e7deae38b46..2b4a832634f 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2930,6 +2930,19 @@ describe Project do
end
end
+ it 'memoizes the result by ref and environment', :request_store do
+ scoped_variable = create(:ci_variable, value: 'secret', project: project, environment_scope: 'scoped')
+
+ expect(project).to receive(:protected_for?).with('ref').once.and_return(true)
+ expect(project).to receive(:protected_for?).with('other').twice.and_return(false)
+
+ 2.times do
+ expect(project.reload.ci_variables_for(ref: 'ref', environment: 'production')).to contain_exactly(ci_variable, protected_variable)
+ expect(project.reload.ci_variables_for(ref: 'other')).to contain_exactly(ci_variable)
+ expect(project.reload.ci_variables_for(ref: 'other', environment: 'scoped')).to contain_exactly(ci_variable, scoped_variable)
+ end
+ end
+
context 'when the ref is not protected' do
before do
allow(project).to receive(:protected_for?).with('ref').and_return(false)
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 1265b95736d..cb7b9961880 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -632,4 +632,26 @@ describe Snippet do
end
end
end
+
+ describe '#can_cache_field?' do
+ using RSpec::Parameterized::TableSyntax
+
+ let(:snippet) { create(:snippet, file_name: file_name) }
+
+ subject { snippet.can_cache_field?(field) }
+
+ where(:field, :file_name, :result) do
+ :title | nil | true
+ :title | 'foo.bar' | true
+ :description | nil | true
+ :description | 'foo.bar' | true
+ :content | nil | false
+ :content | 'bar.foo' | false
+ :content | 'markdown.md' | true
+ end
+
+ with_them do
+ it { is_expected.to eq result }
+ end
+ end
end