diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 09:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 09:08:36 +0000 |
commit | 23d237110e6a646dec08e1f5b4696d2d9c51cfef (patch) | |
tree | 3c568514c8e22203f50d38940cbb9865aad5bb02 /spec | |
parent | 274dff4f027da636f62361c811285cbb5d5a7c0c (diff) | |
download | gitlab-ce-23d237110e6a646dec08e1f5b4696d2d9c51cfef.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
21 files changed, 325 insertions, 5 deletions
diff --git a/spec/controllers/admin/clusters_controller_spec.rb b/spec/controllers/admin/clusters_controller_spec.rb index ebae931764d..326d0808092 100644 --- a/spec/controllers/admin/clusters_controller_spec.rb +++ b/spec/controllers/admin/clusters_controller_spec.rb @@ -448,6 +448,33 @@ describe Admin::ClustersController do end end + describe 'DELETE clear cluster cache' do + let(:cluster) { create(:cluster, :instance) } + let!(:kubernetes_namespace) do + create(:cluster_kubernetes_namespace, + cluster: cluster, + project: create(:project) + ) + end + + def go + delete :clear_cache, params: { id: cluster } + end + + it 'deletes the namespaces associated with the cluster' do + expect { go }.to change { Clusters::KubernetesNamespace.count } + + expect(response).to redirect_to(admin_cluster_path(cluster)) + expect(cluster.kubernetes_namespaces).to be_empty + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + end + describe 'GET #cluster_status' do let(:cluster) { create(:cluster, :providing_by_gcp, :instance) } diff --git a/spec/controllers/groups/clusters_controller_spec.rb b/spec/controllers/groups/clusters_controller_spec.rb index d027405703b..d1669c84e3e 100644 --- a/spec/controllers/groups/clusters_controller_spec.rb +++ b/spec/controllers/groups/clusters_controller_spec.rb @@ -516,6 +516,42 @@ describe Groups::ClustersController do end end + describe 'DELETE clear cluster cache' do + let(:cluster) { create(:cluster, :group, groups: [group]) } + let!(:kubernetes_namespace) do + create(:cluster_kubernetes_namespace, + cluster: cluster, + project: create(:project) + ) + end + + def go + delete :clear_cache, + params: { + group_id: group, + id: cluster + } + end + + it 'deletes the namespaces associated with the cluster' do + expect { go }.to change { Clusters::KubernetesNamespace.count } + + expect(response).to redirect_to(group_cluster_path(group, cluster)) + expect(cluster.kubernetes_namespaces).to be_empty + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(group) } + it { expect { go }.to be_allowed_for(:maintainer).of(group) } + it { expect { go }.to be_denied_for(:developer).of(group) } + it { expect { go }.to be_denied_for(:reporter).of(group) } + it { expect { go }.to be_denied_for(:guest).of(group) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + end + describe 'GET cluster_status' do let(:cluster) { create(:cluster, :providing_by_gcp, cluster_type: :group_type, groups: [group]) } diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 5a0512a042e..9c21b472c15 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -517,6 +517,38 @@ describe Projects::ClustersController do end end + describe 'DELETE clear cluster cache' do + let(:cluster) { create(:cluster, :project, projects: [project]) } + let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster) } + + def go + delete :clear_cache, + params: { + namespace_id: project.namespace, + project_id: project, + id: cluster + } + end + + it 'deletes the namespaces associated with the cluster' do + expect { go }.to change { Clusters::KubernetesNamespace.count } + + expect(response).to redirect_to(project_cluster_path(project, cluster)) + expect(cluster.kubernetes_namespaces).to be_empty + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + end + describe 'GET cluster_status' do let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) } diff --git a/spec/features/merge_request/user_expands_diff_spec.rb b/spec/features/merge_request/user_expands_diff_spec.rb index ba7abd3af2c..9b040271468 100644 --- a/spec/features/merge_request/user_expands_diff_spec.rb +++ b/spec/features/merge_request/user_expands_diff_spec.rb @@ -8,6 +8,7 @@ describe 'User expands diff', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) allow(Gitlab::Git::Diff).to receive(:size_limit).and_return(100.kilobytes) allow(Gitlab::Git::Diff).to receive(:collapse_limit).and_return(10.kilobytes) @@ -20,7 +21,7 @@ describe 'User expands diff', :js do it_behaves_like 'rendering a single diff version' it 'allows user to expand diff' do - page.within find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd"]') do + page.within find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9"]') do click_link 'Click to expand it.' wait_for_requests diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb index 7cb46d90092..9cbea8a8466 100644 --- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb +++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb @@ -21,6 +21,7 @@ describe 'Merge request > User resolves diff notes and threads', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) end it_behaves_like 'rendering a single diff version' diff --git a/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb b/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb index e882b401122..70afe056c64 100644 --- a/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb +++ b/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb @@ -22,6 +22,7 @@ describe 'Merge request > User sees avatars on diff notes', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) project.add_maintainer(user) sign_in user diff --git a/spec/features/merge_request/user_sees_diff_spec.rb b/spec/features/merge_request/user_sees_diff_spec.rb index 82dd779577c..de142344c26 100644 --- a/spec/features/merge_request/user_sees_diff_spec.rb +++ b/spec/features/merge_request/user_sees_diff_spec.rb @@ -11,6 +11,7 @@ describe 'Merge request > User sees diff', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) end it_behaves_like 'rendering a single diff version' diff --git a/spec/features/merge_request/user_sees_versions_spec.rb b/spec/features/merge_request/user_sees_versions_spec.rb index c3fce9761df..b3aef601c7b 100644 --- a/spec/features/merge_request/user_sees_versions_spec.rb +++ b/spec/features/merge_request/user_sees_versions_spec.rb @@ -17,6 +17,7 @@ describe 'Merge request > User sees versions', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) project.add_maintainer(user) sign_in(user) diff --git a/spec/features/merge_request/user_views_diffs_spec.rb b/spec/features/merge_request/user_views_diffs_spec.rb index 5a29477e597..313f438e23b 100644 --- a/spec/features/merge_request/user_views_diffs_spec.rb +++ b/spec/features/merge_request/user_views_diffs_spec.rb @@ -10,6 +10,7 @@ describe 'User views diffs', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) visit(diffs_project_merge_request_path(project, merge_request)) wait_for_requests diff --git a/spec/features/projects/view_on_env_spec.rb b/spec/features/projects/view_on_env_spec.rb index 832985f1a30..c2d4cefad12 100644 --- a/spec/features/projects/view_on_env_spec.rb +++ b/spec/features/projects/view_on_env_spec.rb @@ -10,6 +10,7 @@ describe 'View on environment', :js do before do stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(diffs_batch_load: false) project.add_maintainer(user) end diff --git a/spec/javascripts/diffs/components/app_spec.js b/spec/javascripts/diffs/components/app_spec.js index fdf8bcee756..52f7674a7b3 100644 --- a/spec/javascripts/diffs/components/app_spec.js +++ b/spec/javascripts/diffs/components/app_spec.js @@ -34,6 +34,8 @@ describe('diffs/components/app', () => { localVue, propsData: { endpoint: `${TEST_HOST}/diff/endpoint`, + endpointMetadata: `${TEST_HOST}/diff/endpointMetadata`, + endpointBatch: `${TEST_HOST}/diff/endpointBatch`, projectPath: 'namespace/project', currentUser: {}, changesEmptyStateIllustration: '', @@ -42,6 +44,11 @@ describe('diffs/components/app', () => { ...props, }, store, + methods: { + isLatestVersion() { + return true; + }, + }, }); } @@ -59,6 +66,58 @@ describe('diffs/components/app', () => { wrapper.destroy(); }); + describe('fetch diff methods', () => { + beforeEach(() => { + spyOn(window, 'requestIdleCallback').and.callFake(fn => fn()); + createComponent(); + spyOn(wrapper.vm, 'fetchDiffFiles').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'fetchDiffFilesMeta').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'fetchDiffFilesBatch').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'setDiscussions'); + spyOn(wrapper.vm, 'startRenderDiffsQueue'); + }); + + it('calls fetchDiffFiles if diffsBatchLoad is not enabled', () => { + wrapper.vm.glFeatures.diffsBatchLoad = false; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled(); + }); + }); + + it('calls fetchDiffFiles if diffsBatchLoad is enabled, and not latest version', () => { + wrapper.vm.glFeatures.diffsBatchLoad = true; + wrapper.vm.isLatestVersion = () => false; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled(); + }); + }); + + it('calls batch methods if diffsBatchLoad is enabled, and latest version', () => { + wrapper.vm.glFeatures.diffsBatchLoad = true; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled(); + }); + }); + }); + it('adds container-limiting classes when showFileTree is false with inline diffs', () => { createComponent({}, ({ state }) => { state.diffs.showTreeList = false; @@ -93,6 +152,14 @@ describe('diffs/components/app', () => { expect(wrapper.contains(GlLoadingIcon)).toBe(true); }); + it('displays loading icon on batch loading', () => { + createComponent({}, ({ state }) => { + state.diffs.isBatchLoading = true; + }); + + expect(wrapper.contains(GlLoadingIcon)).toBe(true); + }); + it('displays diffs container when not loading', () => { createComponent(); diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 874891fcc6e..3235febe0dc 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -8,6 +8,8 @@ import { import actions, { setBaseConfig, fetchDiffFiles, + fetchDiffFilesBatch, + fetchDiffFilesMeta, assignDiscussionsToDiff, removeDiscussionsFromDiff, startRenderDiffsQueue, @@ -68,18 +70,41 @@ describe('DiffsStoreActions', () => { describe('setBaseConfig', () => { it('should set given endpoint and project path', done => { const endpoint = '/diffs/set/endpoint'; + const endpointMetadata = '/diffs/set/endpoint/metadata'; + const endpointBatch = '/diffs/set/endpoint/batch'; const projectPath = '/root/project'; const dismissEndpoint = '/-/user_callouts'; const showSuggestPopover = false; testAction( setBaseConfig, - { endpoint, projectPath, dismissEndpoint, showSuggestPopover }, - { endpoint: '', projectPath: '', dismissEndpoint: '', showSuggestPopover: true }, + { + endpoint, + endpointBatch, + endpointMetadata, + projectPath, + dismissEndpoint, + showSuggestPopover, + }, + { + endpoint: '', + endpointBatch: '', + endpointMetadata: '', + projectPath: '', + dismissEndpoint: '', + showSuggestPopover: true, + }, [ { type: types.SET_BASE_CONFIG, - payload: { endpoint, projectPath, dismissEndpoint, showSuggestPopover }, + payload: { + endpoint, + endpointMetadata, + endpointBatch, + projectPath, + dismissEndpoint, + showSuggestPopover, + }, }, ], [], @@ -114,6 +139,64 @@ describe('DiffsStoreActions', () => { }); }); + describe('fetchDiffFilesBatch', () => { + it('should fetch batch diff files', done => { + const endpointBatch = '/fetch/diffs_batch'; + const batch1 = `${endpointBatch}?per_page=10`; + const batch2 = `${endpointBatch}?per_page=10&page=2`; + const mock = new MockAdapter(axios); + const res1 = { diff_files: [], pagination: { next_page: 2 } }; + const res2 = { diff_files: [], pagination: {} }; + mock.onGet(batch1).reply(200, res1); + mock.onGet(batch2).reply(200, res2); + + testAction( + fetchDiffFilesBatch, + {}, + { endpointBatch }, + [ + { type: types.SET_BATCH_LOADING, payload: true }, + { type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: res1.diff_files } }, + { type: types.SET_BATCH_LOADING, payload: false }, + { type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: [] } }, + { type: types.SET_BATCH_LOADING, payload: false }, + ], + [], + () => { + mock.restore(); + done(); + }, + ); + }); + }); + + describe('fetchDiffFilesMeta', () => { + it('should fetch diff meta information', done => { + const endpointMetadata = '/fetch/diffs_meta'; + const mock = new MockAdapter(axios); + const data = { diff_files: [] }; + const res = { data }; + mock.onGet(endpointMetadata).reply(200, res); + + testAction( + fetchDiffFilesMeta, + {}, + { endpointMetadata }, + [ + { type: types.SET_LOADING, payload: true }, + { type: types.SET_LOADING, payload: false }, + { type: types.SET_MERGE_REQUEST_DIFFS, payload: [] }, + { type: types.SET_DIFF_DATA, payload: { data, diff_files: [] } }, + ], + [], + () => { + mock.restore(); + done(); + }, + ); + }); + }); + describe('setHighlightedRow', () => { it('should mark currently selected diff and set lineHash and fileHash of highlightedRow', () => { testAction(setHighlightedRow, 'ABC_123', {}, [ diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 3e033b6c9dc..19bf5bdd592 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -28,6 +28,16 @@ describe('DiffsStoreMutations', () => { }); }); + describe('SET_BATCH_LOADING', () => { + it('should set loading state', () => { + const state = {}; + + mutations[types.SET_BATCH_LOADING](state, false); + + expect(state.isBatchLoading).toEqual(false); + }); + }); + describe('SET_DIFF_DATA', () => { it('should set diff data type properly', () => { const state = {}; @@ -45,6 +55,23 @@ describe('DiffsStoreMutations', () => { }); }); + describe('SET_DIFFSET_DIFF_DATA_BATCH_DATA', () => { + it('should set diff data batch type properly', () => { + const state = { diffFiles: [] }; + const diffMock = { + diff_files: [diffFileMockData], + }; + + mutations[types.SET_DIFF_DATA_BATCH](state, diffMock); + + const firstLine = state.diffFiles[0].parallel_diff_lines[0]; + + expect(firstLine.right.text).toBeUndefined(); + expect(state.diffFiles[0].renderIt).toEqual(true); + expect(state.diffFiles[0].collapsed).toEqual(false); + }); + }); + describe('SET_DIFF_VIEW_TYPE', () => { it('should set diff view type properly', () => { const state = {}; diff --git a/spec/javascripts/environments/environments_app_spec.js b/spec/javascripts/environments/environments_app_spec.js index 0dcd8868aba..10d37c86ea7 100644 --- a/spec/javascripts/environments/environments_app_spec.js +++ b/spec/javascripts/environments/environments_app_spec.js @@ -10,7 +10,6 @@ describe('Environment', () => { endpoint: 'environments.json', canCreateEnvironment: true, canReadEnvironment: true, - cssContainerClass: 'container', newEnvironmentPath: 'environments/new', helpPagePath: 'help', canaryDeploymentFeatureId: 'canary_deployment', diff --git a/spec/lib/gitlab/ci/build/context/build_spec.rb b/spec/lib/gitlab/ci/build/context/build_spec.rb index 3adde213f59..1b73b9a083d 100644 --- a/spec/lib/gitlab/ci/build/context/build_spec.rb +++ b/spec/lib/gitlab/ci/build/context/build_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Ci::Build::Context::Build do diff --git a/spec/lib/gitlab/ci/build/context/global_spec.rb b/spec/lib/gitlab/ci/build/context/global_spec.rb index 6bc8f862779..65cc41ed3f9 100644 --- a/spec/lib/gitlab/ci/build/context/global_spec.rb +++ b/spec/lib/gitlab/ci/build/context/global_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Ci::Build::Context::Global do diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 049db4f7013..7c419a195cd 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -960,4 +960,20 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do end end end + + describe '#delete_cached_resources!' do + let!(:cluster) { create(:cluster, :project) } + let!(:staging_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster, namespace: 'staging') } + let!(:production_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster, namespace: 'production') } + + subject { cluster.delete_cached_resources! } + + it 'deletes associated namespace records' do + expect(cluster.kubernetes_namespaces).to match_array([staging_namespace, production_namespace]) + + subject + + expect(cluster.kubernetes_namespaces).to be_empty + end + end end diff --git a/spec/presenters/group_clusterable_presenter_spec.rb b/spec/presenters/group_clusterable_presenter_spec.rb index 11a8decc9cc..d40ca856f7b 100644 --- a/spec/presenters/group_clusterable_presenter_spec.rb +++ b/spec/presenters/group_clusterable_presenter_spec.rb @@ -83,6 +83,12 @@ describe GroupClusterablePresenter do it { is_expected.to eq(update_applications_group_cluster_path(group, cluster, application)) } end + describe '#clear_cluster_cache_path' do + subject { presenter.clear_cluster_cache_path(cluster) } + + it { is_expected.to eq(clear_cache_group_cluster_path(group, cluster)) } + end + describe '#cluster_path' do subject { presenter.cluster_path(cluster) } diff --git a/spec/presenters/instance_clusterable_presenter_spec.rb b/spec/presenters/instance_clusterable_presenter_spec.rb index 9f1268379f5..3e7ee7a0ff6 100644 --- a/spec/presenters/instance_clusterable_presenter_spec.rb +++ b/spec/presenters/instance_clusterable_presenter_spec.rb @@ -34,4 +34,10 @@ describe InstanceClusterablePresenter do it { is_expected.to eq(aws_proxy_admin_clusters_path(resource: resource)) } end + + describe '#clear_cluster_cache_path' do + subject { presenter.clear_cluster_cache_path(cluster) } + + it { is_expected.to eq(clear_cache_admin_cluster_path(cluster)) } + end end diff --git a/spec/presenters/project_clusterable_presenter_spec.rb b/spec/presenters/project_clusterable_presenter_spec.rb index 441c2a50fea..b3dad4abde5 100644 --- a/spec/presenters/project_clusterable_presenter_spec.rb +++ b/spec/presenters/project_clusterable_presenter_spec.rb @@ -83,6 +83,12 @@ describe ProjectClusterablePresenter do it { is_expected.to eq(update_applications_project_cluster_path(project, cluster, application)) } end + describe '#clear_cluster_cache_path' do + subject { presenter.clear_cluster_cache_path(cluster) } + + it { is_expected.to eq(clear_cache_project_cluster_path(project, cluster)) } + end + describe '#cluster_path' do subject { presenter.cluster_path(cluster) } diff --git a/spec/support/shared_examples/merge_requests_rendering_a_single_diff_version.rb b/spec/support/shared_examples/merge_requests_rendering_a_single_diff_version.rb index 80120629a32..18d025a4b07 100644 --- a/spec/support/shared_examples/merge_requests_rendering_a_single_diff_version.rb +++ b/spec/support/shared_examples/merge_requests_rendering_a_single_diff_version.rb @@ -3,6 +3,10 @@ # This pending test can be removed when `single_mr_diff_view` is enabled by default # disabling the feature flag above is then not needed anymore. RSpec.shared_examples 'rendering a single diff version' do |attribute| + before do + stub_feature_flags(diffs_batch_load: false) + end + pending 'allows editing diff settings single_mr_diff_view is enabled' do project = create(:project, :repository) user = project.creator |