debian-mirror-gitlab/spec/features/projects/blobs/edit_spec.rb

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

209 lines
6.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-01-15 13:20:01 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Editing file blob', :js do
2022-08-27 11:52:29 +05:30
include Spec::Support::Helpers::Features::SourceEditorSpecHelpers
2017-08-17 22:00:37 +05:30
include TreeHelper
2021-01-03 14:25:43 +05:30
include BlobSpecHelpers
2017-01-15 13:20:01 +05:30
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :public, :repository) }
2017-08-17 22:00:37 +05:30
let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master') }
let(:branch) { 'master' }
let(:file_path) { project.repository.ls_files(project.repository.root_ref)[1] }
2018-11-20 20:47:30 +05:30
let(:readme_file_path) { 'README.md' }
2017-01-15 13:20:01 +05:30
2017-08-17 22:00:37 +05:30
context 'as a developer' do
let(:user) { create(:user) }
let(:role) { :developer }
2017-01-15 13:20:01 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_role(user, role)
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
2021-01-03 14:25:43 +05:30
def edit_and_commit(commit_changes: true, is_diff: false)
set_default_button('edit')
refresh
2017-09-10 17:25:29 +05:30
wait_for_requests
2021-01-03 14:25:43 +05:30
if is_diff
first('.js-diff-more-actions').click
click_link('Edit in single-file editor')
else
click_link('Edit')
end
2019-12-26 22:10:19 +05:30
fill_editor(content: 'class NextFeature\\nend\\n')
2018-03-17 18:26:18 +05:30
if commit_changes
click_button 'Commit changes'
end
2017-08-17 22:00:37 +05:30
end
2019-12-26 22:10:19 +05:30
def fill_editor(content: 'class NextFeature\\nend\\n')
2018-11-20 20:47:30 +05:30
wait_for_requests
2022-08-27 11:52:29 +05:30
editor_set_value(content)
2018-11-20 20:47:30 +05:30
end
2017-08-17 22:00:37 +05:30
context 'from MR diff' do
before do
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request)
2021-01-03 14:25:43 +05:30
edit_and_commit(is_diff: true)
2017-08-17 22:00:37 +05:30
end
it 'returns me to the mr' do
expect(page).to have_content(merge_request.title)
end
2017-01-15 13:20:01 +05:30
end
2019-07-07 11:18:12 +05:30
it 'updates the content of file with a number as file path' do
project.repository.create_file(user, '1', 'test', message: 'testing', branch_name: branch)
visit project_blob_path(project, tree_join(branch, '1'))
edit_and_commit
expect(page).to have_content 'NextFeature'
end
2019-12-26 22:10:19 +05:30
it 'editing a template file in a sub directory does not change path' do
project.repository.create_file(user, 'ci/.gitlab-ci.yml', 'test', message: 'testing', branch_name: branch)
visit project_edit_blob_path(project, tree_join(branch, 'ci/.gitlab-ci.yml'))
expect(find_by_id('file_path').value).to eq('ci/.gitlab-ci.yml')
end
2020-07-28 23:09:34 +05:30
it 'updating file path updates syntax highlighting' do
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
expect(find('#editor')['data-mode-id']).to eq('markdown')
find('#file_path').send_keys('foo.txt') do
expect(find('#editor')['data-mode-id']).to eq('plaintext')
end
end
2017-08-17 22:00:37 +05:30
context 'from blob file path' do
before do
2017-09-10 17:25:29 +05:30
visit project_blob_path(project, tree_join(branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'updates content' do
2018-03-17 18:26:18 +05:30
edit_and_commit
2017-08-17 22:00:37 +05:30
expect(page).to have_content 'successfully committed'
expect(page).to have_content 'NextFeature'
end
2018-03-17 18:26:18 +05:30
it 'previews content' do
edit_and_commit(commit_changes: false)
click_link 'Preview changes'
wait_for_requests
new_line_count = page.all('.line_holder.new').size
expect(new_line_count).to be > 0
end
2017-01-15 13:20:01 +05:30
end
2018-11-20 20:47:30 +05:30
context 'when rendering the preview' do
it 'renders content with CommonMark' do
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
2019-12-26 22:10:19 +05:30
fill_editor(content: '1. one\\n - sublist\\n')
2018-11-20 20:47:30 +05:30
click_link 'Preview'
wait_for_requests
2019-07-07 11:18:12 +05:30
# the above generates two separate lists (not embedded) in CommonMark
2019-12-26 22:10:19 +05:30
expect(page).to have_content('sublist')
expect(page).not_to have_xpath('//ol//li//ul')
2018-11-20 20:47:30 +05:30
end
end
2017-01-15 13:20:01 +05:30
end
2017-08-17 22:00:37 +05:30
context 'visit blob edit' do
context 'redirects to sign in and returns' do
context 'as developer' do
let(:user) { create(:user) }
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
visit project_edit_blob_path(project, tree_join(branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'redirects to sign in and returns' do
expect(page).to have_current_path(new_user_session_path)
2017-09-10 17:25:29 +05:30
gitlab_sign_in(user)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
2017-08-17 22:00:37 +05:30
end
end
context 'as guest' do
let(:user) { create(:user) }
before do
2017-09-10 17:25:29 +05:30
visit project_edit_blob_path(project, tree_join(branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'redirects to sign in and returns' do
expect(page).to have_current_path(new_user_session_path)
2017-09-10 17:25:29 +05:30
gitlab_sign_in(user)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_current_path(project_blob_path(project, tree_join(branch, file_path)))
2017-08-17 22:00:37 +05:30
end
end
end
context 'as developer' do
let(:user) { create(:user) }
let(:protected_branch) { 'protected-branch' }
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-08-17 22:00:37 +05:30
project.repository.add_branch(user, protected_branch, 'master')
create(:protected_branch, project: project, name: protected_branch)
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
context 'on some branch' do
before do
2017-09-10 17:25:29 +05:30
visit project_edit_blob_path(project, tree_join(branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'shows blob editor with same branch' do
2017-09-10 17:25:29 +05:30
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
expect(find('.js-branch-name').value).to eq(branch)
2017-08-17 22:00:37 +05:30
end
end
context 'with protected branch' do
it 'shows blob editor with patch branch' do
2021-01-29 00:20:46 +05:30
freeze_time do
visit project_edit_blob_path(project, tree_join(protected_branch, file_path))
2022-05-07 20:08:51 +05:30
epoch = Time.zone.now.strftime('%s%L').last(5)
2021-01-29 00:20:46 +05:30
expect(find('.js-branch-name').value).to eq "#{user.username}-protected-branch-patch-#{epoch}"
end
2017-08-17 22:00:37 +05:30
end
end
2017-01-15 13:20:01 +05:30
end
2018-11-18 11:00:15 +05:30
context 'as maintainer' do
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_edit_blob_path(project, tree_join(branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'shows blob editor with same branch' do
2017-09-10 17:25:29 +05:30
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
expect(find('.js-branch-name').value).to eq(branch)
2017-08-17 22:00:37 +05:30
end
2017-01-15 13:20:01 +05:30
end
end
end