diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-14 01:36:15 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-24 15:34:38 +0300 |
commit | 0377c015cf903a1d22d14086e68d1e07fe3c2643 (patch) | |
tree | d0be528c1d6a1fe44aa937fc3aeb1076aa7e3c7c /spec/lib/gitlab/import | |
parent | 842377ab3c5b80a3758ad8c36dc3358bd265bc10 (diff) |
Refactor GitHub Importer database helpers into helper methods
This in preparation for addressing idle-in-transaction timeouts for other importers.
Part of #50021
Diffstat (limited to 'spec/lib/gitlab/import')
-rw-r--r-- | spec/lib/gitlab/import/database_helpers_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import/database_helpers_spec.rb b/spec/lib/gitlab/import/database_helpers_spec.rb new file mode 100644 index 00000000000..e716155b7d5 --- /dev/null +++ b/spec/lib/gitlab/import/database_helpers_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Import::DatabaseHelpers do + let(:database_helper) do + Class.new do + include Gitlab::Import::DatabaseHelpers + end + end + + subject { database_helper.new } + + describe '.insert_and_return_id' do + let(:attributes) { { iid: 1, title: 'foo' } } + let(:project) { create(:project) } + + context 'on PostgreSQL' do + it 'returns the ID returned by the query' do + expect(Gitlab::Database) + .to receive(:bulk_insert) + .with(Issue.table_name, [attributes], return_ids: true) + .and_return([10]) + + id = subject.insert_and_return_id(attributes, project.issues) + + expect(id).to eq(10) + end + end + + context 'on MySQL' do + it 'uses a separate query to retrieve the ID' do + issue = create(:issue, project: project, iid: attributes[:iid]) + + expect(Gitlab::Database) + .to receive(:bulk_insert) + .with(Issue.table_name, [attributes], return_ids: true) + .and_return([]) + + id = subject.insert_and_return_id(attributes, project.issues) + + expect(id).to eq(issue.id) + end + end + end +end |