diff options
Diffstat (limited to 'spec/lib/gitlab/database_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 15fb1503529..a033316a6d9 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -228,6 +228,7 @@ describe Gitlab::Database do describe '.bulk_insert' do before do allow(described_class).to receive(:connection).and_return(connection) + allow(described_class).to receive(:version).and_return(version) allow(connection).to receive(:quote_column_name, &:itself) allow(connection).to receive(:quote, &:itself) allow(connection).to receive(:execute) @@ -242,6 +243,8 @@ describe Gitlab::Database do ] end + let_it_be(:version) { 9.6 } + it 'does nothing with empty rows' do expect(connection).not_to receive(:execute) @@ -307,6 +310,29 @@ describe Gitlab::Database do expect(ids).to eq([10]) end + + context 'with version >= 9.5' do + it 'allows setting the upsert to do nothing' do + expect(connection) + .to receive(:execute) + .with(/ON CONFLICT DO NOTHING/) + + described_class + .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing) + end + end + + context 'with version < 9.5' do + let(:version) { 9.4 } + it 'refuses setting the upsert' do + expect(connection) + .not_to receive(:execute) + .with(/ON CONFLICT/) + + described_class + .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing) + end + end end end |