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
b2f241bd
Commit
b2f241bd
authored
May 05, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify sql for sorting
parent
a72f4630
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
13 deletions
+15
-13
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+1
-1
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+14
-12
No files found.
app/models/concerns/issuable.rb
View file @
b2f241bd
...
...
@@ -38,7 +38,7 @@ module Issuable
scope
:order_milestone_due_desc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date DESC, milestones.id DESC'
)
}
scope
:order_milestone_due_asc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date ASC, milestones.id ASC'
)
}
scope
:without_label
,
->
{
joins
(
"LEFT OUTER JOIN label_links ON label_links.target_type = '
#{
name
}
' AND label_links.target_id =
#{
table_name
}
.id"
).
where
(
label_links:
{
id:
nil
})
}
scope
:order_weight_desc
,
->
{
reorder
(
'CASE WHEN weight IS NULL then 0 ELSE 1 END DESC
, weight DESC'
)
}
scope
:order_weight_desc
,
->
{
reorder
(
'weight IS NOT NULL
, weight DESC'
)
}
scope
:order_weight_asc
,
->
{
reorder
(
'weight ASC'
)
}
scope
:join_project
,
->
{
joins
(
:project
)
}
...
...
spec/models/concerns/issuable_spec.rb
View file @
b2f241bd
...
...
@@ -115,21 +115,23 @@ describe Issue, "Issuable" do
end
describe
"#sort"
do
let!
(
:issue
)
{
create
(
:issue
)
}
let
(
:project
)
{
issue
.
project
}
let!
(
:issue2
)
{
create
(
:issue
,
weight:
1
,
project:
project
)
}
let!
(
:issue3
)
{
create
(
:issue
,
weight:
2
,
project:
project
)
}
let!
(
:issue4
)
{
create
(
:issue
,
weight:
3
,
project:
project
)
}
let
(
:project
)
{
build_stubbed
(
:empty_project
)
}
it
"sorts by weight desc"
do
issues
=
Issue
.
where
(
project_id:
project
.
id
).
sort
(
'weight_desc'
)
expect
(
issues
).
to
match_array
([
issue4
,
issue3
,
issue2
,
issue
])
end
context
"by weight"
do
let!
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let!
(
:issue2
)
{
create
(
:issue
,
weight:
1
,
project:
project
)
}
let!
(
:issue3
)
{
create
(
:issue
,
weight:
2
,
project:
project
)
}
let!
(
:issue4
)
{
create
(
:issue
,
weight:
3
,
project:
project
)
}
it
"sorts desc"
do
issues
=
project
.
issues
.
sort
(
'weight_desc'
)
expect
(
issues
).
to
match_array
([
issue4
,
issue3
,
issue2
,
issue
])
end
it
"sorts by weight asc"
do
issues
=
Issue
.
where
(
project_id:
project
.
id
).
sort
(
'weight_asc'
)
expect
(
issues
).
to
match_array
([
issue2
,
issue3
,
issue4
,
issue
])
it
"sorts asc"
do
issues
=
project
.
issues
.
sort
(
'weight_asc'
)
expect
(
issues
).
to
match_array
([
issue2
,
issue3
,
issue4
,
issue
])
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