summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/git')
-rw-r--r--spec/lib/gitlab/git/diff_collection_spec.rb46
-rw-r--r--spec/lib/gitlab/git/diff_spec.rb30
-rw-r--r--spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb14
3 files changed, 58 insertions, 32 deletions
diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb
index 0d19d35bc52..6aa4f884d20 100644
--- a/spec/lib/gitlab/git/diff_collection_spec.rb
+++ b/spec/lib/gitlab/git/diff_collection_spec.rb
@@ -3,6 +3,31 @@
require 'spec_helper'
describe Gitlab::Git::DiffCollection, :seed_helper do
+ before do
+ stub_const('MutatingConstantIterator', Class.new)
+
+ MutatingConstantIterator.class_eval do
+ include Enumerable
+
+ def initialize(count, value)
+ @count = count
+ @value = value
+ end
+
+ def each
+ return enum_for(:each) unless block_given?
+
+ loop do
+ break if @count.zero?
+
+ # It is critical to decrement before yielding. We may never reach the lines after 'yield'.
+ @count -= 1
+ yield @value
+ end
+ end
+ end
+ end
+
subject do
Gitlab::Git::DiffCollection.new(
iterator,
@@ -659,25 +684,4 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
def fake_diff(line_length, line_count)
{ 'diff' => "#{'a' * line_length}\n" * line_count }
end
-
- class MutatingConstantIterator
- include Enumerable
-
- def initialize(count, value)
- @count = count
- @value = value
- end
-
- def each
- return enum_for(:each) unless block_given?
-
- loop do
- break if @count.zero?
-
- # It is critical to decrement before yielding. We may never reach the lines after 'yield'.
- @count -= 1
- yield @value
- end
- end
- end
end
diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb
index ac606da5cc1..ff54d7fbcd3 100644
--- a/spec/lib/gitlab/git/diff_spec.rb
+++ b/spec/lib/gitlab/git/diff_spec.rb
@@ -122,6 +122,36 @@ EOT
end
end
end
+
+ context 'using a Gitaly::CommitDelta' do
+ let(:commit_delta) do
+ Gitaly::CommitDelta.new(
+ to_path: ".gitmodules",
+ from_path: ".gitmodules",
+ old_mode: 0100644,
+ new_mode: 0100644,
+ from_id: '357406f3075a57708d0163752905cc1576fceacc',
+ to_id: '8e5177d718c561d36efde08bad36b43687ee6bf0'
+ )
+ end
+ let(:diff) { described_class.new(commit_delta) }
+
+ it 'initializes the diff' do
+ expect(diff.to_hash).to eq(@raw_diff_hash.merge(diff: ''))
+ end
+
+ it 'is not too large' do
+ expect(diff).not_to be_too_large
+ end
+
+ it 'has an empty diff' do
+ expect(diff.diff).to be_empty
+ end
+
+ it 'is not a binary' do
+ expect(diff).not_to have_binary_notice
+ end
+ end
end
describe 'straight diffs' do
diff --git a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
index b396e5d22c3..8339006fe9f 100644
--- a/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
+++ b/spec/lib/gitlab/git/rugged_impl/use_rugged_spec.rb
@@ -8,7 +8,6 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:feature_flag_name) { 'feature-flag-name' }
- let(:feature_flag) { Feature.get(feature_flag_name) }
let(:temp_gitaly_metadata_file) { create_temporary_gitaly_metadata_file }
before(:all) do
@@ -49,10 +48,6 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
end
context 'when feature flag is not persisted' do
- before do
- allow(Feature).to receive(:persisted?).with(feature_flag).and_return(false)
- end
-
context 'when running puma with multiple threads' do
before do
allow(subject).to receive(:running_puma_with_multiple_threads?).and_return(true)
@@ -97,18 +92,15 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
end
context 'when feature flag is persisted' do
- before do
- allow(Feature).to receive(:persisted?).with(feature_flag).and_return(true)
- end
-
it 'returns false when the feature flag is off' do
- allow(feature_flag).to receive(:enabled?).and_return(false)
+ Feature.disable(feature_flag_name)
expect(subject.use_rugged?(repository, feature_flag_name)).to be_falsey
end
it "returns true when feature flag is on" do
- allow(feature_flag).to receive(:enabled?).and_return(true)
+ Feature.enable(feature_flag_name)
+
allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(false)
expect(subject.use_rugged?(repository, feature_flag_name)).to be true