diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-08 12:09:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-08 12:09:44 +0300 |
commit | 058e1a233fc1d96917c72cfab552c72db93f4f8b (patch) | |
tree | f96445a056696c79e520e67ae01d7e055485d137 /spec | |
parent | 24fa0480c03a086451f592ddcacc644e560972cc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/boards/components/config_toggle_spec.js | 59 | ||||
-rw-r--r-- | spec/frontend/boards/components/toggle_focus_spec.js | 47 | ||||
-rw-r--r-- | spec/helpers/projects/pipeline_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 36 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 9 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 34 | ||||
-rw-r--r-- | spec/workers/projects/after_import_worker_spec.rb | 13 |
8 files changed, 171 insertions, 41 deletions
diff --git a/spec/frontend/boards/components/config_toggle_spec.js b/spec/frontend/boards/components/config_toggle_spec.js new file mode 100644 index 00000000000..47d4692453d --- /dev/null +++ b/spec/frontend/boards/components/config_toggle_spec.js @@ -0,0 +1,59 @@ +import Vuex from 'vuex'; +import Vue from 'vue'; +import { shallowMount } from '@vue/test-utils'; +import { GlButton } from '@gitlab/ui'; +import ConfigToggle from '~/boards/components/config_toggle.vue'; +import eventHub from '~/boards/eventhub'; +import store from '~/boards/stores'; +import { mockTracking } from 'helpers/tracking_helper'; + +describe('ConfigToggle', () => { + let wrapper; + + Vue.use(Vuex); + + const createComponent = (provide = {}) => + shallowMount(ConfigToggle, { + store, + provide: { + canAdminList: true, + ...provide, + }, + }); + + const findButton = () => wrapper.findComponent(GlButton); + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders a button with label `View scope` when `canAdminList` is `false`', () => { + wrapper = createComponent({ canAdminList: false }); + expect(findButton().text()).toBe('View scope'); + }); + + it('renders a button with label `Edit board` when `canAdminList` is `true`', () => { + wrapper = createComponent(); + expect(findButton().text()).toBe('Edit board'); + }); + + it('emits `showBoardModal` when button is clicked', () => { + const eventHubSpy = jest.spyOn(eventHub, '$emit'); + wrapper = createComponent(); + + findButton().vm.$emit('click', { preventDefault: () => {} }); + + expect(eventHubSpy).toHaveBeenCalledWith('showBoardModal', 'edit'); + }); + + it('tracks clicking the button', () => { + const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn); + wrapper = createComponent(); + + findButton().vm.$emit('click', { preventDefault: () => {} }); + + expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_button', { + label: 'edit_board', + }); + }); +}); diff --git a/spec/frontend/boards/components/toggle_focus_spec.js b/spec/frontend/boards/components/toggle_focus_spec.js new file mode 100644 index 00000000000..3cbaac91f8d --- /dev/null +++ b/spec/frontend/boards/components/toggle_focus_spec.js @@ -0,0 +1,47 @@ +import { GlButton } from '@gitlab/ui'; +import { nextTick } from 'vue'; +import ToggleFocus from '~/boards/components/toggle_focus.vue'; +import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; + +describe('ToggleFocus', () => { + let wrapper; + + const createComponent = () => { + wrapper = shallowMountExtended(ToggleFocus, { + directives: { + GlTooltip: createMockDirective(), + }, + attachTo: document.body, + }); + }; + + const findButton = () => wrapper.findComponent(GlButton); + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders a button with `maximize` icon', () => { + createComponent(); + + expect(findButton().props('icon')).toBe('maximize'); + expect(findButton().attributes('aria-label')).toBe(ToggleFocus.i18n.toggleFocusMode); + }); + + it('contains a tooltip with title', () => { + createComponent(); + const tooltip = getBinding(findButton().element, 'gl-tooltip'); + + expect(tooltip).toBeDefined(); + expect(findButton().attributes('title')).toBe(ToggleFocus.i18n.toggleFocusMode); + }); + + it('toggles the icon when the button is clicked', async () => { + createComponent(); + findButton().vm.$emit('click'); + await nextTick(); + + expect(findButton().props('icon')).toBe('minimize'); + }); +}); diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb index d04aa9a9d04..2b2dad286c7 100644 --- a/spec/helpers/projects/pipeline_helper_spec.rb +++ b/spec/helpers/projects/pipeline_helper_spec.rb @@ -11,7 +11,11 @@ RSpec.describe Projects::PipelineHelper do let_it_be(:pipeline) { Ci::PipelinePresenter.new(raw_pipeline, current_user: user)} describe '#js_pipeline_tabs_data' do - subject(:pipeline_tabs_data) { helper.js_pipeline_tabs_data(project, pipeline) } + before do + project.add_developer(user) + end + + subject(:pipeline_tabs_data) { helper.js_pipeline_tabs_data(project, pipeline, user) } it 'returns pipeline tabs data' do expect(pipeline_tabs_data).to include({ diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index f75e3352e96..b372350ca26 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -367,8 +367,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end it 'returns the correct count bounding at max_count' do - branch_a_sha = repository_rugged.branches['left-branch'].target.oid - branch_b_sha = repository_rugged.branches['right-branch'].target.oid + branch_a_sha = repository.find_branch('left-branch').dereferenced_target.sha + branch_b_sha = repository.find_branch('right-branch').dereferenced_target.sha count = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: 1000) @@ -407,8 +407,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end it 'returns the correct count bounding at max_count' do - branch_a_sha = repository_rugged.branches['left-branch'].target.oid - branch_b_sha = repository_rugged.branches['right-branch'].target.oid + branch_a_sha = repository.find_branch('left-branch').dereferenced_target.sha + branch_b_sha = repository.find_branch('right-branch').dereferenced_target.sha results = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: max_count) @@ -469,16 +469,14 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do it 'deletes the ref' do repository.delete_refs('refs/heads/feature') - expect(repository_rugged.references['refs/heads/feature']).to be_nil + expect(repository.find_branch('feature')).to be_nil end it 'deletes all refs' do refs = %w[refs/heads/wip refs/tags/v1.1.0] repository.delete_refs(*refs) - refs.each do |ref| - expect(repository_rugged.references[ref]).to be_nil - end + expect(repository.list_refs(refs)).to be_empty end it 'does not fail when deleting an empty list of refs' do @@ -491,7 +489,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end describe '#branch_names_contains_sha' do - let(:head_id) { repository_rugged.head.target.oid } + let(:head_id) { repository.commit.id } let(:new_branch) { head_id } let(:utf8_branch) { 'branch-é' } @@ -1823,7 +1821,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do let(:new_oid) { new_commit_edit_old_file(source_rugged).oid } before do - source_rugged.branches.create(source_branch, new_oid) + source_repository.write_ref(source_branch, new_oid) end it 'writes the ref' do @@ -1869,7 +1867,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do it "removes the branch from the repo" do repository.rm_branch(branch_name, user: user) - expect(repository_rugged.branches[branch_name]).to be_nil + expect(repository.find_branch(branch_name)).to be_nil end end @@ -2342,16 +2340,10 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do end def create_remote_branch(remote_name, branch_name, source_branch_name) - source_branch = repository.branches.find { |branch| branch.name == source_branch_name } + source_branch = repository.find_branch(source_branch_name) repository.write_ref("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha) end - def refs(dir) - IO.popen(%W[git -C #{dir} for-each-ref], &:read).split("\n").map do |line| - line.split("\t").last - end - end - describe '#disconnect_alternates' do let(:project) { create(:project, :repository) } let(:pool_repository) { create(:pool_repository) } @@ -2483,7 +2475,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do it 'mirrors the source repository' do subject - expect(refs(new_repository_path)).to eq(refs(repository_path)) + expect(new_repository.list_refs(['refs/'])).to eq(repository.list_refs(['refs/'])) end end @@ -2495,7 +2487,7 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do it 'mirrors the source repository' do subject - expect(refs(new_repository_path)).to eq(refs(repository_path)) + expect(new_repository.list_refs(['refs/'])).to eq(repository.list_refs(['refs/'])) end context 'with keep-around refs' do @@ -2511,8 +2503,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do it 'includes the temporary and keep-around refs' do subject - expect(refs(new_repository_path)).to include(keep_around_ref) - expect(refs(new_repository_path)).to include(tmp_ref) + expect(new_repository.list_refs([keep_around_ref]).map(&:name)).to match_array([keep_around_ref]) + expect(new_repository.list_refs([tmp_ref]).map(&:name)).to match_array([tmp_ref]) end end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 05ba79e2b98..dc3eaa69a34 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2259,20 +2259,12 @@ RSpec.describe Repository do describe '#branch_count' do it 'returns the number of branches' do expect(repository.branch_count).to be_an(Integer) - - rugged_count = rugged_repo(repository).branches.count - - expect(repository.branch_count).to eq(rugged_count) end end describe '#tag_count' do it 'returns the number of tags' do expect(repository.tag_count).to be_an(Integer) - - rugged_count = rugged_repo(repository).tags.count - - expect(repository.tag_count).to eq(rugged_count) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 626d8c8d337..b50973f0d17 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3442,6 +3442,15 @@ RSpec.describe User do end end + describe '#followed_by?' do + it 'check if followed by another user' do + follower = create :user + followee = create :user + + expect { follower.follow(followee) }.to change { followee.followed_by?(follower) }.from(false).to(true) + end + end + describe '#follow' do it 'follow another user' do user = create :user diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 3b0f1032288..68d5fad8ff4 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -185,6 +185,40 @@ RSpec.describe API::Users do expect(json_response.first['note']).to eq '2018-11-05 | 2FA removed | user requested | www.gitlab.com' end end + + context 'N+1 queries' do + before do + create_list(:user, 2) + end + + it 'avoids N+1 queries when requested by admin' do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + get api("/users", admin) + end.count + + create_list(:user, 3) + + # There is a still a pending N+1 query related to fetching + # project count for each user. + # Refer issue https://gitlab.com/gitlab-org/gitlab/-/issues/367080 + + expect do + get api("/users", admin) + end.not_to exceed_all_query_limit(control_count + 3) + end + + it 'avoids N+1 queries when requested by a regular user' do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + get api("/users", user) + end.count + + create_list(:user, 3) + + expect do + get api("/users", user) + end.not_to exceed_all_query_limit(control_count) + end + end end end diff --git a/spec/workers/projects/after_import_worker_spec.rb b/spec/workers/projects/after_import_worker_spec.rb index 332b547bb66..a14b2443173 100644 --- a/spec/workers/projects/after_import_worker_spec.rb +++ b/spec/workers/projects/after_import_worker_spec.rb @@ -39,8 +39,7 @@ RSpec.describe Projects::AfterImportWorker do end it 'removes refs/pull/**/*' do - expect(rugged.references.map(&:name)) - .not_to include(%r{\Arefs/pull/}) + expect(repository.list_refs(['refs/pull/'])).to be_empty end end @@ -53,8 +52,7 @@ RSpec.describe Projects::AfterImportWorker do end it "does not remove refs/#{name}/tmp" do - expect(rugged.references.map(&:name)) - .to include("refs/#{name}/tmp") + expect(repository.list_refs(["refs/#{name}/tmp"]).length).to be(1) end end end @@ -100,8 +98,7 @@ RSpec.describe Projects::AfterImportWorker do it 'removes refs/pull/**/*' do subject - expect(rugged.references.map(&:name)) - .not_to include(%r{\Arefs/pull/}) + expect(repository.list_refs(['refs/pull/'])).to be_empty end it 'records the failures in the database', :aggregate_failures do @@ -123,9 +120,5 @@ RSpec.describe Projects::AfterImportWorker do expect(import_failure.correlation_id_value).not_to be_empty end end - - def rugged - rugged_repo(repository) - end end end |