Commit 636637d3 authored by Valery Sizov's avatar Valery Sizov

Fix: MergeRequestSerializer breaks on when source_project doesn't exist anymore

parent c07b2c04
......@@ -788,6 +788,9 @@ class MergeRequest < ActiveRecord::Base
end
def rebase_in_progress?
# The source project can be deleted
return false unless source_project
File.exist?(rebase_dir_path) && !clean_stuck_rebase
end
......
---
title: 'Fix: MergeRequestSerializer breaks on MergeRequest#rebase_dir_path when source_project
doesn''t exist anymore'
merge_request:
author:
......@@ -752,20 +752,32 @@ describe MergeRequest, models: true do
end
describe '#rebase_in_progress?' do
it 'return true' do
it 'returns true' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:new).and_return(double(:file, mtime: Time.now))
expect(subject.rebase_in_progress?).to be_truthy
end
it 'return false' do
it 'returns false' do
allow(File).to receive(:exist?).with(subject.rebase_dir_path).and_return(false)
expect(subject.rebase_in_progress?).to be_falsey
end
it 'return false if temporary file exists by is expired' do
it 'returns false if temporary file exists by is expired' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:new).and_return(double(:file, mtime: Time.now - 2.hours))
expect(subject.rebase_in_progress?).to be_falsey
end
it 'returns false if source_project is removed' do
allow(subject).to receive(:source_project).and_return(nil)
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:new).and_return(double(:file, mtime: Time.now))
expect(File).not_to have_received(:exist?)
expect(subject.rebase_in_progress?).to be_falsey
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment