Commit 15012722 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Clear caches before updating MR diffs

The hook ordering influenced the diffs being generated as these used
values from before the update due to the memoization still being in
place. This commit reorders them and tests against this behaviour.
parent 721460b3
......@@ -56,8 +56,8 @@ class MergeRequest < ActiveRecord::Base
serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize
after_create :ensure_merge_request_diff, unless: :importing?
after_update :reload_diff_if_branch_changed
after_update :clear_memoized_shas
after_update :reload_diff_if_branch_changed
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
......
......@@ -1634,6 +1634,20 @@ describe MergeRequest do
subject.reload_diff
end
context 'wehn using the after_update hook to update' do
context 'when the merge request is updated' do
it 'uses the new heads to generate the diff' do
target_branch_sha = subject.target_branch_sha
source_branch_sha = subject.source_branch_sha
subject.update!(source_branch: subject.target_branch, target_branch: subject.source_branch)
expect(subject.merge_request_diff.start_commit_sha).not_to eq(target_branch_sha)
expect(subject.merge_request_diff.head_commit_sha).not_to eq(source_branch_sha)
end
end
end
end
describe '#update_diff_discussion_positions' do
......
require 'spec_helper'
describe MergeRequests::MergeService do
let(:user) { create(:user) }
let(:user2) { create(:user) }
set(:user) { create(:user) }
set(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, :simple, author: user2, assignee: user2) }
let(:project) { merge_request.project }
before do
project.team << [user, :master]
project.team << [user2, :developer]
project.add_master(user)
project.add_developer(user2)
end
describe '#execute' do
......
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