diff options
author | Frank West <frank.west.iii@gmail.com> | 2016-08-08 06:29:23 +0300 |
---|---|---|
committer | Frank West <frank.west.iii@gmail.com> | 2016-08-15 05:34:55 +0300 |
commit | ade0c2c8922c0838ba85cf69419cbb109453d6b2 (patch) | |
tree | 34631dfd4d42827c94cb7b4883b2f0127d63964e /spec/features | |
parent | 30f5b9a5b711b46f1065baf755e413ceced5646b (diff) |
Prevents accidental overwrites of commits from UI
Currently when a user performs an update of a file through the UI and there
has already been a change committed to the file the previous commits will be
overwritten without a check to see if the file has been changed.
This commit uses the last commit sha at the time the user starts editing the
file and compares it with the current sha of the file being edited to ensure
they are the same before committing the file. If the shas do not match we
throw an exception preventing the commit from the commit from occurring.
Fixes #5857
Diffstat (limited to 'spec/features')
-rw-r--r-- | spec/features/projects/files/editing_a_file_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/features/projects/files/editing_a_file_spec.rb b/spec/features/projects/files/editing_a_file_spec.rb new file mode 100644 index 00000000000..fe047e00409 --- /dev/null +++ b/spec/features/projects/files/editing_a_file_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +feature 'User wants to edit a file', feature: true do + include WaitForAjax + + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:commit_params) do + { + source_branch: project.default_branch, + target_branch: project.default_branch, + 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 + + background do + project.team << [user, :master] + login_as user + visit namespace_project_edit_blob_path(project.namespace, project, + File.join(project.default_branch, '.gitignore')) + end + + scenario '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 +end |