diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-17 12:08:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-17 12:08:24 +0300 |
commit | 728a207ea6a99a4bddc16dbbe82294d3fdb60fe4 (patch) | |
tree | 4bc3b6a859681de3bbeabd7bf2ec5ffd756f3a0a /spec | |
parent | ea20020f71c7226d57b6449b1d9b6c6f1298223e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
12 files changed, 328 insertions, 144 deletions
diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index da36148ba85..214eb35ec9d 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -306,6 +306,23 @@ describe RegistrationsController do expect(subject.current_user).not_to be_nil end + + context 'with the experimental signup flow enabled and the user is part of the experimental group' do + before do + stub_experiment(signup_flow: true) + stub_experiment_for_user(signup_flow: true) + end + + let(:base_user_params) { { first_name: 'First', last_name: 'Last', username: 'new_username', email: 'new@user.com', password: 'Any_password' } } + + it 'sets name from first and last name' do + post :create, params: { new_user: base_user_params } + + expect(User.last.first_name).to eq(base_user_params[:first_name]) + expect(User.last.last_name).to eq(base_user_params[:last_name]) + expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}") + end + end end describe '#destroy' do @@ -395,7 +412,7 @@ describe RegistrationsController do label: anything, property: 'experimental_group' ) - patch :update_registration, params: { user: { name: 'New name', role: 'software_developer', setup_for_company: 'false' } } + patch :update_registration, params: { user: { role: 'software_developer', setup_for_company: 'false' } } end end end diff --git a/spec/features/users/signup_spec.rb b/spec/features/users/signup_spec.rb index 3b19bd423a4..30f298b1fc3 100644 --- a/spec/features/users/signup_spec.rb +++ b/spec/features/users/signup_spec.rb @@ -123,50 +123,6 @@ shared_examples 'Signup' do end end - describe 'user\'s full name validation', :js do - before do - if Gitlab::Experimentation.enabled?(:signup_flow) - user = create(:user, role: nil) - sign_in(user) - visit users_sign_up_welcome_path - @user_name_field = 'user_name' - else - visit new_user_registration_path - @user_name_field = 'new_user_name' - end - end - - it 'does not show an error border if the user\'s fullname length is not longer than 128 characters' do - fill_in @user_name_field, with: 'u' * 128 - - expect(find('.name')).not_to have_css '.gl-field-error-outline' - end - - it 'shows an error border if the user\'s fullname contains an emoji' do - simulate_input("##{@user_name_field}", 'Ehsan 🦋') - - expect(find('.name')).to have_css '.gl-field-error-outline' - end - - it 'shows an error border if the user\'s fullname is longer than 128 characters' do - fill_in @user_name_field, with: 'n' * 129 - - expect(find('.name')).to have_css '.gl-field-error-outline' - end - - it 'shows an error message if the user\'s fullname is longer than 128 characters' do - fill_in @user_name_field, with: 'n' * 129 - - expect(page).to have_content("Name is too long (maximum is 128 characters).") - end - - it 'shows an error message if the username contains emojis' do - simulate_input("##{@user_name_field}", 'Ehsan 🦋') - - expect(page).to have_content("Invalid input, please avoid emojis") - end - end - context 'with no errors' do context 'when sending confirmation email' do before do @@ -184,7 +140,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -209,7 +168,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -235,7 +197,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email.capitalize end @@ -263,7 +228,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -287,7 +255,10 @@ shared_examples 'Signup' do visit new_user_registration_path - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name end @@ -313,7 +284,10 @@ shared_examples 'Signup' do visit new_user_registration_path - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name end @@ -338,7 +312,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -357,7 +334,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -394,7 +374,10 @@ shared_examples 'Signup' do fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email - unless Gitlab::Experimentation.enabled?(:signup_flow) + if Gitlab::Experimentation.enabled?(:signup_flow) + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + else fill_in 'new_user_name', with: new_user.name fill_in 'new_user_email_confirmation', with: new_user.email end @@ -412,6 +395,44 @@ shared_examples 'Signup' do end end +shared_examples 'Signup name validation' do |field, max_length| + before do + visit new_user_registration_path + end + + describe "#{field} validation", :js do + it "does not show an error border if the user's fullname length is not longer than #{max_length} characters" do + fill_in field, with: 'u' * max_length + + expect(find('.name')).not_to have_css '.gl-field-error-outline' + end + + it 'shows an error border if the user\'s fullname contains an emoji' do + simulate_input("##{field}", 'Ehsan 🦋') + + expect(find('.name')).to have_css '.gl-field-error-outline' + end + + it "shows an error border if the user\'s fullname is longer than #{max_length} characters" do + fill_in field, with: 'n' * (max_length + 1) + + expect(find('.name')).to have_css '.gl-field-error-outline' + end + + it "shows an error message if the user\'s fullname is longer than #{max_length} characters" do + fill_in field, with: 'n' * (max_length + 1) + + expect(page).to have_content("Name is too long (maximum is #{max_length} characters).") + end + + it 'shows an error message if the username contains emojis' do + simulate_input("##{field}", 'Ehsan 🦋') + + expect(page).to have_content("Invalid input, please avoid emojis") + end + end +end + describe 'With original flow' do before do stub_experiment(signup_flow: false) @@ -419,6 +440,7 @@ describe 'With original flow' do end it_behaves_like 'Signup' + it_behaves_like 'Signup name validation', 'new_user_name', 255 end describe 'With experimental flow' do @@ -428,11 +450,15 @@ describe 'With experimental flow' do end it_behaves_like 'Signup' + it_behaves_like 'Signup name validation', 'new_user_first_name', 127 + it_behaves_like 'Signup name validation', 'new_user_last_name', 127 describe 'when role is required' do it 'after registering, it redirects to step 2 of the signup process, sets the name and role and then redirects to the original requested url' do new_user = build_stubbed(:user) visit new_user_registration_path + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name fill_in 'new_user_username', with: new_user.username fill_in 'new_user_email', with: new_user.email fill_in 'new_user_password', with: new_user.password @@ -441,13 +467,11 @@ describe 'With experimental flow' do expect(page).to have_current_path(users_sign_up_welcome_path) - fill_in 'user_name', with: 'New name' select 'Software Developer', from: 'user_role' choose 'user_setup_for_company_true' click_button 'Get started!' new_user = User.find_by_username(new_user.username) - expect(new_user.name).to eq 'New name' expect(new_user.software_developer_role?).to be_truthy expect(new_user.setup_for_company).to be_truthy expect(page).to have_current_path(new_project_path) diff --git a/spec/frontend/boards/issue_card_spec.js b/spec/frontend/boards/issue_card_spec.js index b9a88324763..df55a106945 100644 --- a/spec/frontend/boards/issue_card_spec.js +++ b/spec/frontend/boards/issue_card_spec.js @@ -50,7 +50,6 @@ describe('Issue card component', () => { rootPath: '/', }, store, - attachToDocument: true, }); }); diff --git a/spec/frontend/create_cluster/eks_cluster/components/service_credentials_form_spec.js b/spec/frontend/create_cluster/eks_cluster/components/service_credentials_form_spec.js index 92a5f5116ac..c58638f5c80 100644 --- a/spec/frontend/create_cluster/eks_cluster/components/service_credentials_form_spec.js +++ b/spec/frontend/create_cluster/eks_cluster/components/service_credentials_form_spec.js @@ -47,7 +47,6 @@ describe('ServiceCredentialsForm', () => { const findCopyExternalIdButton = () => vm.find('.js-copy-external-id-button'); const findInvalidCredentials = () => vm.find('.js-invalid-credentials'); const findSubmitButton = () => vm.find(LoadingButton); - const findForm = () => vm.find('form[name="service-credentials-form"]'); it('displays provided account id', () => { expect(findAccountIdInput().attributes('value')).toBe(accountId); @@ -77,8 +76,10 @@ describe('ServiceCredentialsForm', () => { }); }); - it('dispatches createRole action when form is submitted', () => { - findForm().trigger('submit'); + it('dispatches createRole action when submit button is clicked', () => { + vm.setData({ roleArn: '123' }); // set role ARN to enable button + + findSubmitButton().vm.$emit('click', new Event('click')); expect(createRoleAction).toHaveBeenCalled(); }); diff --git a/spec/frontend/cycle_analytics/limit_warning_component_spec.js b/spec/frontend/cycle_analytics/limit_warning_component_spec.js index a4606099b06..e712dea67cb 100644 --- a/spec/frontend/cycle_analytics/limit_warning_component_spec.js +++ b/spec/frontend/cycle_analytics/limit_warning_component_spec.js @@ -10,7 +10,6 @@ const createComponent = props => propsData: { ...props, }, - attachToDocument: true, }); describe('Limit warning component', () => { diff --git a/spec/frontend/error_tracking/components/error_details_spec.js b/spec/frontend/error_tracking/components/error_details_spec.js index e876a6da922..e19cb1fd3c1 100644 --- a/spec/frontend/error_tracking/components/error_details_spec.js +++ b/spec/frontend/error_tracking/components/error_details_spec.js @@ -246,5 +246,37 @@ describe('ErrorDetails', () => { }); }); }); + + describe('GitLab commit link', () => { + const gitlabCommit = '7975be0116940bf2ad4321f79d02a55c5f7779aa'; + const gitlabCommitPath = + '/gitlab-org/gitlab-test/commit/7975be0116940bf2ad4321f79d02a55c5f7779aa'; + const findGitLabCommitLink = () => wrapper.find(`[href$="${gitlabCommitPath}"]`); + + it('should display a link', () => { + mocks.$apollo.queries.GQLerror.loading = false; + wrapper.setData({ + GQLerror: { + gitlabCommit, + gitlabCommitPath, + }, + }); + return wrapper.vm.$nextTick().then(() => { + expect(findGitLabCommitLink().exists()).toBe(true); + }); + }); + + it('should display a link', () => { + mocks.$apollo.queries.GQLerror.loading = false; + wrapper.setData({ + GQLerror: { + gitlabCommit: null, + }, + }); + return wrapper.vm.$nextTick().then(() => { + expect(findGitLabCommitLink().exists()).toBe(false); + }); + }); + }); }); }); diff --git a/spec/frontend/jobs/components/erased_block_spec.js b/spec/frontend/jobs/components/erased_block_spec.js index 29a7676abe5..d66ee71df6a 100644 --- a/spec/frontend/jobs/components/erased_block_spec.js +++ b/spec/frontend/jobs/components/erased_block_spec.js @@ -13,7 +13,6 @@ describe('Erased block', () => { const createComponent = props => { wrapper = mount(ErasedBlock, { propsData: props, - attachToDocument: true, }); }; diff --git a/spec/frontend/notes/components/discussion_actions_spec.js b/spec/frontend/notes/components/discussion_actions_spec.js index 7e30e166d65..2d95a86d8a6 100644 --- a/spec/frontend/notes/components/discussion_actions_spec.js +++ b/spec/frontend/notes/components/discussion_actions_spec.js @@ -35,7 +35,6 @@ describe('DiscussionActions', () => { shouldShowJumpToNextDiscussion: true, ...props, }, - attachToDocument: true, }); }; diff --git a/spec/frontend/releases/detail/components/app_spec.js b/spec/frontend/releases/detail/components/app_spec.js index 09f348018f4..fd5239ad44e 100644 --- a/spec/frontend/releases/detail/components/app_spec.js +++ b/spec/frontend/releases/detail/components/app_spec.js @@ -31,7 +31,6 @@ describe('Release detail component', () => { wrapper = mount(ReleaseDetailApp, { store, - attachToDocument: true, }); return wrapper.vm.$nextTick(); diff --git a/spec/javascripts/ide/components/commit_sidebar/form_spec.js b/spec/javascripts/ide/components/commit_sidebar/form_spec.js index 2ee0b94582c..e984389bd46 100644 --- a/spec/javascripts/ide/components/commit_sidebar/form_spec.js +++ b/spec/javascripts/ide/components/commit_sidebar/form_spec.js @@ -76,6 +76,25 @@ describe('IDE commit form', () => { done(); }); }); + + it('collapses if lastCommitMsg is set to empty and current view is not commit view', done => { + store.state.lastCommitMsg = 'abc'; + store.state.currentActivityView = activityBarViews.edit; + + vm.$nextTick(() => { + // if commit message is set, form is uncollapsed + expect(vm.isCompact).toBe(false); + + store.state.lastCommitMsg = ''; + + vm.$nextTick(() => { + // collapsed when set to empty + expect(vm.isCompact).toBe(true); + + done(); + }); + }); + }); }); describe('full', () => { diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 110f7a5af65..5620f211d9c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -147,15 +147,15 @@ describe User, :do_not_mock_admin_mode do describe 'name' do it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_length_of(:name).is_at_most(128) } + it { is_expected.to validate_length_of(:name).is_at_most(255) } end describe 'first name' do - it { is_expected.to validate_length_of(:first_name).is_at_most(255) } + it { is_expected.to validate_length_of(:first_name).is_at_most(127) } end describe 'last name' do - it { is_expected.to validate_length_of(:last_name).is_at_most(255) } + it { is_expected.to validate_length_of(:last_name).is_at_most(127) } end describe 'username' do diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index 09ca106c54c..620ef3ff21a 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -33,10 +33,10 @@ describe ProjectPresenter do describe '#default_view' do context 'user not signed in' do - let(:user) { nil } + let_it_be(:user) { nil } context 'when repository is empty' do - let(:project) { create(:project_empty_repo, :public) } + let_it_be(:project) { create(:project_empty_repo, :public) } it 'returns activity if user has repository access' do allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true) @@ -52,7 +52,8 @@ describe ProjectPresenter do end context 'when repository is not empty' do - let(:project) { create(:project, :public, :repository) } + let_it_be(:project) { create(:project, :public, :repository) } + let(:release) { create(:release, project: project, author: user) } it 'returns files and readme if user has repository access' do allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true) @@ -65,6 +66,15 @@ describe ProjectPresenter do expect(presenter.default_view).to eq('activity') end + + it 'returns releases anchor' do + expect(release).to be_truthy + expect(presenter.releases_anchor_data).to have_attributes( + is_link: true, + label: a_string_including("#{project.releases.count}"), + link: presenter.project_releases_path(project) + ) + end end end @@ -121,10 +131,8 @@ describe ProjectPresenter do end describe '#can_current_user_push_code?' do - let(:project) { create(:project, :repository) } - context 'empty repo' do - let(:project) { create(:project) } + let_it_be(:project) { create(:project) } it 'returns true if user can push_code' do project.add_developer(user) @@ -150,6 +158,7 @@ describe ProjectPresenter do it 'returns false if default branch is protected' do project.add_developer(user) + create(:protected_branch, project: project, name: project.default_branch) expect(presenter.can_current_user_push_code?).to be(false) @@ -158,73 +167,125 @@ describe ProjectPresenter do end context 'statistics anchors (empty repo)' do - let(:project) { create(:project, :empty_repo) } + let_it_be(:project) { create(:project, :empty_repo) } describe '#files_anchor_data' do it 'returns files data' do - expect(presenter.files_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0 Bytes'), - link: nil) + expect(presenter.files_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0 Bytes'), + link: nil + ) + end + end + + describe '#releases_anchor_data' do + it 'does not return release count' do + expect(presenter.releases_anchor_data).to be_nil end end describe '#commits_anchor_data' do it 'returns commits data' do - expect(presenter.commits_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0'), - link: nil) + expect(presenter.commits_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0'), + link: nil + ) end end describe '#branches_anchor_data' do it 'returns branches data' do - expect(presenter.branches_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0'), - link: nil) + expect(presenter.branches_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0'), + link: nil + ) end end describe '#tags_anchor_data' do it 'returns tags data' do - expect(presenter.tags_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0'), - link: nil) + expect(presenter.tags_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0'), + link: nil + ) end end end context 'statistics anchors' do - let(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:release) { create(:release, project: project, author: user) } + let(:presenter) { described_class.new(project, current_user: user) } describe '#files_anchor_data' do it 'returns files data' do - expect(presenter.files_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0 Bytes'), - link: presenter.project_tree_path(project)) + expect(presenter.files_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0 Bytes'), + link: presenter.project_tree_path(project) + ) + end + end + + describe '#releases_anchor_data' do + it 'returns release count if user can read release' do + project.add_maintainer(user) + + expect(release).to be_truthy + expect(presenter.releases_anchor_data).to have_attributes( + is_link: true, + label: a_string_including("#{project.releases.count}"), + link: presenter.project_releases_path(project) + ) + end + + it 'returns nil if user cannot read release' do + expect(release).to be_truthy + expect(presenter.releases_anchor_data).to be_nil + end + + context 'user not signed in' do + let_it_be(:user) { nil } + + it 'returns nil if user is signed out' do + expect(release).to be_truthy + expect(presenter.releases_anchor_data).to be_nil + end end end describe '#commits_anchor_data' do it 'returns commits data' do - expect(presenter.commits_anchor_data).to have_attributes(is_link: true, - label: a_string_including('0'), - link: presenter.project_commits_path(project, project.repository.root_ref)) + expect(presenter.commits_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0'), + link: presenter.project_commits_path(project, project.repository.root_ref) + ) end end describe '#branches_anchor_data' do it 'returns branches data' do - expect(presenter.branches_anchor_data).to have_attributes(is_link: true, - label: a_string_including("#{project.repository.branches.size}"), - link: presenter.project_branches_path(project)) + expect(presenter.branches_anchor_data).to have_attributes( + is_link: true, + label: a_string_including("#{project.repository.branches.size}"), + link: presenter.project_branches_path(project) + ) end end describe '#tags_anchor_data' do it 'returns tags data' do - expect(presenter.tags_anchor_data).to have_attributes(is_link: true, - label: a_string_including("#{project.repository.tags.size}"), - link: presenter.project_tags_path(project)) + expect(presenter.tags_anchor_data).to have_attributes( + is_link: true, + label: a_string_including("#{project.repository.tags.size}"), + link: presenter.project_tags_path(project) + ) end end @@ -232,10 +293,12 @@ describe ProjectPresenter do it 'returns new file data if user can push' do project.add_developer(user) - expect(presenter.new_file_anchor_data).to have_attributes(is_link: false, - label: a_string_including("New file"), - link: presenter.project_new_blob_path(project, 'master'), - class_modifier: 'success') + expect(presenter.new_file_anchor_data).to have_attributes( + is_link: false, + label: a_string_including("New file"), + link: presenter.project_new_blob_path(project, 'master'), + class_modifier: 'success' + ) end it 'returns nil if user cannot push' do @@ -243,7 +306,7 @@ describe ProjectPresenter do end context 'when the project is empty' do - let(:project) { create(:project, :empty_repo) } + let_it_be(:project) { create(:project, :empty_repo) } # Since we protect the default branch for empty repos it 'is empty for a developer' do @@ -258,11 +321,14 @@ describe ProjectPresenter do context 'when user can push and README does not exists' do it 'returns anchor data' do project.add_developer(user) + allow(project.repository).to receive(:readme).and_return(nil) - expect(presenter.readme_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Add README'), - link: presenter.add_readme_path) + expect(presenter.readme_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Add README'), + link: presenter.add_readme_path + ) end end @@ -270,9 +336,11 @@ describe ProjectPresenter do it 'returns anchor data' do allow(project.repository).to receive(:readme).and_return(double(name: 'readme')) - expect(presenter.readme_anchor_data).to have_attributes(is_link: false, - label: a_string_including('README'), - link: presenter.readme_path) + expect(presenter.readme_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('README'), + link: presenter.readme_path + ) end end end @@ -281,11 +349,14 @@ describe ProjectPresenter do context 'when user can push and CHANGELOG does not exist' do it 'returns anchor data' do project.add_developer(user) + allow(project.repository).to receive(:changelog).and_return(nil) - expect(presenter.changelog_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Add CHANGELOG'), - link: presenter.add_changelog_path) + expect(presenter.changelog_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Add CHANGELOG'), + link: presenter.add_changelog_path + ) end end @@ -293,9 +364,11 @@ describe ProjectPresenter do it 'returns anchor data' do allow(project.repository).to receive(:changelog).and_return(double(name: 'foo')) - expect(presenter.changelog_anchor_data).to have_attributes(is_link: false, - label: a_string_including('CHANGELOG'), - link: presenter.changelog_path) + expect(presenter.changelog_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('CHANGELOG'), + link: presenter.changelog_path + ) end end end @@ -304,11 +377,14 @@ describe ProjectPresenter do context 'when user can push and LICENSE does not exist' do it 'returns anchor data' do project.add_developer(user) + allow(project.repository).to receive(:license_blob).and_return(nil) - expect(presenter.license_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Add LICENSE'), - link: presenter.add_license_path) + expect(presenter.license_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Add LICENSE'), + link: presenter.add_license_path + ) end end @@ -316,9 +392,11 @@ describe ProjectPresenter do it 'returns anchor data' do allow(project.repository).to receive(:license_blob).and_return(double(name: 'foo')) - expect(presenter.license_anchor_data).to have_attributes(is_link: false, - label: a_string_including(presenter.license_short_name), - link: presenter.license_path) + expect(presenter.license_anchor_data).to have_attributes( + is_link: false, + label: a_string_including(presenter.license_short_name), + link: presenter.license_path + ) end end end @@ -327,11 +405,14 @@ describe ProjectPresenter do context 'when user can push and CONTRIBUTING does not exist' do it 'returns anchor data' do project.add_developer(user) + allow(project.repository).to receive(:contribution_guide).and_return(nil) - expect(presenter.contribution_guide_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Add CONTRIBUTING'), - link: presenter.add_contribution_guide_path) + expect(presenter.contribution_guide_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Add CONTRIBUTING'), + link: presenter.add_contribution_guide_path + ) end end @@ -339,9 +420,11 @@ describe ProjectPresenter do it 'returns anchor data' do allow(project.repository).to receive(:contribution_guide).and_return(double(name: 'foo')) - expect(presenter.contribution_guide_anchor_data).to have_attributes(is_link: false, - label: a_string_including('CONTRIBUTING'), - link: presenter.contribution_guide_path) + expect(presenter.contribution_guide_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('CONTRIBUTING'), + link: presenter.contribution_guide_path + ) end end end @@ -351,21 +434,26 @@ describe ProjectPresenter do it 'returns anchor data' do allow(project).to receive(:auto_devops_enabled?).and_return(true) - expect(presenter.autodevops_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Auto DevOps enabled'), - link: nil) + expect(presenter.autodevops_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Auto DevOps enabled'), + link: nil + ) end end context 'when user can admin pipeline and CI yml does not exist' do it 'returns anchor data' do project.add_maintainer(user) + allow(project).to receive(:auto_devops_enabled?).and_return(false) allow(project.repository).to receive(:gitlab_ci_yml).and_return(nil) - expect(presenter.autodevops_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Enable Auto DevOps'), - link: presenter.project_settings_ci_cd_path(project, anchor: 'autodevops-settings')) + expect(presenter.autodevops_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Enable Auto DevOps'), + link: presenter.project_settings_ci_cd_path(project, anchor: 'autodevops-settings') + ) end end end @@ -374,29 +462,37 @@ describe ProjectPresenter do context 'when user can create Kubernetes cluster' do it 'returns link to cluster if only one exists' do project.add_maintainer(user) + cluster = create(:cluster, projects: [project]) - expect(presenter.kubernetes_cluster_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Kubernetes configured'), - link: presenter.project_cluster_path(project, cluster)) + expect(presenter.kubernetes_cluster_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Kubernetes configured'), + link: presenter.project_cluster_path(project, cluster) + ) end it 'returns link to clusters page if more than one exists' do project.add_maintainer(user) + create(:cluster, :production_environment, projects: [project]) create(:cluster, projects: [project]) - expect(presenter.kubernetes_cluster_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Kubernetes configured'), - link: presenter.project_clusters_path(project)) + expect(presenter.kubernetes_cluster_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Kubernetes configured'), + link: presenter.project_clusters_path(project) + ) end it 'returns link to create a cluster if no cluster exists' do project.add_maintainer(user) - expect(presenter.kubernetes_cluster_anchor_data).to have_attributes(is_link: false, - label: a_string_including('Add Kubernetes cluster'), - link: presenter.new_project_cluster_path(project)) + expect(presenter.kubernetes_cluster_anchor_data).to have_attributes( + is_link: false, + label: a_string_including('Add Kubernetes cluster'), + link: presenter.new_project_cluster_path(project) + ) end end @@ -464,7 +560,7 @@ describe ProjectPresenter do end context 'initialized repo' do - let(:project) { create(:project, :repository) } + let_it_be(:project) { create(:project, :repository) } it 'orders the items correctly' do expect(empty_repo_statistics_buttons.map(&:label)).to start_with( |