summaryrefslogtreecommitdiff
path: root/spec/features/merge_requests
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2018-05-29 20:51:43 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2018-05-29 20:51:43 +1100
commit4cff66a6c46361e8d775ea3f5a80bf147d4020b3 (patch)
treef1f76411400f35f394fedd28ad03d42ccbaf990e /spec/features/merge_requests
parent6e354cb642f911dc71be3d5368f066900fc25970 (diff)
downloadgitlab-ce-4cff66a6c46361e8d775ea3f5a80bf147d4020b3.tar.gz
Add 'squash and rebase' feature to CEblackst0ne-squash-and-merge-in-gitlab-core-ce
Diffstat (limited to 'spec/features/merge_requests')
-rw-r--r--spec/features/merge_requests/user_squashes_merge_request_spec.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/spec/features/merge_requests/user_squashes_merge_request_spec.rb b/spec/features/merge_requests/user_squashes_merge_request_spec.rb
new file mode 100644
index 00000000000..6c952791591
--- /dev/null
+++ b/spec/features/merge_requests/user_squashes_merge_request_spec.rb
@@ -0,0 +1,124 @@
+require 'spec_helper'
+
+feature 'User squashes a merge request', :js do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, :repository) }
+ let(:source_branch) { 'csv' }
+
+ let!(:original_head) { project.repository.commit('master') }
+
+ shared_examples 'squash' do
+ it 'squashes the commits into a single commit, and adds a merge commit' do
+ expect(page).to have_content('Merged')
+
+ latest_master_commits = project.repository.commits_between(original_head.sha, 'master').map(&:raw)
+
+ squash_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/),
+ message: "Csv\n",
+ author_name: user.name,
+ committer_name: user.name)
+
+ merge_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/),
+ message: a_string_starting_with("Merge branch 'csv' into 'master'"),
+ author_name: user.name,
+ committer_name: user.name)
+
+ expect(project.repository).not_to be_merged_to_root_ref(source_branch)
+ expect(latest_master_commits).to match([squash_commit, merge_commit])
+ end
+ end
+
+ shared_examples 'no squash' do
+ it 'accepts the merge request without squashing' do
+ expect(page).to have_content('Merged')
+ expect(project.repository).to be_merged_to_root_ref(source_branch)
+ end
+ end
+
+ def accept_mr
+ expect(page).to have_button('Merge')
+
+ uncheck 'Remove source branch'
+ click_on 'Merge'
+ end
+
+ before do
+ # Prevent source branch from being removed so we can use be_merged_to_root_ref
+ # method to check if squash was performed or not
+ allow_any_instance_of(MergeRequest).to receive(:force_remove_source_branch?).and_return(false)
+ project.add_master(user)
+
+ sign_in user
+ end
+
+ context 'when the MR has only one commit' do
+ before do
+ merge_request = create(:merge_request, source_project: project, target_project: project, source_branch: 'master', target_branch: 'branch-merged')
+
+ visit project_merge_request_path(project, merge_request)
+ end
+
+ it 'does not show the squash checkbox' do
+ expect(page).not_to have_field('squash')
+ end
+ end
+
+ context 'when squash is enabled on merge request creation' do
+ before do
+ visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: source_branch })
+ check 'merge_request[squash]'
+ click_on 'Submit merge request'
+ wait_for_requests
+ end
+
+ it 'shows the squash checkbox as checked' do
+ expect(page).to have_checked_field('squash')
+ end
+
+ context 'when accepting with squash checked' do
+ before do
+ accept_mr
+ end
+
+ include_examples 'squash'
+ end
+
+ context 'when accepting and unchecking squash' do
+ before do
+ uncheck 'squash'
+ accept_mr
+ end
+
+ include_examples 'no squash'
+ end
+ end
+
+ context 'when squash is not enabled on merge request creation' do
+ before do
+ visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: source_branch })
+ click_on 'Submit merge request'
+ wait_for_requests
+ end
+
+ it 'shows the squash checkbox as unchecked' do
+ expect(page).to have_unchecked_field('squash')
+ end
+
+ context 'when accepting and checking squash' do
+ before do
+ check 'squash'
+ accept_mr
+ end
+
+ include_examples 'squash'
+ end
+
+ context 'when accepting with squash unchecked' do
+ before do
+ accept_mr
+ end
+
+ include_examples 'no squash'
+ end
+ end
+end