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

172 lines
4.9 KiB
Ruby
Raw Normal View History

2017-01-15 13:20:01 +05:30
require 'spec_helper'
2018-11-08 19:23:39 +05:30
describe 'Editing file blob', :js do
2017-08-17 22:00:37 +05:30
include TreeHelper
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
2018-03-17 18:26:18 +05:30
def edit_and_commit(commit_changes: true)
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
find('.js-edit-blob').click
2018-11-20 20:47:30 +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
2018-11-20 20:47:30 +05:30
def fill_editor(content: "class NextFeature\\nend\\n")
wait_for_requests
find('#editor')
execute_script("ace.edit('editor').setValue('#{content}')")
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)
2017-08-17 22:00:37 +05:30
edit_and_commit
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
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
old_line_count = page.all('.line_holder.old').size
new_line_count = page.all('.line_holder.new').size
expect(old_line_count).to be > 0
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))
fill_editor(content: "1. one\\n - sublist\\n")
click_link 'Preview'
wait_for_requests
# the above generates two seperate lists (not embedded) in CommonMark
expect(page).to have_content("sublist")
expect(page).not_to have_xpath("//ol//li//ul")
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
before do
2017-09-10 17:25:29 +05:30
visit project_edit_blob_path(project, tree_join(protected_branch, file_path))
2017-08-17 22:00:37 +05:30
end
it 'shows blob editor with patch branch' do
2017-09-10 17:25:29 +05:30
expect(find('.js-branch-name').value).to eq('patch-1')
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