summaryrefslogtreecommitdiff
path: root/spec/models/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:08:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:08:10 +0000
commit5d75b2b9a9d11c20667895e6aa68ea4e76658c5d (patch)
tree2aa529b0a153c805f5f4ecb357321a4e4f4c59cb /spec/models/concerns
parent6f2065c468b05658125b746169c56764a8ccddb1 (diff)
downloadgitlab-ce-5d75b2b9a9d11c20667895e6aa68ea4e76658c5d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/bulk_insert_safe_spec.rb31
1 files changed, 29 insertions, 2 deletions
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb
index a8e56cb8bdd..5ed1d6b9967 100644
--- a/spec/models/concerns/bulk_insert_safe_spec.rb
+++ b/spec/models/concerns/bulk_insert_safe_spec.rb
@@ -129,10 +129,37 @@ describe BulkInsertSafe do
end.not_to change { described_class.count }
end
- it 'does nothing and returns true when items are empty' do
- expect(described_class.bulk_insert!([])).to be(true)
+ it 'does nothing and returns an empty array when items are empty' do
+ expect(described_class.bulk_insert!([])).to eq([])
expect(described_class.count).to eq(0)
end
+
+ context 'with returns option set' do
+ context 'when is set to :ids' do
+ it 'return an array with the primary key values for all inserted records' do
+ items = described_class.valid_list(1)
+
+ expect(described_class.bulk_insert!(items, returns: :ids)).to contain_exactly(a_kind_of(Integer))
+ end
+ end
+
+ context 'when is set to nil' do
+ it 'returns an empty array' do
+ items = described_class.valid_list(1)
+
+ expect(described_class.bulk_insert!(items, returns: nil)).to eq([])
+ end
+ end
+
+ context 'when is set to anything else' do
+ it 'raises an error' do
+ items = described_class.valid_list(1)
+
+ expect { described_class.bulk_insert!([items], returns: [:id, :name]) }
+ .to raise_error(ArgumentError, "returns needs to be :ids or nil")
+ end
+ end
+ end
end
context 'when duplicate items are to be inserted' do