debian-mirror-gitlab/spec/lib/gitlab/git/blame_spec.rb

71 lines
1.9 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require "spec_helper"
2018-11-18 11:00:15 +05:30
describe Gitlab::Git::Blame, :seed_helper do
2019-03-02 22:35:43 +05:30
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
2017-08-17 22:00:37 +05:30
let(:blame) do
Gitlab::Git::Blame.new(repository, SeedRepo::Commit::ID, "CONTRIBUTING.md")
end
2018-11-08 19:23:39 +05:30
describe 'blaming a file' do
2017-09-10 17:25:29 +05:30
context "each count" do
it do
data = []
blame.each do |commit, line|
data << {
commit: commit,
line: line
}
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context "ISO-8859 encoding" do
let(:blame) do
Gitlab::Git::Blame.new(repository, SeedRepo::EncodingCommit::ID, "encoding/iso8859.txt")
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'converts to UTF-8' do
data = []
blame.each do |commit, line|
data << {
commit: commit,
line: line
}
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
commit: commit,
line: line
2017-09-10 17:25:29 +05:30
}
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
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-08-17 22:00:37 +05:30
end
end
end