Commit a0fddb81 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 15012722
...@@ -810,30 +810,30 @@ describe MergeRequest do ...@@ -810,30 +810,30 @@ describe MergeRequest do
end end
describe '#can_remove_source_branch?' do describe '#can_remove_source_branch?' do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:user2) { create(:user) } set(:merge_request) { create(:merge_request, :simple) }
before do subject { merge_request }
subject.source_project.team << [user, :master]
subject.source_branch = "feature" before do
subject.target_branch = "master" subject.source_project.add_master(user)
subject.save!
end end
it "can't be removed when its a protected branch" do it "can't be removed when its a protected branch" do
allow(ProtectedBranch).to receive(:protected?).and_return(true) allow(ProtectedBranch).to receive(:protected?).and_return(true)
expect(subject.can_remove_source_branch?(user)).to be_falsey expect(subject.can_remove_source_branch?(user)).to be_falsey
end end
it "can't remove a root ref" do it "can't remove a root ref" do
subject.source_branch = "master" subject.update(source_branch: 'master', target_branch: 'feature')
subject.target_branch = "feature"
expect(subject.can_remove_source_branch?(user)).to be_falsey expect(subject.can_remove_source_branch?(user)).to be_falsey
end end
it "is unable to remove the source branch for a project the user cannot push to" do it "is unable to remove the source branch for a project the user cannot push to" do
user2 = create(:user)
expect(subject.can_remove_source_branch?(user2)).to be_falsey expect(subject.can_remove_source_branch?(user2)).to be_falsey
end end
...@@ -844,6 +844,7 @@ describe MergeRequest do ...@@ -844,6 +844,7 @@ describe MergeRequest do
end end
it "cannot be removed if the last commit is not also the head of the source branch" do it "cannot be removed if the last commit is not also the head of the source branch" do
subject.clear_memoized_shas
subject.source_branch = "lfs" subject.source_branch = "lfs"
expect(subject.can_remove_source_branch?(user)).to be_falsey expect(subject.can_remove_source_branch?(user)).to be_falsey
...@@ -1635,16 +1636,12 @@ describe MergeRequest do ...@@ -1635,16 +1636,12 @@ describe MergeRequest do
subject.reload_diff subject.reload_diff
end end
context 'wehn using the after_update hook to update' do context 'when using the after_update hook to update' do
context 'when the merge request is updated' do context 'when the branches are updated' do
it 'uses the new heads to generate the diff' do it 'uses the new heads to generate the diff' do
target_branch_sha = subject.target_branch_sha expect { subject.update!(source_branch: subject.target_branch, target_branch: subject.source_branch) }
source_branch_sha = subject.source_branch_sha .to change { subject.merge_request_diff.start_commit_sha }
.and change { subject.merge_request_diff.head_commit_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
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