diff options
author | Alejandro Rodríguez <alejorro70@gmail.com> | 2018-10-15 06:01:26 +0300 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2018-10-30 19:51:58 +0300 |
commit | 5c03ccee39e0bb35aa984388afa416d25c365336 (patch) | |
tree | 04b81cae84db66c1baa3f5817d65fc17ac87ee65 | |
parent | 9dade0bc0f2b4259cdcd52bd4f68a81e161745ed (diff) |
Add LfsChanges and RawDiff spec examples
-rw-r--r-- | ruby/spec/lib/gitlab/git/lfs_changes_spec.rb | 21 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb | 68 |
2 files changed, 89 insertions, 0 deletions
diff --git a/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb b/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb new file mode 100644 index 000000000..3a5c673be --- /dev/null +++ b/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::Git::LfsChanges do + include TestRepo + + let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } + let(:newrev) { '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51' } + let(:blob_object_id) { '0c304a93cb8430108629bbbcaa27db3343299bc0' } + + subject { described_class.new(repository, newrev) } + + describe '#new_pointers' do + it 'filters new objects to find lfs pointers' do + expect(subject.new_pointers(not_in: []).first.id).to eq(blob_object_id) + end + + it 'limits new_objects using object_limit' do + expect(subject.new_pointers(object_limit: 1)).to eq([]) + end + end +end diff --git a/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb b/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb new file mode 100644 index 000000000..071b9a21c --- /dev/null +++ b/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Gitlab::Git::RawDiffChange do + let(:raw_change) {} + let(:old_mode) { 0o100644 } + let(:new_mode) { 0o100644 } + let(:change) { described_class.new(raw_change, old_mode, new_mode) } + + context 'bad input' do + let(:raw_change) { 'foo' } + + it 'does not set most of the attrs' do + expect(change.blob_id).to eq('foo') + expect(change.operation).to eq(:unknown) + expect(change.old_path).to be_blank + expect(change.new_path).to be_blank + expect(change.blob_size).to eq(0) + end + end + + context 'adding a file' do + let(:raw_change) { '93e123ac8a3e6a0b600953d7598af629dec7b735 59 A bar/branch-test.txt' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:added) + expect(change.old_path).to be_blank + expect(change.new_path).to eq('bar/branch-test.txt') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'renaming a file' do + let(:raw_change) { "85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee" } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:renamed) + expect(change.old_path).to eq('files/js/commit.js.coffee') + expect(change.new_path).to eq('files/js/commit.coffee') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'modifying a file' do + let(:raw_change) { 'c60514b6d3d6bf4bec1030f70026e34dfbd69ad5 824 M README.md' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:modified) + expect(change.old_path).to eq('README.md') + expect(change.new_path).to eq('README.md') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'deleting a file' do + let(:raw_change) { '60d7a906c2fd9e4509aeb1187b98d0ea7ce827c9 15364 D files/.DS_Store' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:deleted) + expect(change.old_path).to eq('files/.DS_Store') + expect(change.new_path).to be_nil + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end +end |