diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-29 03:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-29 03:08:52 +0300 |
commit | 21b8ed2e35ee50538ddb2e48ad2b04de2eba43d6 (patch) | |
tree | d6e65cb4660e9aa2d79fbcee590c68b317ba204d /spec | |
parent | 71d6b9014bef64436bbd996667e6458ebde561c4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/settings/repository_controller_spec.rb | 32 | ||||
-rw-r--r-- | spec/features/projects/settings/branch_names_settings_spec.rb | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/project_setting_spec.rb | 1 |
5 files changed, 91 insertions, 2 deletions
diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb index 31fefee3daa..6e04e3991ab 100644 --- a/spec/controllers/projects/settings/repository_controller_spec.rb +++ b/spec/controllers/projects/settings/repository_controller_spec.rb @@ -168,5 +168,37 @@ RSpec.describe Projects::Settings::RepositoryController do end end end + + context 'when updating branch names template from issues' do + let(:branch_name_template) { 'feat/GL-%{id}-%{title}' } + + let(:request_params) { base_params.merge({ project: project_params_attributes }) } + + subject { put :update, params: request_params } + + context('with a good request') do + let(:project_params_attributes) { { issue_branch_template: branch_name_template } } + + it "updates issue_branch_template and redirect to project_settings_repository_path" do + subject + + expect(response).to redirect_to project_settings_repository_path(project) + expect(controller).to set_flash[:notice].to("Project settings were successfully updated.") + expect(project.reload.issue_branch_template).to eq(branch_name_template) + end + end + + context('with a bad input') do + let(:project_params_attributes) { { issue_branch_template: 'a' * 260 } } + + it "updates issue_branch_template and redirect to project_settings_repository_path" do + subject + + expect(response).to redirect_to project_settings_repository_path(project) + expect(controller).to set_flash[:alert].to("Project setting issue branch template is too long (maximum is 255 characters)") + expect(project.reload.issue_branch_template).to eq(nil) + end + end + end end end diff --git a/spec/features/projects/settings/branch_names_settings_spec.rb b/spec/features/projects/settings/branch_names_settings_spec.rb new file mode 100644 index 00000000000..fdd883bc2b6 --- /dev/null +++ b/spec/features/projects/settings/branch_names_settings_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Project settings > repositories > Branch names', :js do + let_it_be(:project) { create(:project, :public) } + let(:user) { create(:user) } + + before do + project.add_maintainer(user) + + sign_in(user) + end + + context 'when Issues are initially disabled' do + let(:project_feature) { project.project_feature } + + before do + project_feature.update!(issues_access_level: ProjectFeature::DISABLED) + visit project_settings_repository_path(project) + end + + it 'do not render the Branch names settings' do + expect(page).not_to have_content('Branch name template') + end + end + + context 'when Issues are initially enabled' do + before do + visit project_settings_repository_path(project) + end + + it 'shows the Branch names settings' do + expect(page).to have_content('Branch name template') + + value = "feature-%{id}" + + within('section#branch-defaults-settings') do + fill_in 'project[issue_branch_template]', with: value + + click_on('Save changes') + end + + expect(project.reload.issue_branch_template).to eq(value) + expect(page).to have_content('Branch name template') + end + end +end diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 64fed73303f..75d980cd5f4 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -568,6 +568,7 @@ Project: - suggestion_commit_message - merge_commit_template - squash_commit_template +- issue_branch_template Author: - name ProjectFeature: diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index f8c731b0d10..9dfe89b8814 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -864,7 +864,7 @@ RSpec.describe Issue do describe '.to_branch_name' do it 'parameterizes arguments and joins with dashes' do - expect(described_class.to_branch_name(123, 'foo bar', '!@#$%', 'f!o@o#b$a%r^')).to eq('123-foo-bar-f-o-o-b-a-r') + expect(described_class.to_branch_name(123, 'foo bar!@#$%f!o@o#b$a%r^')).to eq('123-foo-bar-f-o-o-b-a-r') end it 'preserves the case in the first argument' do @@ -872,7 +872,7 @@ RSpec.describe Issue do end it 'truncates branch name to at most 100 characters' do - expect(described_class.to_branch_name('a' * 101)).to eq('a' * 100) + expect(described_class.to_branch_name('a' * 101, 'a')).to eq('a' * 100) end it 'truncates dangling parts of the branch name' do @@ -884,6 +884,13 @@ RSpec.describe Issue do # 100 characters would've got us "999-lorem...lacus-custom-fri". expect(branch_name).to eq('999-lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-mauris-sit-amet-ipsum-id-lacus-custom') end + + it 'takes issue branch template into account' do + project = create(:project) + project.project_setting.update!(issue_branch_template: 'feature-%{id}-%{title}') + + expect(described_class.to_branch_name(123, 'issue title', project: project)).to eq('feature-123-issue-title') + end end describe '#to_branch_name' do diff --git a/spec/models/project_setting_spec.rb b/spec/models/project_setting_spec.rb index eb0292c7005..b33cf0219d3 100644 --- a/spec/models/project_setting_spec.rb +++ b/spec/models/project_setting_spec.rb @@ -20,6 +20,7 @@ RSpec.describe ProjectSetting, type: :model do describe 'validations' do it { is_expected.not_to allow_value(nil).for(:target_platforms) } it { is_expected.to allow_value([]).for(:target_platforms) } + it { is_expected.to validate_length_of(:issue_branch_template).is_at_most(255) } it { is_expected.not_to allow_value(nil).for(:suggested_reviewers_enabled) } it { is_expected.to allow_value(true).for(:suggested_reviewers_enabled) } |