debian-mirror-gitlab/spec/features/projects/files/editing_a_file_spec.rb

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

66 lines
2.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Projects > Files > User wants to edit a file', feature_category: :projects do
2023-06-20 00:43:36 +05:30
include ProjectForksHelper
let(:project) { create(:project, :repository, :public) }
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2016-09-13 17:45:13 +05:30
let(:commit_params) do
{
2017-08-17 22:00:37 +05:30
start_branch: project.default_branch,
branch_name: project.default_branch,
2016-09-13 17:45:13 +05:30
commit_message: "Committing First Update",
file_path: ".gitignore",
file_content: "First Update",
last_commit_sha: Gitlab::Git::Commit.last_for_path(project.repository, project.default_branch,
".gitignore").sha
}
end
2023-06-20 00:43:36 +05:30
context 'when the user has write access' do
before do
sign_in user
visit project_edit_blob_path(project,
File.join(project.default_branch, '.gitignore'))
end
it 'file has been updated since the user opened the edit page' do
Files::UpdateService.new(project, user, commit_params).execute
click_button 'Commit changes'
expect(page).to have_content 'Someone edited the file the same time you did.'
end
2016-09-13 17:45:13 +05:30
end
2023-06-20 00:43:36 +05:30
context 'when the user does not have write access' do
let(:user) { create(:user) }
context 'and the user has a fork of the project' do
let(:forked_project) { fork_project(project, user, namespace: user.namespace, repository: true) }
before do
forked_project
sign_in user
visit project_edit_blob_path(project,
File.join(project.default_branch, '.gitignore'))
end
context 'and the forked project is ahead of the upstream project' do
before do
Files::UpdateService.new(forked_project, user, commit_params).execute
end
2016-09-13 17:45:13 +05:30
2023-06-20 00:43:36 +05:30
it 'renders an error message' do
click_button 'Commit changes'
2016-09-13 17:45:13 +05:30
2023-06-20 00:43:36 +05:30
expect(page).to have_content(
%(Error: Can't edit this file. The fork and upstream project have diverged. Edit the file on the fork)
)
end
end
end
2016-09-13 17:45:13 +05:30
end
end