diff options
author | Nick Thomas <nick@gitlab.com> | 2018-01-29 11:21:25 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-01-29 11:21:25 +0000 |
commit | 70a7164e4562e0614bee4291022493f5d0f979b8 (patch) | |
tree | 758d8bc3e244a48d014647bd6bbebf5019792e64 | |
parent | 092a34fe93c64ab637a8ce0524adba6c9cf4cdf7 (diff) | |
parent | f0df45fb8a79056c81da659678be571329831cff (diff) | |
download | gitlab-ce-70a7164e4562e0614bee4291022493f5d0f979b8.tar.gz |
Merge branch 'fix-merged-at-check-for-reverted-mrs' into 'master'
Fix MR revert check when no merged_at is present
See merge request gitlab-org/gitlab-ce!16760
-rw-r--r-- | app/models/merge_request.rb | 12 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 30 |
2 files changed, 26 insertions, 16 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 4accb08eaf9..f6d4843abc3 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -989,13 +989,13 @@ class MergeRequest < ActiveRecord::Base merged_at = metrics&.merged_at notes_association = notes_with_associations - # It is not guaranteed that Note#created_at will be strictly later than - # MergeRequestMetric#merged_at. Nanoseconds on MySQL may break this - # comparison, as will a HA environment if clocks are not *precisely* - # synchronized. Add a minute's leeway to compensate for both possibilities - cutoff = merged_at - 1.minute - if merged_at + # It is not guaranteed that Note#created_at will be strictly later than + # MergeRequestMetric#merged_at. Nanoseconds on MySQL may break this + # comparison, as will a HA environment if clocks are not *precisely* + # synchronized. Add a minute's leeway to compensate for both possibilities + cutoff = merged_at - 1.minute + notes_association = notes_association.where('created_at >= ?', cutoff) end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 429b6615131..15f9c68e400 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1064,16 +1064,6 @@ describe MergeRequest do end describe '#can_be_reverted?' do - context 'when there is no merged_at for the MR' do - before do - subject.metrics.update!(merged_at: nil) - end - - it 'returns false' do - expect(subject.can_be_reverted?(nil)).to be_falsey - end - end - context 'when there is no merge_commit for the MR' do before do subject.metrics.update!(merged_at: Time.now.utc) @@ -1097,6 +1087,16 @@ describe MergeRequest do end end + context 'when there is no merged_at for the MR' do + before do + subject.metrics.update!(merged_at: nil) + end + + it 'returns true' do + expect(subject.can_be_reverted?(nil)).to be_truthy + end + end + context 'when there is a revert commit' do let(:current_user) { subject.author } let(:branch) { subject.target_branch } @@ -1127,6 +1127,16 @@ describe MergeRequest do end end + context 'when there is no merged_at for the MR' do + before do + subject.metrics.update!(merged_at: nil) + end + + it 'returns false' do + expect(subject.can_be_reverted?(current_user)).to be_falsey + end + end + context 'when the revert commit is mentioned in a note just before the MR was merged' do before do subject.notes.last.update!(created_at: subject.metrics.merged_at - 30.seconds) |