diff options
Diffstat (limited to 'spec/lib/gitlab/github_import/bulk_importing_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/bulk_importing_spec.rb | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/spec/lib/gitlab/github_import/bulk_importing_spec.rb b/spec/lib/gitlab/github_import/bulk_importing_spec.rb index 63dce51c5da..6c94973b5a8 100644 --- a/spec/lib/gitlab/github_import/bulk_importing_spec.rb +++ b/spec/lib/gitlab/github_import/bulk_importing_spec.rb @@ -3,8 +3,20 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::BulkImporting do - let(:importer) do - Class.new { include(Gitlab::GithubImport::BulkImporting) }.new + let(:project) { instance_double(Project, id: 1) } + let(:importer) { MyImporter.new(project, double) } + let(:importer_class) do + Class.new do + include Gitlab::GithubImport::BulkImporting + + def object_type + :object_type + end + end + end + + before do + stub_const 'MyImporter', importer_class end describe '#build_database_rows' do @@ -21,6 +33,24 @@ RSpec.describe Gitlab::GithubImport::BulkImporting do .with(object) .and_return(false) + expect(Gitlab::Import::Logger) + .to receive(:info) + .with( + import_type: :github, + project_id: 1, + importer: 'MyImporter', + message: '1 object_types fetched' + ) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .with( + project, + :object_type, + :fetched, + value: 1 + ) + enum = [[object, 1]].to_enum expect(importer.build_database_rows(enum)).to eq([{ title: 'Foo' }]) @@ -37,6 +67,24 @@ RSpec.describe Gitlab::GithubImport::BulkImporting do .with(object) .and_return(true) + expect(Gitlab::Import::Logger) + .to receive(:info) + .with( + import_type: :github, + project_id: 1, + importer: 'MyImporter', + message: '0 object_types fetched' + ) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .with( + project, + :object_type, + :fetched, + value: 0 + ) + enum = [[object, 1]].to_enum expect(importer.build_database_rows(enum)).to be_empty @@ -48,12 +96,32 @@ RSpec.describe Gitlab::GithubImport::BulkImporting do rows = [{ title: 'Foo' }] * 10 model = double(:model, table_name: 'kittens') - expect(Gitlab::Database) + expect(Gitlab::Import::Logger) + .to receive(:info) + .twice + .with( + import_type: :github, + project_id: 1, + importer: 'MyImporter', + message: '5 object_types imported' + ) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .twice + .with( + project, + :object_type, + :imported, + value: 5 + ) + + expect(Gitlab::Database.main) .to receive(:bulk_insert) .ordered .with('kittens', rows.first(5)) - expect(Gitlab::Database) + expect(Gitlab::Database.main) .to receive(:bulk_insert) .ordered .with('kittens', rows.last(5)) |