summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 21:07:56 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 21:07:56 +0000
commit0e68afab211a172b862a7acc774e1eda5da8e471 (patch)
tree1eba04a16582c9183d4f479f82dd8709ae40d72f /spec
parent33aa02e7a38d8dfc5e470dd5d776c8d4ce5b2dd5 (diff)
downloadgitlab-ce-0e68afab211a172b862a7acc774e1eda5da8e471.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/projects/releases/user_views_releases_spec.rb114
-rw-r--r--spec/frontend/monitoring/components/dashboard_spec.js16
-rw-r--r--spec/frontend/monitoring/components/embeds/metric_embed_spec.js3
-rw-r--r--spec/frontend/monitoring/store/actions_spec.js10
-rw-r--r--spec/frontend/monitoring/store/mutations_spec.js52
-rw-r--r--spec/frontend/releases/components/release_block_spec.js8
-rw-r--r--spec/models/member_spec.rb4
-rw-r--r--spec/models/wiki_page_spec.rb2
-rw-r--r--spec/workers/reactive_caching_worker_spec.rb8
9 files changed, 157 insertions, 60 deletions
diff --git a/spec/features/projects/releases/user_views_releases_spec.rb b/spec/features/projects/releases/user_views_releases_spec.rb
index a4ba81ffeb9..e21d8ec16e1 100644
--- a/spec/features/projects/releases/user_views_releases_spec.rb
+++ b/spec/features/projects/releases/user_views_releases_spec.rb
@@ -3,41 +3,33 @@
require 'spec_helper'
describe 'User views releases', :js do
- let!(:project) { create(:project, :repository) }
- let!(:release) { create(:release, project: project ) }
- let!(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository, :private) }
+ let_it_be(:release) { create(:release, project: project, name: 'The first release' ) }
+ let_it_be(:maintainer) { create(:user) }
+ let_it_be(:guest) { create(:user) }
before do
- project.add_maintainer(user)
-
- gitlab_sign_in(user)
+ project.add_maintainer(maintainer)
+ project.add_guest(guest)
end
- it 'sees the release' do
- visit project_releases_path(project)
-
- expect(page).to have_content(release.name)
- expect(page).to have_content(release.tag)
- expect(page).not_to have_content('Upcoming Release')
- end
-
- context 'when there is a link as an asset' do
- let!(:release_link) { create(:release_link, release: release, url: url ) }
- let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
- let(:direct_asset_link) { Gitlab::Routing.url_helpers.project_release_url(project, release) << release_link.filepath }
+ context('when the user is a maintainer') do
+ before do
+ gitlab_sign_in(maintainer)
+ end
- it 'sees the link' do
+ it 'sees the release' do
visit project_releases_path(project)
- page.within('.js-assets-list') do
- expect(page).to have_link release_link.name, href: direct_asset_link
- expect(page).not_to have_content('(external source)')
- end
+ expect(page).to have_content(release.name)
+ expect(page).to have_content(release.tag)
+ expect(page).not_to have_content('Upcoming Release')
end
- context 'when there is a link redirect' do
- let!(:release_link) { create(:release_link, release: release, name: 'linux-amd64 binaries', filepath: '/binaries/linux-amd64', url: url) }
+ context 'when there is a link as an asset' do
+ let!(:release_link) { create(:release_link, release: release, url: url ) }
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
+ let(:direct_asset_link) { Gitlab::Routing.url_helpers.project_release_url(project, release) << release_link.filepath }
it 'sees the link' do
visit project_releases_path(project)
@@ -47,39 +39,73 @@ describe 'User views releases', :js do
expect(page).not_to have_content('(external source)')
end
end
- end
- context 'when url points to external resource' do
- let(:url) { 'http://google.com/download' }
+ context 'when there is a link redirect' do
+ let!(:release_link) { create(:release_link, release: release, name: 'linux-amd64 binaries', filepath: '/binaries/linux-amd64', url: url) }
+ let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
- it 'sees that the link is external resource' do
- visit project_releases_path(project)
+ it 'sees the link' do
+ visit project_releases_path(project)
- page.within('.js-assets-list') do
- expect(page).to have_content('(external source)')
+ page.within('.js-assets-list') do
+ expect(page).to have_link release_link.name, href: direct_asset_link
+ expect(page).not_to have_content('(external source)')
+ end
+ end
+ end
+
+ context 'when url points to external resource' do
+ let(:url) { 'http://google.com/download' }
+
+ it 'sees that the link is external resource' do
+ visit project_releases_path(project)
+
+ page.within('.js-assets-list') do
+ expect(page).to have_content('(external source)')
+ end
end
end
end
- end
- context 'with an upcoming release' do
- let(:tomorrow) { Time.zone.now + 1.day }
- let!(:release) { create(:release, project: project, released_at: tomorrow ) }
+ context 'with an upcoming release' do
+ let(:tomorrow) { Time.zone.now + 1.day }
+ let!(:release) { create(:release, project: project, released_at: tomorrow ) }
- it 'sees the upcoming tag' do
- visit project_releases_path(project)
+ it 'sees the upcoming tag' do
+ visit project_releases_path(project)
+
+ expect(page).to have_content('Upcoming Release')
+ end
+ end
+
+ context 'with a tag containing a slash' do
+ it 'sees the release' do
+ release = create :release, :with_evidence, project: project, tag: 'debian/2.4.0-1'
+ visit project_releases_path(project)
- expect(page).to have_content('Upcoming Release')
+ expect(page).to have_content(release.name)
+ expect(page).to have_content(release.tag)
+ end
end
end
- context 'with a tag containing a slash' do
- it 'sees the release' do
- release = create :release, :with_evidence, project: project, tag: 'debian/2.4.0-1'
+ context('when the user is a guest') do
+ before do
+ gitlab_sign_in(guest)
+ end
+
+ it 'renders release info except for Git-related data' do
visit project_releases_path(project)
- expect(page).to have_content(release.name)
- expect(page).to have_content(release.tag)
+ within('.release-block') do
+ expect(page).to have_content(release.description)
+
+ # The following properties (sometimes) include Git info,
+ # so they are not rendered for Guest users
+ expect(page).not_to have_content(release.name)
+ expect(page).not_to have_content(release.tag)
+ expect(page).not_to have_content(release.commit.short_id)
+ end
end
end
end
diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js
index b9d838085a1..ec25c9e169a 100644
--- a/spec/frontend/monitoring/components/dashboard_spec.js
+++ b/spec/frontend/monitoring/components/dashboard_spec.js
@@ -88,11 +88,17 @@ describe('Dashboard', () => {
expect(findEnvironmentsDropdown().exists()).toBe(true);
});
- it('sets endpoints: logs path', () => {
- expect(store.dispatch).toHaveBeenCalledWith(
- 'monitoringDashboard/setEndpoints',
- expect.objectContaining({ logsPath: propsData.logsPath }),
- );
+ it('sets initial state', () => {
+ expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setInitialState', {
+ currentDashboard: '',
+ currentEnvironmentName: 'production',
+ dashboardEndpoint: 'https://invalid',
+ dashboardsEndpoint: 'https://invalid',
+ deploymentsEndpoint: null,
+ logsPath: '/path/to/logs',
+ metricsEndpoint: 'http://test.host/monitoring/mock',
+ projectPath: '/path/to/project',
+ });
});
});
diff --git a/spec/frontend/monitoring/components/embeds/metric_embed_spec.js b/spec/frontend/monitoring/components/embeds/metric_embed_spec.js
index d0fe22cefec..b829cd53479 100644
--- a/spec/frontend/monitoring/components/embeds/metric_embed_spec.js
+++ b/spec/frontend/monitoring/components/embeds/metric_embed_spec.js
@@ -26,9 +26,8 @@ describe('MetricEmbed', () => {
beforeEach(() => {
actions = {
- setFeatureFlags: jest.fn(),
+ setInitialState: jest.fn(),
setShowErrorBanner: jest.fn(),
- setEndpoints: jest.fn(),
setTimeRange: jest.fn(),
fetchDashboard: jest.fn(),
};
diff --git a/spec/frontend/monitoring/store/actions_spec.js b/spec/frontend/monitoring/store/actions_spec.js
index 203bc6f4e0e..e9f9aa0ba18 100644
--- a/spec/frontend/monitoring/store/actions_spec.js
+++ b/spec/frontend/monitoring/store/actions_spec.js
@@ -16,7 +16,7 @@ import {
fetchEnvironmentsData,
fetchPrometheusMetrics,
fetchPrometheusMetric,
- setEndpoints,
+ setInitialState,
filterEnvironments,
setGettingStartedEmptyState,
duplicateSystemDashboard,
@@ -208,14 +208,14 @@ describe('Monitoring store actions', () => {
});
});
- describe('Set endpoints', () => {
+ describe('Set initial state', () => {
let mockedState;
beforeEach(() => {
mockedState = storeState();
});
- it('should commit SET_ENDPOINTS mutation', done => {
+ it('should commit SET_INITIAL_STATE mutation', done => {
testAction(
- setEndpoints,
+ setInitialState,
{
metricsEndpoint: 'additional_metrics.json',
deploymentsEndpoint: 'deployments.json',
@@ -223,7 +223,7 @@ describe('Monitoring store actions', () => {
mockedState,
[
{
- type: types.SET_ENDPOINTS,
+ type: types.SET_INITIAL_STATE,
payload: {
metricsEndpoint: 'additional_metrics.json',
deploymentsEndpoint: 'deployments.json',
diff --git a/spec/frontend/monitoring/store/mutations_spec.js b/spec/frontend/monitoring/store/mutations_spec.js
index 5a79b8ef49c..0310c7e9510 100644
--- a/spec/frontend/monitoring/store/mutations_spec.js
+++ b/spec/frontend/monitoring/store/mutations_spec.js
@@ -86,6 +86,58 @@ describe('Monitoring mutations', () => {
expect(typeof stateCopy.deploymentData[0]).toEqual('object');
});
});
+
+ describe('SET_INITIAL_STATE', () => {
+ it('should set all the endpoints', () => {
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ metricsEndpoint: 'additional_metrics.json',
+ deploymentsEndpoint: 'deployments.json',
+ dashboardEndpoint: 'dashboard.json',
+ projectPath: '/gitlab-org/gitlab-foss',
+ currentEnvironmentName: 'production',
+ });
+ expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json');
+ expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json');
+ expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json');
+ expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss');
+ expect(stateCopy.currentEnvironmentName).toEqual('production');
+ });
+
+ it('should not remove previously set properties', () => {
+ const defaultLogsPath = stateCopy.logsPath;
+
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ logsPath: defaultLogsPath,
+ });
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ dashboardEndpoint: 'dashboard.json',
+ });
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ projectPath: '/gitlab-org/gitlab-foss',
+ });
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ currentEnvironmentName: 'canary',
+ });
+
+ expect(stateCopy).toMatchObject({
+ logsPath: defaultLogsPath,
+ dashboardEndpoint: 'dashboard.json',
+ projectPath: '/gitlab-org/gitlab-foss',
+ currentEnvironmentName: 'canary',
+ });
+ });
+
+ it('should not update unknown properties', () => {
+ mutations[types.SET_INITIAL_STATE](stateCopy, {
+ dashboardEndpoint: 'dashboard.json',
+ someOtherProperty: 'some invalid value', // someOtherProperty is not allowed
+ });
+
+ expect(stateCopy.dashboardEndpoint).toBe('dashboard.json');
+ expect(stateCopy.someOtherProperty).toBeUndefined();
+ });
+ });
+
describe('SET_ENDPOINTS', () => {
it('should set all the endpoints', () => {
mutations[types.SET_ENDPOINTS](stateCopy, {
diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js
index 7ea2379ea35..9846fcb65eb 100644
--- a/spec/frontend/releases/components/release_block_spec.js
+++ b/spec/frontend/releases/components/release_block_spec.js
@@ -165,6 +165,14 @@ describe('Release block', () => {
});
});
+ it('does not set the ID if tagName is missing', () => {
+ release.tagName = undefined;
+
+ return factory(release).then(() => {
+ expect(wrapper.attributes().id).toBeUndefined();
+ });
+ });
+
describe('evidence block', () => {
it('renders the evidence block when the evidence is available and the feature flag is true', () =>
factory(release, { releaseEvidenceCollection: true }).then(() =>
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb
index cd9d7c16f88..e922542a984 100644
--- a/spec/models/member_spec.rb
+++ b/spec/models/member_spec.rb
@@ -38,10 +38,6 @@ describe Member do
expect(member).not_to be_valid
end
-
- it "is valid otherwise" do
- expect(member).to be_valid
- end
end
context "when an invite email is not provided" do
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index e8e80a8c7f4..0a0611bdeb8 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -577,6 +577,8 @@ describe WikiPage do
end
it 'returns false when version is nil' do
+ expect(latest_page).to receive(:version) { nil }
+
expect(latest_page.historical?).to be_falsy
end
diff --git a/spec/workers/reactive_caching_worker_spec.rb b/spec/workers/reactive_caching_worker_spec.rb
index c39a97b4eee..603ce6160ce 100644
--- a/spec/workers/reactive_caching_worker_spec.rb
+++ b/spec/workers/reactive_caching_worker_spec.rb
@@ -37,5 +37,13 @@ describe ReactiveCachingWorker do
expect(scheduled_job).to include('meta.related_class' => 'Environment')
end
+
+ it 'sets the related class on the job when it was passed as a class' do
+ described_class.perform_async(Project, 1, 'other', 'argument')
+
+ scheduled_job = described_class.jobs.first
+
+ expect(scheduled_job).to include('meta.related_class' => 'Project')
+ end
end
end