2018-02-07 08:00:53 -05:00
|
|
|
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)
|
|
|
|
expect(result[:message]).to eq('You have no permissions')
|
|
|
|
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 } }
|
|
|
|
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) }
|
2018-07-11 10:36:08 -04:00
|
|
|
let(:maintainer) { create(:user) }
|
2018-02-07 08:00:53 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
2018-02-07 08:00:53 -05:00
|
|
|
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)
|
2018-06-03 23:50:28 -04:00
|
|
|
expect(result[:message]).to match(/You must have maintainer access/)
|
2018-02-07 08:00:53 -05:00
|
|
|
expect(result[:http_status]).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 23:50:28 -04:00
|
|
|
context 'by a maintainer user' do
|
2018-07-11 10:36:08 -04:00
|
|
|
let(:current_user) { maintainer }
|
2018-02-07 08:00:53 -05:00
|
|
|
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
|