summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-09-25 10:30:37 +0000
committerRobert Speicher <robert@gitlab.com>2016-09-25 10:30:37 +0000
commit0a9f9c10e466fdc711463eefbb80bd856c98c1e3 (patch)
tree7caf4fe7c39c018591171fe61c58a8fc96c94f78 /spec/lib
parentb12dedc072b56d1addfa8a8df40a82145e19f75b (diff)
parenta8829f25d3c2de4b7ca17c83f80bdd2907cf5f9a (diff)
downloadgitlab-ce-0a9f9c10e466fdc711463eefbb80bd856c98c1e3.tar.gz
Merge branch '22229-use-base-sha-when-downloading-merge-requests' into 'master'
Use base SHA for patches and diffs ## What does this MR do? Switch from using 'start SHA' to 'base SHA' for patches and diffs ## Are there points in the code the reviewer needs to double check? ## Why was this MR needed? Makes the downloaded patches and diffs on the merge request page match the frontend-rendered "changes" in these scenarios: * Unpatched gitlab-workhorse, downloading patchsets of open MRs (https://gitlab.com/gitlab-org/gitlab-workhorse/merge_requests/68) * Unpatched gitlab-workhorse, downloading diffs of open and merged MRs * Patched gitlab-workhorse, downloading patchsets of merged merge requests ## What are the relevant issue numbers? Closes #22229 See merge request !6435
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb40
1 files changed, 37 insertions, 3 deletions
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 6c7fa7e7c15..b5b685da904 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -1,8 +1,16 @@
require 'spec_helper'
describe Gitlab::Workhorse, lib: true do
- let(:project) { create(:project) }
- let(:subject) { Gitlab::Workhorse }
+ let(:project) { create(:project) }
+ let(:repository) { project.repository }
+
+ def decode_workhorse_header(array)
+ key, value = array
+ command, encoded_params = value.split(":")
+ params = JSON.parse(Base64.urlsafe_decode64(encoded_params))
+
+ [key, command, params]
+ end
describe ".send_git_archive" do
context "when the repository doesn't have an archive file path" do
@@ -11,11 +19,37 @@ describe Gitlab::Workhorse, lib: true do
end
it "raises an error" do
- expect { subject.send_git_archive(project.repository, ref: "master", format: "zip") }.to raise_error(RuntimeError)
+ expect { described_class.send_git_archive(project.repository, ref: "master", format: "zip") }.to raise_error(RuntimeError)
end
end
end
+ describe '.send_git_patch' do
+ let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
+ subject { described_class.send_git_patch(repository, diff_refs) }
+
+ it 'sets the header correctly' do
+ key, command, params = decode_workhorse_header(subject)
+
+ expect(key).to eq("Gitlab-Workhorse-Send-Data")
+ expect(command).to eq("git-format-patch")
+ expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
+ end
+ end
+
+ describe '.send_git_diff' do
+ let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
+ subject { described_class.send_git_patch(repository, diff_refs) }
+
+ it 'sets the header correctly' do
+ key, command, params = decode_workhorse_header(subject)
+
+ expect(key).to eq("Gitlab-Workhorse-Send-Data")
+ expect(command).to eq("git-format-patch")
+ expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
+ end
+ end
+
describe ".secret" do
subject { described_class.secret }