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
...
@@ -144,7 +144,7 @@ module BulkInsertSafe
when
nil
when
nil
false
false
else
else
r
aise
ArgumentError
,
"returns needs to be :ids or nil"
r
eturns
end
end
# Handle insertions for tables with a composite primary key
# Handle insertions for tables with a composite primary key
...
@@ -161,7 +161,7 @@ module BulkInsertSafe
...
@@ -161,7 +161,7 @@ module BulkInsertSafe
ActiveRecord
::
InsertAll
ActiveRecord
::
InsertAll
.
new
(
insert_all_proxy_class
,
attributes
,
on_duplicate:
on_duplicate
,
returning:
returning
,
unique_by:
unique_by
)
.
new
(
insert_all_proxy_class
,
attributes
,
on_duplicate:
on_duplicate
,
returning:
returning
,
unique_by:
unique_by
)
.
execute
.
execute
.
pluck
(
primary_key
)
.
cast_values
(
insert_all_proxy_class
.
attribute_types
).
to_a
end
end
end
end
end
end
...
...
spec/models/concerns/bulk_insert_safe_spec.rb
View file @
e08fa9c3
...
@@ -180,29 +180,26 @@ RSpec.describe BulkInsertSafe do
...
@@ -180,29 +180,26 @@ RSpec.describe BulkInsertSafe do
end
end
context
'with returns option set'
do
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
context
'when is set to :ids'
do
it
'return an array with the primary key values for all inserted records'
do
let
(
:returns
)
{
:ids
}
items
=
bulk_insert_item_class
.
valid_list
(
1
)
expect
(
bulk_insert_item_class
.
bulk_insert!
(
items
,
returns: :ids
)).
to
contain_exactly
(
a_kind_of
(
Integer
))
it
{
is_expected
.
to
contain_exactly
(
a_kind_of
(
Integer
))
}
end
end
end
context
'when is set to nil'
do
context
'when is set to nil'
do
it
'returns an empty array'
do
let
(
:returns
)
{
nil
}
items
=
bulk_insert_item_class
.
valid_list
(
1
)
expect
(
bulk_insert_item_class
.
bulk_insert!
(
items
,
returns:
nil
)).
to
eq
([])
it
{
is_expected
.
to
eq
([])
}
end
end
end
context
'when is set to anything else'
do
context
'when is set to a list of attributes'
do
it
'raises an error'
do
let
(
:returns
)
{
[
:id
,
:sha_value
]
}
items
=
bulk_insert_item_class
.
valid_list
(
1
)
expect
{
bulk_insert_item_class
.
bulk_insert!
([
items
],
returns:
[
:id
,
:name
])
}
it
{
is_expected
.
to
contain_exactly
([
a_kind_of
(
Integer
),
'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
])
}
.
to
raise_error
(
ArgumentError
,
"returns needs to be :ids or nil"
)
end
end
end
end
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