Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e08fa9c3
Commit
e08fa9c3
authored
Oct 12, 2021
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow BulkInsertSafe module to return all columns of a relation
parent
4eaa23f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
16 deletions
+13
-16
app/models/concerns/bulk_insert_safe.rb
app/models/concerns/bulk_insert_safe.rb
+2
-2
spec/models/concerns/bulk_insert_safe_spec.rb
spec/models/concerns/bulk_insert_safe_spec.rb
+11
-14
No files found.
app/models/concerns/bulk_insert_safe.rb
View file @
e08fa9c3
...
...
@@ -144,7 +144,7 @@ module BulkInsertSafe
when
nil
false
else
r
aise
ArgumentError
,
"returns needs to be :ids or nil"
r
eturns
end
# Handle insertions for tables with a composite primary key
...
...
@@ -161,7 +161,7 @@ module BulkInsertSafe
ActiveRecord
::
InsertAll
.
new
(
insert_all_proxy_class
,
attributes
,
on_duplicate:
on_duplicate
,
returning:
returning
,
unique_by:
unique_by
)
.
execute
.
pluck
(
primary_key
)
.
cast_values
(
insert_all_proxy_class
.
attribute_types
).
to_a
end
end
end
...
...
spec/models/concerns/bulk_insert_safe_spec.rb
View file @
e08fa9c3
...
...
@@ -180,29 +180,26 @@ RSpec.describe BulkInsertSafe do
end
context
'with returns option set'
do
let
(
:items
)
{
bulk_insert_item_class
.
valid_list
(
1
)
}
subject
(
:bulk_insert
)
{
bulk_insert_item_class
.
bulk_insert!
(
items
,
returns:
returns
)
}
context
'when is set to :ids'
do
it
'return an array with the primary key values for all inserted records'
do
items
=
bulk_insert_item_class
.
valid_list
(
1
)
let
(
:returns
)
{
:ids
}
expect
(
bulk_insert_item_class
.
bulk_insert!
(
items
,
returns: :ids
)).
to
contain_exactly
(
a_kind_of
(
Integer
))
end
it
{
is_expected
.
to
contain_exactly
(
a_kind_of
(
Integer
))
}
end
context
'when is set to nil'
do
it
'returns an empty array'
do
items
=
bulk_insert_item_class
.
valid_list
(
1
)
let
(
:returns
)
{
nil
}
expect
(
bulk_insert_item_class
.
bulk_insert!
(
items
,
returns:
nil
)).
to
eq
([])
end
it
{
is_expected
.
to
eq
([])
}
end
context
'when is set to anything else'
do
it
'raises an error'
do
items
=
bulk_insert_item_class
.
valid_list
(
1
)
context
'when is set to a list of attributes'
do
let
(
:returns
)
{
[
:id
,
:sha_value
]
}
expect
{
bulk_insert_item_class
.
bulk_insert!
([
items
],
returns:
[
:id
,
:name
])
}
.
to
raise_error
(
ArgumentError
,
"returns needs to be :ids or nil"
)
end
it
{
is_expected
.
to
contain_exactly
([
a_kind_of
(
Integer
),
'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
])
}
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment