diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-25 15:10:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-25 15:10:30 +0000 |
commit | d5fa3bac88ff4b8c5870d6d7988fc7e37832c183 (patch) | |
tree | 7fb663cbbaa98fb55d322f91e549ee6b6711a4f2 /spec | |
parent | cc1e91be1cd930f58baebb89f2ff1893045a2aea (diff) | |
download | gitlab-ce-d5fa3bac88ff4b8c5870d6d7988fc7e37832c183.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
16 files changed, 222 insertions, 31 deletions
diff --git a/spec/channels/application_cable/connection_spec.rb b/spec/channels/application_cable/connection_spec.rb index f5b2cdd2fca..4943669bde0 100644 --- a/spec/channels/application_cable/connection_spec.rb +++ b/spec/channels/application_cable/connection_spec.rb @@ -21,7 +21,7 @@ RSpec.describe ApplicationCable::Connection, :clean_gitlab_redis_sessions do end context 'with a stale password' do - let(:partial_password_hash) { build(:user, password: 'some_old_password').authenticatable_salt } + let(:partial_password_hash) { build(:user, password: User.random_password).authenticatable_salt } let(:session_hash) { { 'warden.user.user.key' => [[user.id], partial_password_hash] } } it 'sets current_user to nil' do diff --git a/spec/controllers/projects/pages_controller_spec.rb b/spec/controllers/projects/pages_controller_spec.rb index 1fa8838b548..136f98ac907 100644 --- a/spec/controllers/projects/pages_controller_spec.rb +++ b/spec/controllers/projects/pages_controller_spec.rb @@ -19,9 +19,9 @@ RSpec.describe Projects::PagesController do project.add_maintainer(user) end - describe 'GET show' do + describe 'GET new' do it 'returns 200 status' do - get :show, params: request_params + get :new, params: request_params expect(response).to have_gitlab_http_status(:ok) end @@ -31,13 +31,55 @@ RSpec.describe Projects::PagesController do let(:project) { create(:project, namespace: group) } it 'returns a 200 status code' do - get :show, params: request_params + get :new, params: request_params expect(response).to have_gitlab_http_status(:ok) end end end + describe 'GET show' do + subject { get :show, params: request_params } + + context 'when the project does not have onboarding complete' do + before do + project.pages_metadatum.update_attribute(:deployed, false) + project.pages_metadatum.update_attribute(:onboarding_complete, false) + end + + it 'redirects to #new' do + expect(subject).to redirect_to(action: 'new') + end + end + + context 'when the project does have onboarding complete' do + before do + project.pages_metadatum.update_attribute(:onboarding_complete, true) + end + + it 'returns 200 status' do + expect(subject).to have_gitlab_http_status(:ok) + end + + context 'when the project is in a subgroup' do + let(:group) { create(:group, :nested) } + let(:project) { create(:project, namespace: group) } + + it 'returns a 200 status code' do + expect(subject).to have_gitlab_http_status(:ok) + end + end + end + + context 'when pages is disabled' do + let(:project) { create(:project, :pages_disabled) } + + it 'renders the disabled view' do + expect(subject).to render_template :disabled + end + end + end + describe 'DELETE destroy' do it 'returns 302 status' do delete :destroy, params: request_params diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index d60512e2b2a..5c8f5d1a603 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -404,6 +404,13 @@ FactoryBot.define do end end + trait :pages_published do + after(:create) do |project| + project.mark_pages_onboarding_complete + project.mark_pages_as_deployed + end + end + trait :service_desk_disabled do service_desk_enabled { nil } end diff --git a/spec/features/projects/pages/user_adds_domain_spec.rb b/spec/features/projects/pages/user_adds_domain_spec.rb index afa3f29ce0d..5cb4fa163c8 100644 --- a/spec/features/projects/pages/user_adds_domain_spec.rb +++ b/spec/features/projects/pages/user_adds_domain_spec.rb @@ -5,7 +5,7 @@ RSpec.describe 'User adds pages domain', :js do include LetsEncryptHelpers include Spec::Support::Helpers::ModalHelpers - let_it_be(:project) { create(:project, pages_https_only: false) } + let_it_be(:project) { create(:project, :pages_published, pages_https_only: false) } let(:user) { create(:user) } @@ -18,8 +18,6 @@ RSpec.describe 'User adds pages domain', :js do end context 'when pages are exposed on external HTTP address', :http_pages_enabled do - let(:project) { create(:project, pages_https_only: false) } - shared_examples 'adds new domain' do it 'adds new domain' do visit new_project_pages_domain_path(project) @@ -42,7 +40,7 @@ RSpec.describe 'User adds pages domain', :js do context 'when project in group namespace' do it_behaves_like 'adds new domain' do let(:group) { create :group } - let(:project) { create(:project, namespace: group, pages_https_only: false) } + let(:project) { create(:project, :pages_published, namespace: group, pages_https_only: false) } end end diff --git a/spec/features/projects/pages/user_configures_pages_pipeline_spec.rb b/spec/features/projects/pages/user_configures_pages_pipeline_spec.rb new file mode 100644 index 00000000000..029479d6b95 --- /dev/null +++ b/spec/features/projects/pages/user_configures_pages_pipeline_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'Pages edits pages settings', :js do + include Spec::Support::Helpers::ModalHelpers + + let_it_be(:project) { create(:project, pages_https_only: false) } + let_it_be(:user) { create(:user) } + + before do + allow(Gitlab.config.pages).to receive(:enabled).and_return(true) + + project.add_maintainer(user) + + sign_in(user) + end + + context 'when pipeline wizard feature is enabled' do + before do + Feature.enable(:use_pipeline_wizard_for_pages) + end + + context 'when onboarding is not complete' do + it 'renders onboarding instructions' do + visit project_pages_path(project) + + expect(page).to have_content('Get started with Pages') + end + end + + context 'when onboarding is complete' do + before do + project.mark_pages_onboarding_complete + end + + it 'shows waiting screen' do + visit project_pages_path(project) + + expect(page).to have_content('Waiting for the Pages Pipeline to complete...') + end + end + end + + context 'when pipeline wizard feature is disabled' do + before do + Feature.disable(:use_pipeline_wizard_for_pages) + end + + it 'shows configure pages instructions' do + visit project_pages_path(project) + + expect(page).to have_content('Configure pages') + end + + after do + Feature.enable(:use_pipeline_wizard_for_pages) + end + end +end diff --git a/spec/features/projects/pages/user_edits_lets_encrypt_settings_spec.rb b/spec/features/projects/pages/user_edits_lets_encrypt_settings_spec.rb index 4c633bea64e..2e28fa20b90 100644 --- a/spec/features/projects/pages/user_edits_lets_encrypt_settings_spec.rb +++ b/spec/features/projects/pages/user_edits_lets_encrypt_settings_spec.rb @@ -5,7 +5,8 @@ RSpec.describe "Pages with Let's Encrypt", :https_pages_enabled do include LetsEncryptHelpers include Spec::Support::Helpers::ModalHelpers - let(:project) { create(:project, pages_https_only: false) } + let_it_be_with_reload(:project) { create(:project, :pages_published, pages_https_only: false) } + let(:user) { create(:user) } let(:role) { :maintainer } let(:certificate_pem) { attributes_for(:pages_domain)[:certificate] } diff --git a/spec/features/projects/pages/user_edits_settings_spec.rb b/spec/features/projects/pages/user_edits_settings_spec.rb index bd163f4a109..88c27a6adf2 100644 --- a/spec/features/projects/pages/user_edits_settings_spec.rb +++ b/spec/features/projects/pages/user_edits_settings_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' RSpec.describe 'Pages edits pages settings', :js do include Spec::Support::Helpers::ModalHelpers - let(:project) { create(:project, pages_https_only: false) } - let(:user) { create(:user) } + let_it_be_with_reload(:project) { create(:project, :pages_published, pages_https_only: false) } + let_it_be(:user) { create(:user) } before do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) @@ -80,13 +80,6 @@ RSpec.describe 'Pages edits pages settings', :js do end end - it 'does not see anything to destroy' do - visit project_pages_path(project) - - expect(page).to have_content('Configure pages') - expect(page).not_to have_link('Remove pages') - end - describe 'project settings page' do it 'renders "Pages" tab' do visit edit_project_path(project) @@ -151,7 +144,7 @@ RSpec.describe 'Pages edits pages settings', :js do end context 'non-HTTPS domain exists' do - let(:project) { create(:project, pages_https_only: false) } + let(:project) { create(:project, :pages_published, pages_https_only: false) } before do create(:pages_domain, :without_key, :without_certificate, project: project) diff --git a/spec/frontend/pipeline_wizard/components/widgets/checklist_spec.js b/spec/frontend/pipeline_wizard/components/widgets/checklist_spec.js index 43719595c5c..b8e194015b0 100644 --- a/spec/frontend/pipeline_wizard/components/widgets/checklist_spec.js +++ b/spec/frontend/pipeline_wizard/components/widgets/checklist_spec.js @@ -1,4 +1,4 @@ -import { GlFormCheckbox, GlFormCheckboxGroup } from '@gitlab/ui'; +import { GlFormCheckbox, GlFormGroup, GlFormCheckboxGroup } from '@gitlab/ui'; import { nextTick } from 'vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import ChecklistWidget from '~/pipeline_wizard/components/widgets/checklist.vue'; @@ -21,6 +21,7 @@ describe('Pipeline Wizard - Checklist Widget', () => { return eventArray[eventArray.length - 1]; }; const findItem = (atIndex = 0) => wrapper.findAllComponents(GlFormCheckbox).at(atIndex); + const getGlFormGroup = () => wrapper.getComponent(GlFormGroup); const getGlFormCheckboxGroup = () => wrapper.getComponent(GlFormCheckboxGroup); // The item.ids *can* be passed inside props.items, but are usually @@ -57,6 +58,16 @@ describe('Pipeline Wizard - Checklist Widget', () => { expect(findItem().text()).toBe(props.items[0]); }); + it('assigns the same non-null value to label-for and form id', () => { + createComponent(); + const formGroupLabelFor = getGlFormGroup().attributes('label-for'); + const formCheckboxGroupId = getGlFormCheckboxGroup().attributes('id'); + + expect(formGroupLabelFor).not.toBeNull(); + expect(formCheckboxGroupId).not.toBeNull(); + expect(formGroupLabelFor).toBe(formCheckboxGroupId); + }); + it('displays an item with a help text', () => { createComponent(); const { text, help } = props.items[1]; diff --git a/spec/graphql/types/work_item_type_spec.rb b/spec/graphql/types/work_item_type_spec.rb index 7ed58786b5b..153934c374c 100644 --- a/spec/graphql/types/work_item_type_spec.rb +++ b/spec/graphql/types/work_item_type_spec.rb @@ -11,6 +11,7 @@ RSpec.describe GitlabSchema.types['WorkItem'] do it 'has specific fields' do fields = %i[ + confidential description description_html id diff --git a/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb index 09d2919c6c4..76f2dd4b659 100644 --- a/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb @@ -10,9 +10,9 @@ RSpec.describe Banzai::Pipeline::IncidentManagement::TimelineEventPipeline do expect(described_class.filters).to eq( [ *Banzai::Pipeline::PlainMarkdownPipeline.filters, + Banzai::Filter::SanitizationFilter, *Banzai::Pipeline::GfmPipeline.reference_filters, Banzai::Filter::EmojiFilter, - Banzai::Filter::SanitizationFilter, Banzai::Filter::ExternalLinkFilter, Banzai::Filter::ImageLinkFilter ] @@ -62,7 +62,32 @@ RSpec.describe Banzai::Pipeline::IncidentManagement::TimelineEventPipeline do context 'when markdown contains emojis' do let(:markdown) { ':+1:👍' } - it { is_expected.to eq('<p>👍👍</p>') } + it 'renders emojis wrapped in <gl-emoji> tag' do + # rubocop:disable Layout/LineLength + is_expected.to eq( + %q(<p><gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji><gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji></p>) + ) + # rubocop:enable Layout/LineLength + end + end + + context 'when markdown contains labels' do + let(:label) { create(:label, project: project, title: 'backend') } + let(:markdown) { %Q(~"#{label.name}" ~unknown) } + + it 'replaces existing label to a link' do + # rubocop:disable Layout/LineLength + is_expected.to match( + %r(<p>.+<a href=\"[\w/]+-/issues\?label_name=#{label.name}\".+style=\"background-color: #\d{6}\".*>#{label.name}</span></a></span> ~unknown</p>) + ) + # rubocop:enable Layout/LineLength + end + end + + context 'when markdown contains table' do + let(:markdown) { '<table><tr><th>table head</th><tr><tr><td>table content</td></tr></table>'} + + it { is_expected.to eq('table headtable content') } end context 'when markdown contains a reference to an issue' do diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb index 09ed27eb90f..fce55256922 100644 --- a/spec/mailers/emails/profile_spec.rb +++ b/spec/mailers/emails/profile_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Emails::Profile do describe 'for users that signed up, the email' do let(:example_site_path) { root_path } - let(:new_user) { create(:user, email: new_user_address, password: "securePassword") } + let(:new_user) { create(:user, email: new_user_address) } subject { Notify.new_user_email(new_user.id) } @@ -59,6 +59,7 @@ RSpec.describe Emails::Profile do it_behaves_like 'a user cannot unsubscribe through footer link' it 'does not contain the new user\'s password' do + is_expected.not_to have_body_text(new_user.password) is_expected.not_to have_body_text /password/ end end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 9f5f81dd6c0..f4786083b75 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -37,7 +37,7 @@ RSpec.describe SystemHook do let(:project) { create(:project, namespace: user.namespace) } let(:group) { create(:group) } let(:params) do - { name: 'John Doe', username: 'jduser', email: 'jg@example.com', password: 'mydummypass' } + { name: 'John Doe', username: 'jduser', email: 'jg@example.com', password: User.random_password } end before do diff --git a/spec/models/incident_management/timeline_event_spec.rb b/spec/models/incident_management/timeline_event_spec.rb index 17150fc9266..9f4011fe6a7 100644 --- a/spec/models/incident_management/timeline_event_spec.rb +++ b/spec/models/incident_management/timeline_event_spec.rb @@ -47,11 +47,20 @@ RSpec.describe IncidentManagement::TimelineEvent do describe '#cache_markdown_field' do let(:note) { 'note **bold** _italic_ `code` ![image](/path/img.png) :+1:👍' } + + let(:expected_image_html) do + '<a class="with-attachment-icon" href="/path/img.png" target="_blank" rel="noopener noreferrer">image</a>' + end + + # rubocop:disable Layout/LineLength + let(:expected_emoji_html) do + '<gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji><gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji>' + end + let(:expected_note_html) do - # rubocop:disable Layout/LineLength - '<p>note <strong>bold</strong> <em>italic</em> <code>code</code> <a class="with-attachment-icon" href="/path/img.png" target="_blank" rel="noopener noreferrer">image</a> 👍👍</p>' - # rubocop:enable Layout/LineLength + %Q(<p>note <strong>bold</strong> <em>italic</em> <code>code</code> #{expected_image_html} #{expected_emoji_html}</p>) end + # rubocop:enable Layout/LineLength before do allow(Banzai::Renderer).to receive(:cacheless_render_field).and_call_original diff --git a/spec/requests/api/graphql/work_item_spec.rb b/spec/requests/api/graphql/work_item_spec.rb index a4e6a3a9791..e9753affcc3 100644 --- a/spec/requests/api/graphql/work_item_spec.rb +++ b/spec/requests/api/graphql/work_item_spec.rb @@ -41,6 +41,7 @@ RSpec.describe 'Query.work_item(id)' do 'lockVersion' => work_item.lock_version, 'state' => "OPEN", 'title' => work_item.title, + 'confidential' => work_item.confidential, 'workItemType' => hash_including('id' => work_item.work_item_type.to_gid.to_s), 'userPermissions' => { 'readWorkItem' => true, 'updateWorkItem' => true, 'deleteWorkItem' => false } ) diff --git a/spec/tasks/gitlab/password_rake_spec.rb b/spec/tasks/gitlab/password_rake_spec.rb index 65bba836024..5d5e5af2536 100644 --- a/spec/tasks/gitlab/password_rake_spec.rb +++ b/spec/tasks/gitlab/password_rake_spec.rb @@ -3,7 +3,8 @@ require 'rake_helper' RSpec.describe 'gitlab:password rake tasks', :silence_stdout do - let_it_be(:user_1) { create(:user, username: 'foobar', password: 'initial_password') } + let_it_be(:user_1) { create(:user, username: 'foobar', password: User.random_password) } + let_it_be(:password) { User.random_password } def stub_username(username) allow(Gitlab::TaskHelpers).to receive(:prompt).with('Enter username: ').and_return(username) @@ -19,14 +20,14 @@ RSpec.describe 'gitlab:password rake tasks', :silence_stdout do Rake.application.rake_require 'tasks/gitlab/password' stub_username('foobar') - stub_password('secretpassword') + stub_password(password) end describe ':reset' do context 'when all inputs are correct' do it 'updates the password properly' do run_rake_task('gitlab:password:reset', user_1.username) - expect(user_1.reload.valid_password?('secretpassword')).to eq(true) + expect(user_1.reload.valid_password?(password)).to eq(true) end end @@ -55,7 +56,7 @@ RSpec.describe 'gitlab:password rake tasks', :silence_stdout do context 'when passwords do not match' do before do - stub_password('randompassword', 'differentpassword') + stub_password(password, User.random_password) end it 'aborts with an error' do diff --git a/spec/views/projects/pages/new.html.haml_spec.rb b/spec/views/projects/pages/new.html.haml_spec.rb new file mode 100644 index 00000000000..919b2fe84ee --- /dev/null +++ b/spec/views/projects/pages/new.html.haml_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'projects/pages/new' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + + before do + allow(project).to receive(:show_pages_onboarding?).and_return(true) + project.add_maintainer(user) + + assign(:project, project) + allow(view).to receive(:current_user).and_return(user) + end + + describe 'with onboarding wizard feature enabled' do + before do + Feature.enable(:use_pipeline_wizard_for_pages) + end + + it "shows the onboarding wizard" do + render + expect(rendered).to have_selector('#js-pages') + end + end + + describe 'with onboarding wizard feature disabled' do + before do + Feature.disable(:use_pipeline_wizard_for_pages) + end + + it "does not show the onboarding wizard" do + render + expect(rendered).not_to have_selector('#js-pages') + end + + it "renders the usage instructions" do + render + expect(rendered).to render_template('projects/pages/_use') + end + end +end |