debian-mirror-gitlab/spec/features/projects/commit/user_reverts_commit_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'User reverts a commit', :js, feature_category: :source_code_management do
2018-03-17 18:26:18 +05:30
include RepoHelpers
2021-03-08 18:12:59 +05:30
let_it_be(:user) { create(:user) }
2021-06-08 01:23:25 +05:30
2021-03-11 19:13:27 +05:30
let!(:project) { create_default(:project, :repository, namespace: user.namespace) }
2018-03-17 18:26:18 +05:30
before do
sign_in(user)
2018-05-09 12:01:36 +05:30
end
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
context 'when clicking revert from the dropdown for a commit on pipelines tab' do
it 'launches the modal and is able to submit the revert' do
sha = '7d3b0f7cff5f37573aea97cebfd5692ea1689924'
create(:ci_empty_pipeline, sha: sha)
visit project_commit_path(project, project.commit(sha).id)
click_link 'Pipelines'
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
open_modal
page.within(modal_selector) do
expect(page).to have_content('Revert this commit')
end
2018-03-17 18:26:18 +05:30
end
2021-03-08 18:12:59 +05:30
end
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
context 'when starting from the commit tab' do
before do
visit project_commit_path(project, sample_commit.id)
end
context 'without creating a new merge request' do
it 'reverts a commit' do
revert_commit
expect(page).to have_content('The commit has been successfully reverted.')
end
it 'does not revert a previously reverted commit' do
revert_commit
# Visit the comment again once it was reverted.
visit project_commit_path(project, sample_commit.id)
revert_commit
2021-03-08 18:12:59 +05:30
2023-05-27 22:25:52 +05:30
expect(page).to have_content('Commit revert failed:')
2021-03-11 19:13:27 +05:30
end
2018-03-17 18:26:18 +05:30
end
2021-03-11 19:13:27 +05:30
context 'with creating a new merge request' do
it 'reverts a commit' do
revert_commit(create_merge_request: true)
expect(page).to have_content('The commit has been successfully reverted. You can now submit a merge request to get this change into the original branch.')
expect(page).to have_content("From revert-#{Commit.truncate_sha(sample_commit.id)} into master")
end
end
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
context 'when the project is archived' do
let(:project) { create(:project, :repository, :archived, namespace: user.namespace) }
2018-03-17 18:26:18 +05:30
2021-04-29 21:17:54 +05:30
it 'does not show the revert button' do
2021-03-11 19:13:27 +05:30
open_dropdown
2021-04-29 21:17:54 +05:30
expect(page).not_to have_button('Revert')
2021-03-11 19:13:27 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
2021-03-11 19:13:27 +05:30
def revert_commit(create_merge_request: false)
open_modal
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
page.within(modal_selector) do
uncheck('create_merge_request') unless create_merge_request
2021-04-29 21:17:54 +05:30
click_button 'Revert'
2018-03-17 18:26:18 +05:30
end
end
2018-05-09 12:01:36 +05:30
2021-03-11 19:13:27 +05:30
def open_dropdown
2021-04-29 21:17:54 +05:30
find(dropdown_selector).click
2021-03-11 19:13:27 +05:30
end
2018-05-09 12:01:36 +05:30
2021-03-11 19:13:27 +05:30
def open_modal
open_dropdown
2021-04-29 21:17:54 +05:30
page.within(dropdown_selector) do
click_button 'Revert'
end
end
def dropdown_selector
'[data-testid="commit-options-dropdown"]'
2021-03-11 19:13:27 +05:30
end
2018-05-09 12:01:36 +05:30
2021-03-11 19:13:27 +05:30
def modal_selector
'[data-testid="modal-commit"]'
2018-05-09 12:01:36 +05:30
end
2018-03-17 18:26:18 +05:30
end