diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-30 21:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-30 21:09:47 +0300 |
commit | cd99e8611a6df11975c227517892606440ad3ff6 (patch) | |
tree | aea53bef850be971e128b4be9649654d760b2b02 /spec | |
parent | 412fe7ab5511ec446f250d415d571108fe838b68 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
26 files changed, 728 insertions, 743 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 327f162f57a..0875bb4e92a 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -80,6 +80,7 @@ RSpec.describe 'Database schema', feature_category: :database do ldap_group_links: %w[group_id], members: %w[source_id created_by_id], merge_requests: %w[last_edited_by_id state_id], + merge_requests_compliance_violations: %w[target_project_id], merge_request_diff_commits: %w[commit_author_id committer_id], namespaces: %w[owner_id parent_id], notes: %w[author_id commit_id noteable_id updated_by_id resolved_by_id confirmed_by_id discussion_id], diff --git a/spec/factories/lfs_objects.rb b/spec/factories/lfs_objects.rb index 59c6ea5f55a..630f775d231 100644 --- a/spec/factories/lfs_objects.rb +++ b/spec/factories/lfs_objects.rb @@ -20,4 +20,11 @@ FactoryBot.define do trait :object_storage do file_store { LfsObjectUploader::Store::REMOTE } end + + trait :with_lfs_object_dot_iso_file do + with_file + object_storage + oid { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' } + size { 133 } + end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 6e3a7a3f5ef..67186282c95 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -253,9 +253,35 @@ FactoryBot.define do create_templates { nil } create_branch { nil } create_tag { nil } + lfs { false } end after :create do |project, evaluator| + # Specify `lfs: true` to create the LfsObject for the LFS file in the test repo: + # https://gitlab.com/gitlab-org/gitlab-test/-/blob/master/files/lfs/lfs_object.iso + if evaluator.lfs + RSpec::Mocks.with_temporary_scope do + # If lfs object store is disabled we need to mock + unless Gitlab.config.lfs.object_store.enabled + config = Gitlab.config.lfs.object_store.merge('enabled' => true) + allow(LfsObjectUploader).to receive(:object_store_options).and_return(config) + Fog.mock! + Fog::Storage.new(LfsObjectUploader.object_store_credentials).tap do |connection| + connection.directories.create(key: config.remote_directory) # rubocop:disable Rails/SaveBang + + # Cleanup remaining files + connection.directories.each do |directory| + directory.files.map(&:destroy) + end + rescue Excon::Error::Conflict + end + end + + lfs_object = create(:lfs_object, :with_lfs_object_dot_iso_file) + create(:lfs_objects_project, project: project, lfs_object: lfs_object) + end + end + if evaluator.create_templates templates_path = "#{evaluator.create_templates}_templates" @@ -286,7 +312,6 @@ FactoryBot.define do "README on branch #{evaluator.create_branch}", message: 'Add README.md', branch_name: evaluator.create_branch) - end if evaluator.create_tag diff --git a/spec/features/search/user_searches_for_code_spec.rb b/spec/features/search/user_searches_for_code_spec.rb index dd7095107f4..6c9db029683 100644 --- a/spec/features/search/user_searches_for_code_spec.rb +++ b/spec/features/search/user_searches_for_code_spec.rb @@ -3,242 +3,235 @@ require 'spec_helper' RSpec.describe 'User searches for code', :js, :disable_rate_limiter, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be_with_reload(:project) { create(:project, :repository, namespace: user.namespace) } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - context 'when signed in' do + context 'when signed in' do + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when on a project page' do before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_maintainer(user) - sign_in(user) + visit(project_path(project)) end - context 'when on a project page' do - before do - visit(project_path(project)) - end + it 'finds a file' do + submit_search('application.js') + select_search_scope('Code') - it 'finds a file' do - submit_search('application.js') - select_search_scope('Code') + expect(page).to have_selector('.results', text: 'application.js') + expect(page).to have_selector('.file-content .code') + expect(page).to have_selector("span.line[lang='javascript']") + expect(page).to have_link('application.js', href: %r{master/files/js/application.js}) + expect(page).to have_button('Copy file path') + end + end + + context 'when on a project search page' do + before do + visit(search_path) + find('[data-testid="project-filter"]').click + + wait_for_requests - expect(page).to have_selector('.results', text: 'application.js') - expect(page).to have_selector('.file-content .code') - expect(page).to have_selector("span.line[lang='javascript']") - expect(page).to have_link('application.js', href: %r{master/files/js/application.js}) - expect(page).to have_button('Copy file path') + page.within('[data-testid="project-filter"]') do + click_on(project.name) end end - context 'when on a project search page' do - before do - visit(search_path) - find('[data-testid="project-filter"]').click + include_examples 'top right search form' + include_examples 'search timeouts', 'blobs' do + let(:additional_params) { { project_id: project.id } } + end - wait_for_requests + context 'when searching code' do + let(:expected_result) { 'Update capybara, rspec-rails, poltergeist to recent versions' } - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + before do + fill_in('dashboard_search', with: 'rspec') + find('.gl-search-box-by-click-search-button').click end - include_examples 'top right search form' - include_examples 'search timeouts', 'blobs' do - let(:additional_params) { { project_id: project.id } } + it 'finds code and links to blob' do + expect(page).to have_selector('.results', text: expected_result) + + find("#blob-L3").click + expect(current_url).to match(%r{blob/master/.gitignore#L3}) end - context 'when searching code' do - let(:expected_result) { 'Update capybara, rspec-rails, poltergeist to recent versions' } + it 'finds code and links to blame' do + expect(page).to have_selector('.results', text: expected_result) - before do - fill_in('dashboard_search', with: 'rspec') - find('.gl-search-box-by-click-search-button').click - end + find("#blame-L3").click + expect(current_url).to match(%r{blame/master/.gitignore#L3}) + end - it 'finds code and links to blob' do - expect(page).to have_selector('.results', text: expected_result) + it_behaves_like 'code highlight' do + subject { page } + end + end - find("#blob-L3").click - expect(current_url).to match(%r{blob/master/.gitignore#L3}) - end + it 'search multiple words with refs switching' do + expected_result = 'Use `snake_case` for naming files' + search = 'for naming files' + ref_selector = 'v1.0.0' - it 'finds code and links to blame' do - expect(page).to have_selector('.results', text: expected_result) + fill_in('dashboard_search', with: search) + find('.gl-search-box-by-click-search-button').click - find("#blame-L3").click - expect(current_url).to match(%r{blame/master/.gitignore#L3}) - end + expect(page).to have_selector('.results', text: expected_result) - it_behaves_like 'code highlight' do - subject { page } - end - end + find('.ref-selector').click + wait_for_requests - it 'search multiple words with refs switching' do - expected_result = 'Use `snake_case` for naming files' - search = 'for naming files' + page.within('.ref-selector') do + fill_in 'Search by Git revision', with: ref_selector + wait_for_requests + find('li', text: ref_selector, match: :prefer_exact).click + end - fill_in('dashboard_search', with: search) - find('.gl-search-box-by-click-search-button').click + expect(page).to have_selector('.results', text: expected_result) - expect(page).to have_selector('.results', text: expected_result) + expect(find_field('dashboard_search').value).to eq(search) + expect(find("#blob-L1502")[:href]).to match(%r{blob/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + expect(find("#blame-L1502")[:href]).to match(%r{blame/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + end + end - find('.ref-selector').click - wait_for_requests + context 'when :new_header_search is true' do + context 'search code within refs' do + let(:ref_name) { 'v1.0.0' } - page.within('.ref-selector') do - find('li', text: 'v1.0.0').click - end + before do + # This feature is disabled by default in spec_helper.rb. + # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. + # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. + stub_feature_flags(new_header_search: true) + visit(project_tree_path(project, ref_name)) - expect(page).to have_selector('.results', text: expected_result) + submit_search('gitlab-grack') + select_search_scope('Code') + end - expect(find_field('dashboard_search').value).to eq(search) - expect(find("#blob-L1502")[:href]).to match(%r{blob/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) - expect(find("#blame-L1502")[:href]).to match(%r{blame/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + it 'shows ref switcher in code result summary' do + expect(find('.ref-selector')).to have_text(ref_name) end - end - context 'when :new_header_search is true' do - context 'search code within refs' do - let(:ref_name) { 'v1.0.0' } + it 'persists branch name across search' do + find('.gl-search-box-by-click-search-button').click + expect(find('.ref-selector')).to have_text(ref_name) + end - before do - # This feature is disabled by default in spec_helper.rb. - # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. - # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. - stub_feature_flags(new_header_search: true) - visit(project_tree_path(project, ref_name)) + # this example is use to test the design that the refs is not + # only represent the branch as well as the tags. + it 'ref switcher list all the branches and tags' do + find('.ref-selector').click + wait_for_requests - submit_search('gitlab-grack') - select_search_scope('Code') + page.within('.ref-selector') do + expect(page).to have_selector('li', text: 'add-ipython-files') + expect(page).to have_selector('li', text: 'v1.0.0') end + end - it 'shows ref switcher in code result summary' do - expect(find('.ref-selector')).to have_text(ref_name) - end + it 'search result changes when refs switched' do + ref = 'master' + expect(find('.results')).not_to have_content('path = gitlab-grack') - it 'persists branch name across search' do - find('.gl-search-box-by-click-search-button').click - expect(find('.ref-selector')).to have_text(ref_name) - end + find('.ref-selector').click + wait_for_requests - # this example is use to test the design that the refs is not - # only represent the branch as well as the tags. - it 'ref switcher list all the branches and tags' do - find('.ref-selector').click + page.within('.ref-selector') do + fill_in _('Search by Git revision'), with: ref wait_for_requests - page.within('.ref-selector') do - expect(page).to have_selector('li', text: 'add-ipython-files') - expect(page).to have_selector('li', text: 'v1.0.0') - end + find('li', text: ref).click end - it 'search result changes when refs switched' do - ref = 'master' - expect(find('.results')).not_to have_content('path = gitlab-grack') + expect(page).to have_selector('.results', text: 'path = gitlab-grack') + end + end + end - find('.ref-selector').click - wait_for_requests + context 'when :new_header_search is false' do + context 'search code within refs' do + let(:ref_name) { 'v1.0.0' } - page.within('.ref-selector') do - fill_in _('Search by Git revision'), with: ref - wait_for_requests + before do + # This feature is disabled by default in spec_helper.rb. + # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. + # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. + stub_feature_flags(new_header_search: false) + visit(project_tree_path(project, ref_name)) - find('li', text: ref).click - end + submit_search('gitlab-grack') + select_search_scope('Code') + end - expect(page).to have_selector('.results', text: 'path = gitlab-grack') - end + it 'shows ref switcher in code result summary' do + expect(find('.ref-selector')).to have_text(ref_name) end - end - context 'when :new_header_search is false' do - context 'search code within refs' do - let(:ref_name) { 'v1.0.0' } + it 'persists branch name across search' do + find('.gl-search-box-by-click-search-button').click + expect(find('.ref-selector')).to have_text(ref_name) + end - before do - # This feature is disabled by default in spec_helper.rb. - # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. - # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. - stub_feature_flags(new_header_search: false) - visit(project_tree_path(project, ref_name)) + # this example is use to test the design that the refs is not + # only represent the branch as well as the tags. + it 'ref switcher list all the branches and tags' do + find('.ref-selector').click + wait_for_requests - submit_search('gitlab-grack') - select_search_scope('Code') + page.within('.ref-selector') do + expect(page).to have_selector('li', text: 'add-ipython-files') + expect(page).to have_selector('li', text: 'v1.0.0') end + end - it 'shows ref switcher in code result summary' do - expect(find('.ref-selector')).to have_text(ref_name) - end + it 'search result changes when refs switched' do + ref = 'master' + expect(find('.results')).not_to have_content('path = gitlab-grack') - it 'persists branch name across search' do - find('.gl-search-box-by-click-search-button').click - expect(find('.ref-selector')).to have_text(ref_name) - end + find('.ref-selector').click + wait_for_requests - # this example is use to test the design that the refs is not - # only represent the branch as well as the tags. - it 'ref switcher list all the branches and tags' do - find('.ref-selector').click + page.within('.ref-selector') do + fill_in _('Search by Git revision'), with: ref wait_for_requests - page.within('.ref-selector') do - expect(page).to have_selector('li', text: 'add-ipython-files') - expect(page).to have_selector('li', text: 'v1.0.0') - end + find('li', text: ref).click end - it 'search result changes when refs switched' do - ref = 'master' - expect(find('.results')).not_to have_content('path = gitlab-grack') - - find('.ref-selector').click - wait_for_requests - - page.within('.ref-selector') do - fill_in _('Search by Git revision'), with: ref - wait_for_requests - - find('li', text: ref).click - end - - expect(page).to have_selector('.results', text: 'path = gitlab-grack') - end + expect(page).to have_selector('.results', text: 'path = gitlab-grack') end end + end - it 'no ref switcher shown in issue result summary' do - issue = create(:issue, title: 'test', project: project) - visit(project_tree_path(project)) + it 'no ref switcher shown in issue result summary' do + issue = create(:issue, title: 'test', project: project) + visit(project_tree_path(project)) - submit_search('test') - select_search_scope('Code') + submit_search('test') + select_search_scope('Code') - expect(page).to have_selector('.ref-selector') + expect(page).to have_selector('.ref-selector') - select_search_scope('Issues') + select_search_scope('Issues') - expect(find(:css, '.results')).to have_link(issue.title) - expect(page).not_to have_selector('.ref-selector') - end + expect(find(:css, '.results')).to have_link(issue.title) + expect(page).not_to have_selector('.ref-selector') end + end - context 'when signed out' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - end - - context 'when block_anonymous_global_searches is enabled' do - it 'is redirected to login page' do - visit(search_path) + context 'when signed out' do + context 'when block_anonymous_global_searches is enabled' do + it 'is redirected to login page' do + visit(search_path) - expect(page).to have_content('You must be logged in to search across all of GitLab') - end + expect(page).to have_content('You must be logged in to search across all of GitLab') end end end diff --git a/spec/features/search/user_searches_for_comments_spec.rb b/spec/features/search/user_searches_for_comments_spec.rb index d7f6143d173..f7af1797c71 100644 --- a/spec/features/search/user_searches_for_comments_spec.rb +++ b/spec/features/search/user_searches_for_comments_spec.rb @@ -3,51 +3,45 @@ require 'spec_helper' RSpec.describe 'User searches for comments', :js, :disable_rate_limiter, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_reporter(user) - sign_in(user) + before do + project.add_reporter(user) + sign_in(user) - visit(project_path(project)) - end + visit(project_path(project)) + end - include_examples 'search timeouts', 'notes' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'search timeouts', 'notes' do + let(:additional_params) { { project_id: project.id } } + end - context 'when a comment is in commits' do - context 'when comment belongs to an invalid commit' do - let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') } + context 'when a comment is in commits' do + context 'when comment belongs to an invalid commit' do + let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') } - it 'finds a commit' do - submit_search(comment.note) - select_search_scope('Comments') + it 'finds a commit' do + submit_search(comment.note) + select_search_scope('Comments') - page.within('.results') do - expect(page).to have_content('Commit deleted') - expect(page).to have_content('12345678') - end + page.within('.results') do + expect(page).to have_content('Commit deleted') + expect(page).to have_content('12345678') end end end + end - context 'when a comment is in a snippet' do - let(:snippet) { create(:project_snippet, :private, project: project, author: user, title: 'Some title') } - let(:comment) { create(:note, noteable: snippet, author: user, note: 'Supercalifragilisticexpialidocious', project: project) } + context 'when a comment is in a snippet' do + let(:snippet) { create(:project_snippet, :private, project: project, author: user, title: 'Some title') } + let(:comment) { create(:note, noteable: snippet, author: user, note: 'Supercalifragilisticexpialidocious', project: project) } - it 'finds a snippet' do - submit_search(comment.note) - select_search_scope('Comments') + it 'finds a snippet' do + submit_search(comment.note) + select_search_scope('Comments') - expect(page).to have_selector('.results', text: snippet.title) - end + expect(page).to have_selector('.results', text: snippet.title) end end end diff --git a/spec/features/search/user_searches_for_commits_spec.rb b/spec/features/search/user_searches_for_commits_spec.rb index 1fd62a01c78..724daf9277d 100644 --- a/spec/features/search/user_searches_for_commits_spec.rb +++ b/spec/features/search/user_searches_for_commits_spec.rb @@ -3,61 +3,55 @@ require 'spec_helper' RSpec.describe 'User searches for commits', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } - let(:project) { create(:project, :repository) } let(:sha) { '6d394385cf567f80a8fd85055db1ab4c5295806f' } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_reporter(user) - sign_in(user) + before do + project.add_reporter(user) + sign_in(user) - visit(search_path(project_id: project.id)) - end + visit(search_path(project_id: project.id)) + end - include_examples 'search timeouts', 'commits' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'search timeouts', 'commits' do + let(:additional_params) { { project_id: project.id } } + end - context 'when searching by SHA' do - it 'finds a commit and redirects to its page' do - submit_search(sha) + context 'when searching by SHA' do + it 'finds a commit and redirects to its page' do + submit_search(sha) - expect(page).to have_current_path(project_commit_path(project, sha)) - end + expect(page).to have_current_path(project_commit_path(project, sha)) + end - it 'finds a commit in uppercase and redirects to its page' do - submit_search(sha.upcase) + it 'finds a commit in uppercase and redirects to its page' do + submit_search(sha.upcase) - expect(page).to have_current_path(project_commit_path(project, sha)) - end + expect(page).to have_current_path(project_commit_path(project, sha)) end + end - context 'when searching by message' do - it 'finds a commit and holds on /search page' do - project.repository.commit_files( - user, - message: 'Message referencing another sha: "deadbeef"', - branch_name: 'master', - actions: [{ action: :create, file_path: 'a/new.file', contents: 'new file' }] - ) + context 'when searching by message' do + it 'finds a commit and holds on /search page' do + project.repository.commit_files( + user, + message: 'Message referencing another sha: "deadbeef"', + branch_name: 'master', + actions: [{ action: :create, file_path: 'a/new.file', contents: 'new file' }] + ) - submit_search('deadbeef') + submit_search('deadbeef') - expect(page).to have_current_path('/search', ignore_query: true) - end + expect(page).to have_current_path('/search', ignore_query: true) + end - it 'finds multiple commits' do - submit_search('See merge request') - select_search_scope('Commits') + it 'finds multiple commits' do + submit_search('See merge request') + select_search_scope('Commits') - expect(page).to have_selector('.commit-row-description', visible: false, count: 9) - end + expect(page).to have_selector('.commit-row-description', visible: false, count: 9) end end end diff --git a/spec/features/search/user_searches_for_issues_spec.rb b/spec/features/search/user_searches_for_issues_spec.rb index 6ebbe86d1a9..9451e337db1 100644 --- a/spec/features/search/user_searches_for_issues_spec.rb +++ b/spec/features/search/user_searches_for_issues_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe 'User searches for issues', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: user.namespace) } @@ -17,133 +15,123 @@ RSpec.describe 'User searches for issues', :js, :clean_gitlab_redis_rate_limitin select_search_scope('Issues') end - where(search_page_vertical_nav_enabled: [true, false]) - - with_them do - context 'when signed in' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) + context 'when signed in' do + before do + project.add_maintainer(user) + sign_in(user) - project.add_maintainer(user) - sign_in(user) + visit(search_path) + end - visit(search_path) - end + include_examples 'top right search form' + include_examples 'search timeouts', 'issues' - include_examples 'top right search form' - include_examples 'search timeouts', 'issues' + it 'finds an issue' do + search_for_issue(issue1.title) - it 'finds an issue' do - search_for_issue(issue1.title) - - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end + end - it 'hides confidential icon for non-confidential issues' do - search_for_issue(issue1.title) + it 'hides confidential icon for non-confidential issues' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).not_to have_css('[data-testid="eye-slash-icon"]') - end + page.within('.results') do + expect(page).not_to have_css('[data-testid="eye-slash-icon"]') end + end - it 'shows confidential icon for confidential issues' do - search_for_issue(issue2.title) + it 'shows confidential icon for confidential issues' do + search_for_issue(issue2.title) - page.within('.results') do - expect(page).to have_css('[data-testid="eye-slash-icon"]') - end + page.within('.results') do + expect(page).to have_css('[data-testid="eye-slash-icon"]') end + end - it 'shows correct badge for open issues' do - search_for_issue(issue1.title) + it 'shows correct badge for open issues' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_css('.badge-success') - expect(page).not_to have_css('.badge-info') - end + page.within('.results') do + expect(page).to have_css('.badge-success') + expect(page).not_to have_css('.badge-info') end + end - it 'shows correct badge for closed issues' do - search_for_issue(issue2.title) + it 'shows correct badge for closed issues' do + search_for_issue(issue2.title) - page.within('.results') do - expect(page).not_to have_css('.badge-success') - expect(page).to have_css('.badge-info') - end + page.within('.results') do + expect(page).not_to have_css('.badge-success') + expect(page).to have_css('.badge-info') end + end - it 'sorts by created date' do - search_for_issue('issue') + it 'sorts by created date' do + search_for_issue('issue') - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(issue2.title) - expect(page.all('.search-result-row').last).to have_link(issue1.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue2.title) + expect(page.all('.search-result-row').last).to have_link(issue1.title) + end - find('[data-testid="sort-highest-icon"]').click + find('[data-testid="sort-highest-icon"]').click - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(issue1.title) - expect(page.all('.search-result-row').last).to have_link(issue2.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue1.title) + expect(page.all('.search-result-row').last).to have_link(issue2.title) end + end - context 'when on a project page' do - it 'finds an issue' do - find('[data-testid="project-filter"]').click + context 'when on a project page' do + it 'finds an issue' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - search_for_issue(issue1.title) + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end end end + end - context 'when signed out' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - end - - context 'when block_anonymous_global_searches is disabled' do - let_it_be(:project) { create(:project, :public) } + context 'when signed out' do + context 'when block_anonymous_global_searches is disabled' do + let_it_be(:project) { create(:project, :public) } - before do - stub_feature_flags(block_anonymous_global_searches: false) + before do + stub_feature_flags(block_anonymous_global_searches: false) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' + include_examples 'top right search form' - it 'finds an issue' do - search_for_issue(issue1.title) + it 'finds an issue' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end end + end - context 'when block_anonymous_global_searches is enabled' do - it 'is redirected to login page' do - visit(search_path) + context 'when block_anonymous_global_searches is enabled' do + it 'is redirected to login page' do + visit(search_path) - expect(page).to have_content('You must be logged in to search across all of GitLab') - end + expect(page).to have_content('You must be logged in to search across all of GitLab') end end end diff --git a/spec/features/search/user_searches_for_merge_requests_spec.rb b/spec/features/search/user_searches_for_merge_requests_spec.rb index 69f62a4c1e2..d7b52d9e07a 100644 --- a/spec/features/search/user_searches_for_merge_requests_spec.rb +++ b/spec/features/search/user_searches_for_merge_requests_spec.rb @@ -3,12 +3,10 @@ require 'spec_helper' RSpec.describe 'User searches for merge requests', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - - let(:user) { create(:user) } - let(:project) { create(:project, namespace: user.namespace) } - let!(:merge_request1) { create(:merge_request, title: 'Merge Request Foo', source_project: project, target_project: project, created_at: 1.hour.ago) } - let!(:merge_request2) { create(:merge_request, :simple, title: 'Merge Request Bar', source_project: project, target_project: project) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, namespace: user.namespace) } + let_it_be(:merge_request1) { create(:merge_request, title: 'Merge Request Foo', source_project: project, target_project: project, created_at: 1.hour.ago) } + let_it_be(:merge_request2) { create(:merge_request, :simple, title: 'Merge Request Bar', source_project: project, target_project: project) } def search_for_mr(search) fill_in('dashboard_search', with: search) @@ -16,64 +14,60 @@ RSpec.describe 'User searches for merge requests', :js, :clean_gitlab_redis_rate select_search_scope('Merge requests') end - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - sign_in(user) + before do + sign_in(user) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' - include_examples 'search timeouts', 'merge_requests' + include_examples 'top right search form' + include_examples 'search timeouts', 'merge_requests' - it 'finds a merge request' do - search_for_mr(merge_request1.title) + it 'finds a merge request' do + search_for_mr(merge_request1.title) - page.within('.results') do - expect(page).to have_link(merge_request1.title) - expect(page).not_to have_link(merge_request2.title) + page.within('.results') do + expect(page).to have_link(merge_request1.title) + expect(page).not_to have_link(merge_request2.title) - # Each result should have MR refs like `gitlab-org/gitlab!1` - page.all('.search-result-row').each do |e| - expect(e.text).to match(/!\d+/) - end + # Each result should have MR refs like `gitlab-org/gitlab!1` + page.all('.search-result-row').each do |e| + expect(e.text).to match(/!\d+/) end end + end - it 'sorts by created date' do - search_for_mr('Merge Request') + it 'sorts by created date' do + search_for_mr('Merge Request') - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(merge_request2.title) - expect(page.all('.search-result-row').last).to have_link(merge_request1.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(merge_request2.title) + expect(page.all('.search-result-row').last).to have_link(merge_request1.title) + end - find('[data-testid="sort-highest-icon"]').click + find('[data-testid="sort-highest-icon"]').click - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(merge_request1.title) - expect(page.all('.search-result-row').last).to have_link(merge_request2.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(merge_request1.title) + expect(page.all('.search-result-row').last).to have_link(merge_request2.title) end + end - context 'when on a project page' do - it 'finds a merge request' do - find('[data-testid="project-filter"]').click + context 'when on a project page' do + it 'finds a merge request' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - search_for_mr(merge_request1.title) + search_for_mr(merge_request1.title) - page.within('.results') do - expect(page).to have_link(merge_request1.title) - expect(page).not_to have_link(merge_request2.title) - end + page.within('.results') do + expect(page).to have_link(merge_request1.title) + expect(page).not_to have_link(merge_request2.title) end end end diff --git a/spec/features/search/user_searches_for_milestones_spec.rb b/spec/features/search/user_searches_for_milestones_spec.rb index e87c2176380..238e59be940 100644 --- a/spec/features/search/user_searches_for_milestones_spec.rb +++ b/spec/features/search/user_searches_for_milestones_spec.rb @@ -4,29 +4,42 @@ require 'spec_helper' RSpec.describe 'User searches for milestones', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: user.namespace) } + let_it_be(:milestone1) { create(:milestone, title: 'Foo', project: project) } + let_it_be(:milestone2) { create(:milestone, title: 'Bar', project: project) } + + before do + project.add_maintainer(user) + sign_in(user) - let!(:milestone1) { create(:milestone, title: 'Foo', project: project) } - let!(:milestone2) { create(:milestone, title: 'Bar', project: project) } + visit(search_path) + end - where(search_page_vertical_nav_enabled: [true, false]) + include_examples 'top right search form' + include_examples 'search timeouts', 'milestones' - with_them do - before do - project.add_maintainer(user) - sign_in(user) - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) + it 'finds a milestone' do + fill_in('dashboard_search', with: milestone1.title) + find('.gl-search-box-by-click-search-button').click + select_search_scope('Milestones') - visit(search_path) + page.within('.results') do + expect(page).to have_link(milestone1.title) + expect(page).not_to have_link(milestone2.title) end + end - include_examples 'top right search form' - include_examples 'search timeouts', 'milestones' - + context 'when on a project page' do it 'finds a milestone' do + find('[data-testid="project-filter"]').click + + wait_for_requests + + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end + fill_in('dashboard_search', with: milestone1.title) find('.gl-search-box-by-click-search-button').click select_search_scope('Milestones') @@ -36,26 +49,5 @@ feature_category: :global_search do expect(page).not_to have_link(milestone2.title) end end - - context 'when on a project page' do - it 'finds a milestone' do - find('[data-testid="project-filter"]').click - - wait_for_requests - - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end - - fill_in('dashboard_search', with: milestone1.title) - find('.gl-search-box-by-click-search-button').click - select_search_scope('Milestones') - - page.within('.results') do - expect(page).to have_link(milestone1.title) - expect(page).not_to have_link(milestone2.title) - end - end - end end end diff --git a/spec/features/search/user_searches_for_users_spec.rb b/spec/features/search/user_searches_for_users_spec.rb index 4737cef98c7..e0a07c5103d 100644 --- a/spec/features/search/user_searches_for_users_spec.rb +++ b/spec/features/search/user_searches_for_users_spec.rb @@ -7,85 +7,80 @@ RSpec.describe 'User searches for users', :js, :clean_gitlab_redis_rate_limiting let_it_be(:user2) { create(:user, username: 'michael_bluth', name: 'Michael Bluth') } let_it_be(:user3) { create(:user, username: 'gob_2018', name: 'George Oscar Bluth') } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - - sign_in(user1) - end + before do + sign_in(user1) + end - include_examples 'search timeouts', 'users' do - before do - visit(search_path) - end + include_examples 'search timeouts', 'users' do + before do + visit(search_path) end + end - context 'when on the dashboard' do - it 'finds the user' do - visit dashboard_projects_path + context 'when on the dashboard' do + it 'finds the user' do + visit dashboard_projects_path - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') - end + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') end end + end - context 'when on the project page' do - let_it_be_with_reload(:project) { create(:project) } + context 'when on the project page' do + let_it_be_with_reload(:project) { create(:project) } - before do - project.add_developer(user1) - project.add_developer(user2) - end + before do + project.add_developer(user1) + project.add_developer(user2) + end - it 'finds the user belonging to the project' do - visit project_path(project) + it 'finds the user belonging to the project' do + visit project_path(project) - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') - expect(page).not_to have_content('Michael Bluth') - expect(page).not_to have_content('@michael_bluth') + expect(page).not_to have_content('Michael Bluth') + expect(page).not_to have_content('@michael_bluth') - expect(page).not_to have_content('George Oscar Bluth') - expect(page).not_to have_content('@gob_2018') - end + expect(page).not_to have_content('George Oscar Bluth') + expect(page).not_to have_content('@gob_2018') end end + end - context 'when on the group page' do - let(:group) { create(:group) } + context 'when on the group page' do + let(:group) { create(:group) } - before do - group.add_developer(user1) - group.add_developer(user2) - end + before do + group.add_developer(user1) + group.add_developer(user2) + end - it 'finds the user belonging to the group' do - visit group_path(group) + it 'finds the user belonging to the group' do + visit group_path(group) - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') - expect(page).not_to have_content('Michael Bluth') - expect(page).not_to have_content('@michael_bluth') + expect(page).not_to have_content('Michael Bluth') + expect(page).not_to have_content('@michael_bluth') - expect(page).not_to have_content('George Oscar Bluth') - expect(page).not_to have_content('@gob_2018') - end + expect(page).not_to have_content('George Oscar Bluth') + expect(page).not_to have_content('@gob_2018') end end end diff --git a/spec/features/search/user_searches_for_wiki_pages_spec.rb b/spec/features/search/user_searches_for_wiki_pages_spec.rb index c7dc3e34bb7..1d8bdc58ce6 100644 --- a/spec/features/search/user_searches_for_wiki_pages_spec.rb +++ b/spec/features/search/user_searches_for_wiki_pages_spec.rb @@ -4,58 +4,53 @@ require 'spec_helper' RSpec.describe 'User searches for wiki pages', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } + let_it_be(:wiki_page) do + create(:wiki_page, wiki: project.wiki, title: 'directory/title', content: 'Some Wiki content') + end - let(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } - let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, title: 'directory/title', content: 'Some Wiki content') } - - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_maintainer(user) - sign_in(user) + before do + project.add_maintainer(user) + sign_in(user) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' - include_examples 'search timeouts', 'wiki_blobs' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'top right search form' + include_examples 'search timeouts', 'wiki_blobs' do + let(:additional_params) { { project_id: project.id } } + end - shared_examples 'search wiki blobs' do - it 'finds a page' do - find('[data-testid="project-filter"]').click + shared_examples 'search wiki blobs' do + it 'finds a page' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - fill_in('dashboard_search', with: search_term) - find('.gl-search-box-by-click-search-button').click - select_search_scope('Wiki') + fill_in('dashboard_search', with: search_term) + find('.gl-search-box-by-click-search-button').click + select_search_scope('Wiki') - page.within('.results') do - expect(page).to have_link(wiki_page.title, href: project_wiki_path(project, wiki_page.slug)) - end + page.within('.results') do + expect(page).to have_link(wiki_page.title, href: project_wiki_path(project, wiki_page.slug)) end end + end - context 'when searching by content' do - it_behaves_like 'search wiki blobs' do - let(:search_term) { 'content' } - end + context 'when searching by content' do + it_behaves_like 'search wiki blobs' do + let(:search_term) { 'content' } end + end - context 'when searching by title' do - it_behaves_like 'search wiki blobs' do - let(:search_term) { 'title' } - end + context 'when searching by title' do + it_behaves_like 'search wiki blobs' do + let(:search_term) { 'title' } end end end diff --git a/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap b/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap deleted file mode 100644 index ce456d6c899..00000000000 --- a/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`pages/search/show/refresh_counts fetches and displays search counts 1`] = ` -"<div class=\\"badge\\">22</div> -<div class=\\"badge js-search-count\\" data-url=\\"http://test.host/search/count?search=lorem+ipsum&project_id=3&scope=issues\\">4</div> -<div class=\\"badge js-search-count\\" data-url=\\"http://test.host/search/count?search=lorem+ipsum&project_id=3&scope=merge_requests\\">5</div>" -`; diff --git a/spec/frontend/pages/search/show/refresh_counts_spec.js b/spec/frontend/pages/search/show/refresh_counts_spec.js deleted file mode 100644 index 6f14f0c70bd..00000000000 --- a/spec/frontend/pages/search/show/refresh_counts_spec.js +++ /dev/null @@ -1,43 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import { TEST_HOST } from 'helpers/test_constants'; -import axios from '~/lib/utils/axios_utils'; -import refreshCounts from '~/pages/search/show/refresh_counts'; - -const URL = `${TEST_HOST}/search/count?search=lorem+ipsum&project_id=3`; -const urlWithScope = (scope) => `${URL}&scope=${scope}`; -const counts = [ - { scope: 'issues', count: 4 }, - { scope: 'merge_requests', count: 5 }, -]; -const fixture = `<div class="badge">22</div> -<div class="badge js-search-count hidden" data-url="${urlWithScope('issues')}"></div> -<div class="badge js-search-count hidden" data-url="${urlWithScope('merge_requests')}"></div>`; - -describe('pages/search/show/refresh_counts', () => { - let mock; - - beforeEach(() => { - mock = new MockAdapter(axios); - setHTMLFixture(fixture); - }); - - afterEach(() => { - resetHTMLFixture(); - }); - - afterEach(() => { - mock.restore(); - }); - - it('fetches and displays search counts', () => { - counts.forEach(({ scope, count }) => { - mock.onGet(urlWithScope(scope)).reply(200, { count }); - }); - - // assert before act behavior - return refreshCounts().then(() => { - expect(document.body.innerHTML).toMatchSnapshot(); - }); - }); -}); diff --git a/spec/frontend/search/sidebar/components/app_spec.js b/spec/frontend/search/sidebar/components/app_spec.js index e87217950cd..6aa40b7a2be 100644 --- a/spec/frontend/search/sidebar/components/app_spec.js +++ b/spec/frontend/search/sidebar/components/app_spec.js @@ -84,23 +84,14 @@ describe('GlobalSearchSidebar', () => { expect(findFilters().exists()).toBe(true); }); }); - }); - - describe('when search_page_vertical_nav is enabled', () => { - beforeEach(() => { - createComponent({}, { searchPageVerticalNav: true }); - }); - it('shows the vertical navigation', () => { - expect(findSidebarNavigation().exists()).toBe(true); - }); - }); - describe('when search_page_vertical_nav is disabled', () => { - beforeEach(() => { - createComponent({}, { searchPageVerticalNav: false }); - }); - it('hides the vertical navigation', () => { - expect(findSidebarNavigation().exists()).toBe(false); + describe('renders navigation', () => { + beforeEach(() => { + createComponent({}); + }); + it('shows the vertical navigation', () => { + expect(findSidebarNavigation().exists()).toBe(true); + }); }); }); }); diff --git a/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js b/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js index d5ecca4636c..4f146757454 100644 --- a/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js +++ b/spec/frontend/search/sidebar/components/confidentiality_filter_spec.js @@ -22,24 +22,4 @@ describe('ConfidentialityFilter', () => { expect(findRadioFilter().exists()).toBe(true); }); }); - - describe.each` - hasFeatureFlagEnabled | paddingClass - ${true} | ${'gl-px-5'} - ${false} | ${'gl-px-0'} - `(`RadioFilter`, ({ hasFeatureFlagEnabled, paddingClass }) => { - beforeEach(() => { - createComponent({ - provide: { - glFeatures: { - searchPageVerticalNav: hasFeatureFlagEnabled, - }, - }, - }); - }); - - it(`has ${paddingClass} class`, () => { - expect(findRadioFilter().classes(paddingClass)).toBe(true); - }); - }); }); diff --git a/spec/frontend/search/sidebar/components/status_filter_spec.js b/spec/frontend/search/sidebar/components/status_filter_spec.js index 2ed199469e6..6704634ef36 100644 --- a/spec/frontend/search/sidebar/components/status_filter_spec.js +++ b/spec/frontend/search/sidebar/components/status_filter_spec.js @@ -22,24 +22,4 @@ describe('StatusFilter', () => { expect(findRadioFilter().exists()).toBe(true); }); }); - - describe.each` - hasFeatureFlagEnabled | paddingClass - ${true} | ${'gl-px-5'} - ${false} | ${'gl-px-0'} - `(`RadioFilter`, ({ hasFeatureFlagEnabled, paddingClass }) => { - beforeEach(() => { - createComponent({ - provide: { - glFeatures: { - searchPageVerticalNav: hasFeatureFlagEnabled, - }, - }, - }); - }); - - it(`has ${paddingClass} class`, () => { - expect(findRadioFilter().classes(paddingClass)).toBe(true); - }); - }); }); diff --git a/spec/helpers/bizible_helper_spec.rb b/spec/helpers/bizible_helper_spec.rb index b82211d51ec..c1b79a8e1e2 100644 --- a/spec/helpers/bizible_helper_spec.rb +++ b/spec/helpers/bizible_helper_spec.rb @@ -4,43 +4,43 @@ require "spec_helper" RSpec.describe BizibleHelper do describe '#bizible_enabled?' do - before do - stub_config(extra: { bizible: SecureRandom.uuid }) - end - - context 'when bizible is disabled' do + context 'when bizible config is not true' do before do - allow(helper).to receive(:bizible_enabled?).and_return(false) + stub_config(extra: { bizible: false }) end - it { is_expected.to be_falsey } + it { expect(helper.bizible_enabled?).to be_falsy } end - context 'when bizible is enabled' do + context 'when bizible config is enabled' do before do - allow(helper).to receive(:bizible_enabled?).and_return(true) + stub_config(extra: { bizible: true }) end - it { is_expected.to be_truthy } - end + it { expect(helper.bizible_enabled?).to be_truthy } - subject(:bizible_enabled?) { helper.bizible_enabled? } + context 'with ecomm_instrumentation feature flag disabled' do + before do + stub_feature_flags(ecomm_instrumentation: false) + end - context 'with ecomm_instrumentation feature flag disabled' do - before do - stub_feature_flags(ecomm_instrumentation: false) + it { expect(helper.bizible_enabled?).to be_falsey } end - it { is_expected.to be_falsey } - end + context 'with ecomm_instrumentation feature flag enabled' do + before do + stub_feature_flags(ecomm_instrumentation: true) + end + + it { expect(helper.bizible_enabled?).to be_truthy } + end - context 'with ecomm_instrumentation feature flag enabled' do - context 'when no id is set' do + context 'with invite_email present' do before do - stub_config(extra: {}) + stub_feature_flags(ecomm_instrumentation: true) end - it { is_expected.to be_falsey } + it { expect(helper.bizible_enabled?('test@test.com')).to be_falsy } end end end diff --git a/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb index 9373888aada..df18e1e4f48 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities, feature_category: :pipeline_execution do +RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities, feature_category: :continuous_integration do let(:project) { create(:project, :test_repo) } let_it_be(:user) { create(:user) } diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 47430dc6651..ec5c90b45ca 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -31,6 +31,7 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration do it { is_expected.to have_many(:pages_deployments).with_foreign_key(:ci_build_id) } it { is_expected.to have_one(:deployment) } + it { is_expected.to have_one(:runner_machine).through(:metadata) } it { is_expected.to have_one(:runner_session).with_foreign_key(:build_id) } it { is_expected.to have_one(:trace_metadata).with_foreign_key(:build_id) } it { is_expected.to have_one(:runtime_metadata).with_foreign_key(:build_id) } @@ -2047,6 +2048,16 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration do end end + describe '#runner_machine' do + let_it_be(:runner) { create(:ci_runner) } + let_it_be(:runner_machine) { create(:ci_runner_machine, runner: runner) } + let_it_be(:build) { create(:ci_build, runner_machine: runner_machine) } + + subject(:build_runner_machine) { described_class.find(build.id).runner_machine } + + it { is_expected.to eq(runner_machine) } + end + describe '#tag_list' do let_it_be(:build) { create(:ci_build, tag_list: ['tag']) } @@ -5781,4 +5792,43 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration do expect(build.metadata.partition_id).to eq(ci_testing_partition_id) end end + + describe 'secrets management id_tokens usage data' do + context 'when ID tokens are defined' do + let(:ci_build) { FactoryBot.build(:ci_build, user: user, id_tokens: { 'ID_TOKEN_1' => { aud: 'developers' } }) } + + context 'on create' do + it 'tracks event with user_id' do + expect(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event) + .with('i_ci_secrets_management_id_tokens_build_created', values: user.id) + + ci_build.save! + end + end + + context 'on update' do + before do + ci_build.save! + end + + it 'does not track event' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) + + ci_build.success + end + end + end + + context 'when ID tokens are not defined' do + let(:ci_build) { FactoryBot.build(:ci_build, user: user) } + + context 'on create' do + it 'does not track event' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) + + ci_build.save! + end + end + end + end end diff --git a/spec/models/ci/processable_spec.rb b/spec/models/ci/processable_spec.rb index 89ed8ab3fa7..db22d8f3a6c 100644 --- a/spec/models/ci/processable_spec.rb +++ b/spec/models/ci/processable_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::Processable do +RSpec.describe Ci::Processable, feature_category: :continuous_integration do let_it_be(:project) { create(:project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } @@ -83,7 +83,7 @@ RSpec.describe Ci::Processable do runner_id tag_taggings taggings tags trigger_request_id user_id auto_canceled_by_id retried failure_reason sourced_pipelines sourced_pipeline artifacts_file_store artifacts_metadata_store - metadata runner_session trace_chunks upstream_pipeline_id + metadata runner_machine_id runner_machine runner_session trace_chunks upstream_pipeline_id artifacts_file artifacts_metadata artifacts_size commands resource resource_group_id processed security_scans author pipeline_id report_results pending_state pages_deployments diff --git a/spec/models/ci/runner_machine_spec.rb b/spec/models/ci/runner_machine_spec.rb index c658058c131..530b3ff2e8d 100644 --- a/spec/models/ci/runner_machine_spec.rb +++ b/spec/models/ci/runner_machine_spec.rb @@ -6,7 +6,9 @@ RSpec.describe Ci::RunnerMachine, feature_category: :runner_fleet, type: :model it_behaves_like 'having unique enum values' it { is_expected.to belong_to(:runner) } + it { is_expected.to belong_to(:runner_version).with_foreign_key(:version) } it { is_expected.to have_many(:build_metadata) } + it { is_expected.to have_many(:builds).through(:build_metadata) } describe 'validation' do it { is_expected.to validate_presence_of(:runner) } diff --git a/spec/models/ci/runner_version_spec.rb b/spec/models/ci/runner_version_spec.rb index dfaa2201859..3e987c8309a 100644 --- a/spec/models/ci/runner_version_spec.rb +++ b/spec/models/ci/runner_version_spec.rb @@ -11,6 +11,8 @@ RSpec.describe Ci::RunnerVersion, feature_category: :runner_fleet do create(:ci_runner_version, version: 'abc123', status: :not_available) end + it { is_expected.to have_many(:runner_machines).with_foreign_key(:version) } + it_behaves_like 'having unique enum values' describe '.not_available' do diff --git a/spec/requests/projects/blob_spec.rb b/spec/requests/projects/blob_spec.rb new file mode 100644 index 00000000000..7d62619e76a --- /dev/null +++ b/spec/requests/projects/blob_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Blobs', feature_category: :source_code_management do + let_it_be(:project) { create(:project, :public, :repository, lfs: true) } + + describe 'GET /:namespace_id/:project_id/-/blob/:id' do + subject(:request) do + get namespace_project_blob_path(namespace_id: project.namespace, project_id: project, id: id) + end + + context 'with LFS file' do + let(:id) { 'master/files/lfs/lfs_object.iso' } + let(:object_store_host) { 'http://127.0.0.1:9000' } + let(:connect_src) do + csp = response.headers['Content-Security-Policy'] + csp.split('; ').find { |src| src.starts_with?('connect-src') } + end + + let(:gitlab_config) do + Gitlab.config.gitlab.deep_merge( + 'content_security_policy' => { + 'enabled' => content_security_policy_enabled + } + ) + end + + let(:lfs_config) do + Gitlab.config.lfs.deep_merge( + 'enabled' => lfs_enabled, + 'object_store' => { + 'remote_directory' => 'lfs-objects', + 'enabled' => true, + 'proxy_download' => proxy_download, + 'connection' => { + 'endpoint' => object_store_host, + 'path_style' => true + } + } + ) + end + + before do + stub_config_setting(gitlab_config) + stub_lfs_setting(lfs_config) + stub_lfs_object_storage(proxy_download: proxy_download) + + request + end + + describe 'directly downloading lfs file' do + let(:lfs_enabled) { true } + let(:proxy_download) { false } + let(:content_security_policy_enabled) { true } + + it { expect(response).to have_gitlab_http_status(:success) } + + it { expect(connect_src).to include(object_store_host) } + + context 'when lfs is disabled' do + let(:lfs_enabled) { false } + + it { expect(response).to have_gitlab_http_status(:success) } + + it { expect(connect_src).not_to include(object_store_host) } + end + + context 'when content_security_policy is disabled' do + let(:content_security_policy_enabled) { false } + + it { expect(response).to have_gitlab_http_status(:success) } + + it { expect(connect_src).not_to include(object_store_host) } + end + + context 'when proxy download is enabled' do + let(:proxy_download) { true } + + it { expect(response).to have_gitlab_http_status(:success) } + + it { expect(connect_src).not_to include(object_store_host) } + end + end + end + end +end diff --git a/spec/tasks/gitlab/usage_data_rake_spec.rb b/spec/tasks/gitlab/usage_data_rake_spec.rb index 4e84018d5ff..72f284b0b7f 100644 --- a/spec/tasks/gitlab/usage_data_rake_spec.rb +++ b/spec/tasks/gitlab/usage_data_rake_spec.rb @@ -78,7 +78,8 @@ RSpec.describe 'gitlab:usage data take tasks', :silence_stdout, feature_category `git checkout -- #{Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH}` end - it "generates #{Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH}" do + it "generates #{Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH}", + quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/386191' do run_rake_task('gitlab:usage_data:generate_ci_template_events') expect(File.exist?(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH)).to be true diff --git a/spec/views/search/_results.html.haml_spec.rb b/spec/views/search/_results.html.haml_spec.rb index de994a0da2b..ed71a03c7e0 100644 --- a/spec/views/search/_results.html.haml_spec.rb +++ b/spec/views/search/_results.html.haml_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe 'search/_results', feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let(:search_objects) { Issue.page(1).per(2) } @@ -32,30 +30,22 @@ RSpec.describe 'search/_results', feature_category: :global_search do assign(:search_service_presenter, search_service_presenter) end - where(search_page_vertical_nav_enabled: [true, false]) + describe 'page size' do + context 'when search results have a count' do + it 'displays the page size' do + render - with_them do - describe 'page size' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - end - - context 'when search results have a count' do - it 'displays the page size' do - render - - expect(rendered).to have_content('Showing 1 - 2 of 3 issues for foo') - end + expect(rendered).to have_content('Showing 1 - 2 of 3 issues for foo') end + end - context 'when search results do not have a count' do - let(:search_objects) { Issue.page(1).per(2).without_count } + context 'when search results do not have a count' do + let(:search_objects) { Issue.page(1).per(2).without_count } - it 'does not display the page size' do - render + it 'does not display the page size' do + render - expect(rendered).not_to have_content(/Showing .* of .*/) - end + expect(rendered).not_to have_content(/Showing .* of .*/) end end end diff --git a/spec/views/search/show.html.haml_spec.rb b/spec/views/search/show.html.haml_spec.rb index 6adb2c77c4d..db06adfeb6b 100644 --- a/spec/views/search/show.html.haml_spec.rb +++ b/spec/views/search/show.html.haml_spec.rb @@ -10,122 +10,96 @@ RSpec.describe 'search/show', feature_category: :global_search do end before do - stub_template "search/_category.html.haml" => 'Category Partial' stub_template "search/_results.html.haml" => 'Results Partial' + allow(view).to receive(:current_user) { user } + assign(:search_service_presenter, search_service_presenter) + assign(:search_term, search_term) end - context 'search_page_vertical_nav feature flag enabled' do - before do - allow(view).to receive(:current_user) { user } - assign(:search_term, search_term) + context 'when search term is supplied' do + let(:search_term) { 'Search Foo' } + + it 'renders the results partial' do + render + + expect(rendered).to render_template('search/_results') end + end - context 'when search term is supplied' do - let(:search_term) { 'Search Foo' } + context 'when the search page is opened' do + it 'displays the title' do + render - it 'will not render category partial' do - render + expect(rendered).to have_selector('h1.page-title', text: 'Search') + expect(rendered).not_to have_selector('h1.page-title code') + end - expect(rendered).not_to render_template('search/_category') - expect(rendered).to render_template('search/_results') - end + it 'does not render the results partial' do + render + + expect(rendered).not_to render_template('search/_results') end end - context 'search_page_vertical_nav feature flag disabled' do - before do - stub_feature_flags(search_page_vertical_nav: false) + context 'unfurling support' do + let(:group) { build(:group) } + let(:search_results) do + instance_double(Gitlab::GroupSearchResults).tap do |double| + allow(double).to receive(:formatted_count).and_return(0) + end + end - assign(:search_term, search_term) + before do + assign(:search_results, search_results) + assign(:scope, 'issues') + assign(:group, group) end - context 'when the search page is opened' do - it 'displays the title' do + context 'search with full count' do + let(:search_service_presenter) do + instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false) + end + + it 'renders meta tags for a group' do render - expect(rendered).to have_selector('h1.page-title', text: 'Search') - expect(rendered).not_to have_selector('h1.page-title code') + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path) end - it 'does not render partials' do + it 'renders meta tags for both group and project' do + project = build(:project, group: group) + assign(:project, project) + render - expect(rendered).not_to render_template('search/_category') - expect(rendered).not_to render_template('search/_results') + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) end end - context 'when search term is supplied' do - let(:search_term) { 'Search Foo' } + context 'search without full count' do + let(:search_service_presenter) do + instance_double(SearchServicePresenter, without_count?: true, advanced_search_enabled?: false) + end - it 'renders partials' do + it 'renders meta tags for a group' do render - expect(rendered).to render_template('search/_category') - expect(rendered).to render_template('search/_results') + expect(view.page_description).to match(/issues results for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path) end - context 'unfurling support' do - let(:group) { build(:group) } - let(:search_results) do - instance_double(Gitlab::GroupSearchResults).tap do |double| - allow(double).to receive(:formatted_count).and_return(0) - end - end - - before do - assign(:search_results, search_results) - assign(:scope, 'issues') - assign(:group, group) - end - - context 'search with full count' do - let(:search_service_presenter) do - instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false) - end - - it 'renders meta tags for a group' do - render - - expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path) - end - - it 'renders meta tags for both group and project' do - project = build(:project, group: group) - assign(:project, project) - - render - - expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) - end - end - - context 'search without full count' do - let(:search_service_presenter) do - instance_double(SearchServicePresenter, without_count?: true, advanced_search_enabled?: false) - end - - it 'renders meta tags for a group' do - render - - expect(view.page_description).to match(/issues results for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path) - end - - it 'renders meta tags for both group and project' do - project = build(:project, group: group) - assign(:project, project) - - render - - expect(view.page_description).to match(/issues results for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) - end - end + it 'renders meta tags for both group and project' do + project = build(:project, group: group) + assign(:project, project) + + render + + expect(view.page_description).to match(/issues results for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) end end end |