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
046b7773
Commit
046b7773
authored
Apr 16, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide a column to grouped COUNT query
That fixes Rails warning about dangerous query method
parent
2376a5ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
app/models/ci/stage.rb
app/models/ci/stage.rb
+1
-1
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+12
-0
No files found.
app/models/ci/stage.rb
View file @
046b7773
...
...
@@ -46,7 +46,7 @@ module Ci
self
.
position
=
statuses
.
select
(
:stage_idx
)
.
where
.
not
(
stage_idx:
nil
)
.
group
(
:stage_idx
)
.
order
(
'COUNT(
*
) DESC'
)
.
order
(
'COUNT(
id
) DESC'
)
.
first
&
.
stage_idx
.
to_i
end
...
...
spec/models/ci/stage_spec.rb
View file @
046b7773
...
...
@@ -286,6 +286,18 @@ RSpec.describe Ci::Stage, :models do
end
end
context
'when stage has statuses with nil idx'
do
before
do
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
,
stage_idx:
nil
)
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
,
stage_idx:
10
)
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
,
stage_idx:
nil
)
end
it
'sets index to a non-empty value'
do
expect
{
stage
.
update_legacy_status
}.
to
change
{
stage
.
reload
.
position
}.
from
(
nil
).
to
(
10
)
end
end
context
'when stage does not have statuses'
do
it
'fallbacks to zero'
do
expect
(
stage
.
reload
.
position
).
to
be_nil
...
...
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