2017-01-04 13:43:06 -05:00
|
|
|
# coding: utf-8
|
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe Gitlab::Git::Blame, seed_helper: true do
|
2017-08-22 07:54:14 -04:00
|
|
|
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') }
|
2017-01-04 13:43:06 -05:00
|
|
|
let(:blame) do
|
|
|
|
Gitlab::Git::Blame.new(repository, SeedRepo::Commit::ID, "CONTRIBUTING.md")
|
|
|
|
end
|
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
shared_examples 'blaming a file' do
|
|
|
|
context "each count" do
|
|
|
|
it do
|
|
|
|
data = []
|
|
|
|
blame.each do |commit, line|
|
|
|
|
data << {
|
|
|
|
commit: commit,
|
|
|
|
line: line
|
|
|
|
}
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
expect(data.size).to eq(95)
|
|
|
|
expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit)
|
|
|
|
expect(data.first[:line]).to eq("# Contribute to GitLab")
|
|
|
|
expect(data.first[:line]).to be_utf8
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
context "ISO-8859 encoding" do
|
|
|
|
let(:blame) do
|
|
|
|
Gitlab::Git::Blame.new(repository, SeedRepo::EncodingCommit::ID, "encoding/iso8859.txt")
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
it 'converts to UTF-8' do
|
|
|
|
data = []
|
|
|
|
blame.each do |commit, line|
|
|
|
|
data << {
|
|
|
|
commit: commit,
|
|
|
|
line: line
|
|
|
|
}
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
expect(data.size).to eq(1)
|
|
|
|
expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit)
|
|
|
|
expect(data.first[:line]).to eq("Ä ü")
|
|
|
|
expect(data.first[:line]).to be_utf8
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
context "unknown encoding" do
|
|
|
|
let(:blame) do
|
|
|
|
Gitlab::Git::Blame.new(repository, SeedRepo::EncodingCommit::ID, "encoding/iso8859.txt")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'converts to UTF-8' do
|
|
|
|
expect(CharlockHolmes::EncodingDetector).to receive(:detect).and_return(nil)
|
|
|
|
data = []
|
|
|
|
blame.each do |commit, line|
|
|
|
|
data << {
|
2017-01-04 13:43:06 -05:00
|
|
|
commit: commit,
|
|
|
|
line: line
|
2017-07-28 08:16:26 -04:00
|
|
|
}
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
|
2017-07-28 08:16:26 -04:00
|
|
|
expect(data.size).to eq(1)
|
|
|
|
expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit)
|
|
|
|
expect(data.first[:line]).to eq(" ")
|
|
|
|
expect(data.first[:line]).to be_utf8
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
end
|
2017-07-28 08:16:26 -04:00
|
|
|
|
|
|
|
context 'when Gitaly blame feature is enabled' do
|
|
|
|
it_behaves_like 'blaming a file'
|
|
|
|
end
|
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
context 'when Gitaly blame feature is disabled', :skip_gitaly_mock do
|
2017-07-28 08:16:26 -04:00
|
|
|
it_behaves_like 'blaming a file'
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|