2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Lfs::UnlockFileService do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:lock_author) { create(:user) }
|
|
|
|
let!(:lock) { create(:lfs_file_lock, user: lock_author, project: project) }
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
subject { described_class.new(project, current_user, params) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'when not authorized' do
|
|
|
|
it "doesn't succeed" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:http_status]).to eq(403)
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(result[:message]).to eq(_('You have no permissions'))
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authorized' do
|
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when lock does not exists' do
|
|
|
|
let(:params) { { id: 123 } }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it "doesn't succeed" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:http_status]).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unlocked by the author' do
|
|
|
|
let(:current_user) { lock_author }
|
|
|
|
let(:params) { { id: lock.id } }
|
|
|
|
|
|
|
|
it "succeeds" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:success)
|
|
|
|
expect(result[:lock]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unlocked by a different user' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:params) { { id: lock.id } }
|
|
|
|
|
|
|
|
it "doesn't succeed" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:message]).to match(/is locked by GitLab User #{lock_author.id}/)
|
|
|
|
expect(result[:http_status]).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when forced' do
|
|
|
|
let(:developer) { create(:user) }
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:maintainer) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(maintainer)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'by a regular user' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
let(:params) do
|
|
|
|
{ id: lock.id,
|
|
|
|
force: true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't succeed" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(result[:message]).to eq(_('You must have maintainer access to force delete a lock'))
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(result[:http_status]).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'by a maintainer user' do
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:current_user) { maintainer }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:params) do
|
|
|
|
{ id: lock.id,
|
|
|
|
force: true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds" do
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:success)
|
|
|
|
expect(result[:lock]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|