Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-10-15 18:27:15 +0300
committerRobert Speicher <robert@gitlab.com>2018-10-15 18:27:15 +0300
commitf5d088eb11b066dadad06948e158b39e9432573c (patch)
tree9f1db7d7ba83f1b221bdb88b864e8efca1fd95d8 /spec
parent201143e9db57ed6f4cd72704387777b4be5ecc34 (diff)
parent399056ed783e12337a9c47b06b4aae021198f1cd (diff)
Merge branch 'zj-remove-linguist' into 'master'
Remove dependencies on Linguist Closes #35450 See merge request gitlab-org/gitlab-ce!21008
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/merge_requests/conflicts_controller_spec.rb1
-rw-r--r--spec/lib/gitlab/blob_helper_spec.rb125
-rw-r--r--spec/lib/gitlab/conflict/file_spec.rb5
-rw-r--r--spec/lib/gitlab/git/blob_snippet_spec.rb19
-rw-r--r--spec/lib/gitlab/language_data_spec.rb22
5 files changed, 147 insertions, 25 deletions
diff --git a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb
index 397cc79bde4..1e1ea9a7144 100644
--- a/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests/conflicts_controller_spec.rb
@@ -150,7 +150,6 @@ describe Projects::MergeRequests::ConflictsController do
'new_path' => path,
'blob_icon' => 'file-text-o',
'blob_path' => a_string_ending_with(path),
- 'blob_ace_mode' => 'ruby',
'content' => content)
end
end
diff --git a/spec/lib/gitlab/blob_helper_spec.rb b/spec/lib/gitlab/blob_helper_spec.rb
new file mode 100644
index 00000000000..0b56f8687c3
--- /dev/null
+++ b/spec/lib/gitlab/blob_helper_spec.rb
@@ -0,0 +1,125 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BlobHelper do
+ include FakeBlobHelpers
+
+ let(:project) { create(:project) }
+ let(:blob) { fake_blob(path: 'file.txt') }
+ let(:large_blob) { fake_blob(path: 'test.pdf', size: 2.megabytes, binary: true) }
+
+ describe '#extname' do
+ it 'returns the extension' do
+ expect(blob.extname).to eq('.txt')
+ end
+ end
+
+ describe '#known_extension?' do
+ it 'returns true' do
+ expect(blob.known_extension?).to be_truthy
+ end
+ end
+
+ describe '#viewable' do
+ it 'returns true' do
+ expect(blob.viewable?).to be_truthy
+ end
+
+ it 'returns false' do
+ expect(large_blob.viewable?).to be_falsey
+ end
+ end
+
+ describe '#large?' do
+ it 'returns false' do
+ expect(blob.large?).to be_falsey
+ end
+
+ it 'returns true' do
+ expect(large_blob.large?).to be_truthy
+ end
+ end
+
+ describe '#binary?' do
+ it 'returns true' do
+ expect(large_blob.binary?).to be_truthy
+ end
+
+ it 'returns false' do
+ expect(blob.binary?).to be_falsey
+ end
+ end
+
+ describe '#text?' do
+ it 'returns true' do
+ expect(blob.text?).to be_truthy
+ end
+
+ it 'returns false' do
+ expect(large_blob.text?).to be_falsey
+ end
+ end
+
+ describe '#image?' do
+ it 'returns false' do
+ expect(blob.image?).to be_falsey
+ end
+ end
+
+ describe '#mime_type' do
+ it 'returns text/plain' do
+ expect(blob.mime_type).to eq('text/plain')
+ end
+
+ it 'returns application/pdf' do
+ expect(large_blob.mime_type).to eq('application/pdf')
+ end
+ end
+
+ describe '#binary_mime_type?' do
+ it 'returns false' do
+ expect(blob.binary_mime_type?).to be_falsey
+ end
+ end
+
+ describe '#lines' do
+ it 'returns the payload in an Array' do
+ expect(blob.lines).to eq(['foo'])
+ end
+ end
+
+ describe '#content_type' do
+ it 'returns text/plain' do
+ expect(blob.content_type).to eq('text/plain; charset=utf-8')
+ end
+
+ it 'returns text/plain' do
+ expect(large_blob.content_type).to eq('application/pdf')
+ end
+ end
+
+ describe '#encoded_newlines_re' do
+ it 'returns a regular expression' do
+ expect(blob.encoded_newlines_re).to eq(/\r\n|\r|\n/)
+ end
+ end
+
+ describe '#ruby_encoding' do
+ it 'returns UTF-8' do
+ expect(blob.ruby_encoding).to eq('UTF-8')
+ end
+ end
+
+ describe '#encoding' do
+ it 'returns UTF-8' do
+ expect(blob.ruby_encoding).to eq('UTF-8')
+ end
+ end
+
+ describe '#empty?' do
+ it 'returns false' do
+ expect(blob.empty?).to be_falsey
+ end
+ end
+end
diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb
index 1bd077ddbdf..a955ce54e85 100644
--- a/spec/lib/gitlab/conflict/file_spec.rb
+++ b/spec/lib/gitlab/conflict/file_spec.rb
@@ -267,11 +267,6 @@ FILE
it 'includes the full content of the conflict' do
expect(conflict_file.as_json(full_content: true)).to have_key(:content)
end
-
- it 'includes the detected language of the conflict file' do
- expect(conflict_file.as_json(full_content: true)[:blob_ace_mode])
- .to eq('ruby')
- end
end
end
end
diff --git a/spec/lib/gitlab/git/blob_snippet_spec.rb b/spec/lib/gitlab/git/blob_snippet_spec.rb
deleted file mode 100644
index 6effec8295c..00000000000
--- a/spec/lib/gitlab/git/blob_snippet_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# encoding: UTF-8
-
-require "spec_helper"
-
-describe Gitlab::Git::BlobSnippet, :seed_helper do
- describe '#data' do
- context 'empty lines' do
- let(:snippet) { Gitlab::Git::BlobSnippet.new('master', nil, nil, nil) }
-
- it { expect(snippet.data).to be_nil }
- end
-
- context 'present lines' do
- let(:snippet) { Gitlab::Git::BlobSnippet.new('master', %w(wow much), 1, 'wow.rb') }
-
- it { expect(snippet.data).to eq("wow\nmuch") }
- end
- end
-end
diff --git a/spec/lib/gitlab/language_data_spec.rb b/spec/lib/gitlab/language_data_spec.rb
new file mode 100644
index 00000000000..b08150855fe
--- /dev/null
+++ b/spec/lib/gitlab/language_data_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::LanguageData do
+ describe '#extensions' do
+ before do
+ described_class.clear_extensions!
+ end
+
+ it 'loads the extensions once' do
+ expect(YAML).to receive(:load_file).once.and_call_original
+
+ 2.times do
+ expect(described_class.extensions).to be_a(Set)
+ expect(described_class.extensions.count).to be > 0
+ # Sanity check for known extensions
+ expect(described_class.extensions).to include(*%w(.rb .yml .json))
+ end
+ end
+ end
+end