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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
af18cddd
Commit
af18cddd
authored
Apr 20, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udpated a few things based on MR feedback. Also added model spec
parent
8619208b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
203 additions
and
176 deletions
+203
-176
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-3
app/helpers/milestones_helper.rb
app/helpers/milestones_helper.rb
+1
-1
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+8
-1
spec/features/issues/filter_by_labels_spec.rb
spec/features/issues/filter_by_labels_spec.rb
+167
-170
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+25
-1
No files found.
app/finders/issuable_finder.rb
View file @
af18cddd
...
@@ -270,8 +270,7 @@ class IssuableFinder
...
@@ -270,8 +270,7 @@ class IssuableFinder
if
filter_by_no_label?
if
filter_by_no_label?
items
=
items
.
without_label
items
=
items
.
without_label
else
else
items
=
items
.
with_label
(
label_names
.
flatten
)
items
=
items
.
with_label
(
label_names
)
if
projects
if
projects
items
=
items
.
where
(
labels:
{
project_id:
projects
})
items
=
items
.
where
(
labels:
{
project_id:
projects
})
end
end
...
@@ -282,7 +281,7 @@ class IssuableFinder
...
@@ -282,7 +281,7 @@ class IssuableFinder
end
end
def
label_names
def
label_names
params
[
:label_name
].
split
(
','
)
params
[
:label_name
].
is_a?
(
String
)
?
params
[
:label_name
].
split
(
','
)
:
params
[
:label_name
]
end
end
def
current_user_related?
def
current_user_related?
...
...
app/helpers/milestones_helper.rb
View file @
af18cddd
...
@@ -32,7 +32,7 @@ module MilestonesHelper
...
@@ -32,7 +32,7 @@ module MilestonesHelper
end
end
def
milestone_issues_by_label_count
(
milestone
,
label
,
state
:)
def
milestone_issues_by_label_count
(
milestone
,
label
,
state
:)
milestone
.
issues
.
with_label
(
[
label
.
title
]
).
send
(
state
).
size
milestone
.
issues
.
with_label
(
label
.
title
).
send
(
state
).
size
end
end
def
milestone_progress_bar
(
milestone
)
def
milestone_progress_bar
(
milestone
)
...
...
app/models/concerns/issuable.rb
View file @
af18cddd
...
@@ -37,7 +37,6 @@ module Issuable
...
@@ -37,7 +37,6 @@ module Issuable
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:closed
,
->
{
with_state
(
:closed
)
}
scope
:order_milestone_due_desc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date DESC, milestones.id DESC'
)
}
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
:order_milestone_due_asc
,
->
{
joins
(
:milestone
).
reorder
(
'milestones.due_date ASC, milestones.id ASC'
)
}
scope
:with_label
,
->
(
title
)
{
joins
(
:labels
).
where
(
labels:
{
title:
title
}).
group
(
'issues.id'
).
having
(
"count(distinct labels.title) =
#{
title
.
count
}
"
)
}
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
: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
:join_project
,
->
{
joins
(
:project
)
}
scope
:join_project
,
->
{
joins
(
:project
)
}
...
@@ -122,6 +121,14 @@ module Issuable
...
@@ -122,6 +121,14 @@ module Issuable
joins
(
join_clause
).
group
(
issuable_table
[
:id
]).
reorder
(
"COUNT(notes.id) DESC"
)
joins
(
join_clause
).
group
(
issuable_table
[
:id
]).
reorder
(
"COUNT(notes.id) DESC"
)
end
end
def
with_label
(
title
)
if
title
.
is_a?
(
Array
)
&&
title
.
count
>
1
joins
(
:labels
).
where
(
labels:
{
title:
title
}).
group
(
'issues.id'
).
having
(
"count(distinct labels.title) =
#{
title
.
count
}
"
)
else
joins
(
:labels
).
where
(
labels:
{
title:
title
})
end
end
end
end
def
today?
def
today?
...
...
spec/features/issues/filter_by_labels_spec.rb
View file @
af18cddd
# Uncomment once this is merged with multi-filter-labels
require
'rails_helper'
# Changes are related to using AND in label filters instead of OR
feature
'Issue filtering by Labels'
,
feature:
true
do
# require 'rails_helper'
let
(
:project
)
{
create
(
:project
,
:public
)
}
#
let!
(
:user
)
{
create
(
:user
)}
# feature 'Issue filtering by Labels', feature: true do
let!
(
:label
)
{
create
(
:label
,
project:
project
)
}
# let(:project) { create(:project, :public) }
# let!(:user) { create(:user)}
before
do
# let!(:label) { create(:label, project: project) }
[
'bug'
,
'feature'
,
'enhancement'
].
each
do
|
title
|
#
create
(
:label
,
# before do
project:
project
,
# ['bug', 'feature', 'enhancement'].each do |title|
title:
title
)
# create(:label,
end
# project: project,
# title: title)
issue1
=
create
(
:issue
,
title:
"Bugfix1"
,
project:
project
)
# end
issue1
.
labels
<<
project
.
labels
.
find_by
(
title:
'bug'
)
#
# issue1 = create(:issue, title: "Bugfix1", project: project)
issue2
=
create
(
:issue
,
title:
"Bugfix2"
,
project:
project
)
# issue1.labels << project.labels.find_by(title: 'bug')
issue2
.
labels
<<
project
.
labels
.
find_by
(
title:
'bug'
)
#
issue2
.
labels
<<
project
.
labels
.
find_by
(
title:
'enhancement'
)
# issue2 = create(:issue, title: "Bugfix2", project: project)
# issue2.labels << project.labels.find_by(title: 'bug')
issue3
=
create
(
:issue
,
title:
"Feature1"
,
project:
project
)
# issue2.labels << project.labels.find_by(title: 'enhancement')
issue3
.
labels
<<
project
.
labels
.
find_by
(
title:
'feature'
)
#
# issue3 = create(:issue, title: "Feature1", project: project)
project
.
team
<<
[
user
,
:master
]
# issue3.labels << project.labels.find_by(title: 'feature')
login_as
(
user
)
#
# project.team << [user, :master]
visit
namespace_project_issues_path
(
project
.
namespace
,
project
)
# login_as(user)
end
#
# visit namespace_project_issues_path(project.namespace, project)
context
'filter by label bug'
,
js:
true
do
# end
before
do
#
page
.
find
(
'.js-label-select'
).
click
# context 'filter by label bug', js: true do
sleep
0.5
# before do
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
bug
\"
) a').click()"
)
# page.find('.js-label-select').click
page
.
first
(
'.labels-filter .dropdown-title .dropdown-menu-close-icon'
).
click
# sleep 0.5
sleep
2
# execute_script("$('.dropdown-menu-labels li:contains(\"bug\") a').click()")
end
# page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
# sleep 2
it
'should show issue "Bugfix1" and "Bugfix2" in issues list'
do
# end
expect
(
page
).
to
have_content
"Bugfix1"
#
expect
(
page
).
to
have_content
"Bugfix2"
# it 'should show issue "Bugfix1" and "Bugfix2" in issues list' do
end
# expect(page).to have_content "Bugfix1"
# expect(page).to have_content "Bugfix2"
it
'should not show "Feature1" in issues list'
do
# end
expect
(
page
).
not_to
have_content
"Feature1"
#
end
# it 'should not show "Feature1" in issues list' do
# expect(page).not_to have_content "Feature1"
it
'should show label "bug" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"bug"
#
end
# it 'should show label "bug" in filtered-labels' do
# expect(find('.filtered-labels')).to have_content "bug"
it
'should not show label "feature" and "enhancement" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"feature"
#
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"enhancement"
# it 'should not show label "feature" and "enhancement" in filtered-labels' do
end
# expect(find('.filtered-labels')).not_to have_content "feature"
end
# expect(find('.filtered-labels')).not_to have_content "enhancement"
# end
context
'filter by label feature'
,
js:
true
do
# end
before
do
#
page
.
find
(
'.js-label-select'
).
click
# context 'filter by label feature', js: true do
sleep
0.5
# before do
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
feature
\"
) a').click()"
)
# page.find('.js-label-select').click
page
.
first
(
'.labels-filter .dropdown-title .dropdown-menu-close-icon'
).
click
# sleep 0.5
sleep
2
# execute_script("$('.dropdown-menu-labels li:contains(\"feature\") a').click()")
end
# page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
# sleep 2
it
'should show issue "Feature1" in issues list'
do
# end
expect
(
page
).
to
have_content
"Feature1"
#
end
# it 'should show issue "Feature1" in issues list' do
# expect(page).to have_content "Feature1"
it
'should not show "Bugfix1" and "Bugfix2" in issues list'
do
# end
expect
(
page
).
not_to
have_content
"Bugfix2"
#
expect
(
page
).
not_to
have_content
"Bugfix1"
# it 'should not show "Bugfix1" and "Bugfix2" in issues list' do
end
# expect(page).not_to have_content "Bugfix2"
# expect(page).not_to have_content "Bugfix1"
it
'should show label "feature" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"feature"
#
end
# it 'should show label "feature" in filtered-labels' do
# expect(find('.filtered-labels')).to have_content "feature"
it
'should not show label "bug" and "enhancement" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"bug"
#
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"enhancement"
# it 'should not show label "bug" and "enhancement" in filtered-labels' do
end
# expect(find('.filtered-labels')).not_to have_content "bug"
end
# expect(find('.filtered-labels')).not_to have_content "enhancement"
# end
context
'filter by label enhancement'
,
js:
true
do
# end
before
do
#
page
.
find
(
'.js-label-select'
).
click
# context 'filter by label enhancement', js: true do
sleep
0.5
# before do
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
enhancement
\"
) a').click()"
)
# page.find('.js-label-select').click
page
.
first
(
'.labels-filter .dropdown-title .dropdown-menu-close-icon'
).
click
# sleep 0.5
sleep
2
# execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
end
# page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
# sleep 2
it
'should show issue "Bugfix2" in issues list'
do
# end
expect
(
page
).
to
have_content
"Bugfix2"
#
end
# it 'should show issue "Bugfix2" in issues list' do
# expect(page).to have_content "Bugfix2"
it
'should not show "Feature1" and "Bugfix1" in issues list'
do
# end
expect
(
page
).
not_to
have_content
"Feature1"
#
expect
(
page
).
not_to
have_content
"Bugfix1"
# it 'should not show "Feature1" and "Bugfix1" in issues list' do
end
# expect(page).not_to have_content "Feature1"
# expect(page).not_to have_content "Bugfix1"
it
'should show label "enhancement" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"enhancement"
#
end
# it 'should show label "enhancement" in filtered-labels' do
# expect(find('.filtered-labels')).to have_content "enhancement"
it
'should not show label "feature" and "bug" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"bug"
#
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"feature"
# it 'should not show label "feature" and "bug" in filtered-labels' do
end
# expect(find('.filtered-labels')).not_to have_content "bug"
end
# expect(find('.filtered-labels')).not_to have_content "feature"
# end
context
'filter by label enhancement or feature'
,
js:
true
do
# end
before
do
#
page
.
find
(
'.js-label-select'
).
click
# context 'filter by label enhancement or feature', js: true do
sleep
0.5
# before do
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
enhancement
\"
) a').click()"
)
# page.find('.js-label-select').click
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
feature
\"
) a').click()"
)
# sleep 0.5
page
.
first
(
'.labels-filter .dropdown-title .dropdown-menu-close-icon'
).
click
# execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
sleep
2
# execute_script("$('.dropdown-menu-labels li:contains(\"feature\") a').click()")
end
# page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
# sleep 2
it
'should not show "Bugfix1" or "Feature1" in issues list'
do
# end
expect
(
page
).
not_to
have_content
"Bugfix1"
#
expect
(
page
).
not_to
have_content
"Feature1"
# it 'should not show "Bugfix1" or "Feature1" in issues list' do
end
# expect(page).not_to have_content "Bugfix1"
# expect(page).not_to have_content "Feature1"
it
'should show label "enhancement" and "feature" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"enhancement"
#
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"feature"
# it 'should show label "enhancement" and "feature" in filtered-labels' do
end
# expect(find('.filtered-labels')).to have_content "enhancement"
# expect(find('.filtered-labels')).to have_content "feature"
it
'should not show label "bug" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"bug"
#
end
# it 'should not show label "bug" in filtered-labels' do
end
# expect(find('.filtered-labels')).not_to have_content "bug"
# end
context
'filter by label enhancement and bug in issues list'
,
js:
true
do
# end
before
do
#
page
.
find
(
'.js-label-select'
).
click
# context 'filter by label enhancement and bug in issues list', js: true do
sleep
0.5
# before do
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
enhancement
\"
) a').click()"
)
# page.find('.js-label-select').click
execute_script
(
"$('.dropdown-menu-labels li:contains(
\"
bug
\"
) a').click()"
)
# sleep 0.5
page
.
first
(
'.labels-filter .dropdown-title .dropdown-menu-close-icon'
).
click
# execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
sleep
2
# execute_script("$('.dropdown-menu-labels li:contains(\"bug\") a').click()")
end
# page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
# sleep 2
it
'should show issue "Bugfix2" in issues list'
do
# end
expect
(
page
).
to
have_content
"Bugfix2"
#
end
# it 'should show issue "Bugfix2" in issues list' do
# expect(page).to have_content "Bugfix2"
it
'should not show "Feature1"'
do
# end
expect
(
page
).
not_to
have_content
"Feature1"
#
end
# it 'should not show "Feature1"' do
# expect(page).not_to have_content "Feature1"
it
'should show label "bug" and "enhancement" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"bug"
#
expect
(
find
(
'.filtered-labels'
)).
to
have_content
"enhancement"
# it 'should show label "bug" and "enhancement" in filtered-labels' do
end
# expect(find('.filtered-labels')).to have_content "bug"
# expect(find('.filtered-labels')).to have_content "enhancement"
it
'should not show label "feature" in filtered-labels'
do
# end
expect
(
find
(
'.filtered-labels'
)).
not_to
have_content
"feature"
#
end
# it 'should not show label "feature" in filtered-labels' do
end
# expect(find('.filtered-labels')).not_to have_content "feature"
end
# end
# end
# end
spec/models/concerns/issuable_spec.rb
View file @
af18cddd
...
@@ -212,4 +212,28 @@ describe Issue, "Issuable" do
...
@@ -212,4 +212,28 @@ describe Issue, "Issuable" do
expect
(
issue
.
downvotes
).
to
eq
(
1
)
expect
(
issue
.
downvotes
).
to
eq
(
1
)
end
end
end
end
end
describe
".with_label"
do
let
(
:example_label
)
{
'test1'
}
let
(
:example_labels
)
{
[
'test1'
,
'test2'
]
}
it
'finds issue with 1 label'
do
setup_labels
([
example_label
])
expect
(
Issue
.
with_label
(
example_label
).
count
).
to
eq
(
1
)
end
it
'finds issue with 2 labels'
do
setup_labels
(
example_labels
)
expect
(
Issue
.
with_label
(
example_labels
).
to_a
.
count
).
to
eq
(
1
)
end
def
setup_labels
(
label_names
)
labels
=
label_names
.
map
do
|
label
|
create
(
:label
,
project:
issue
.
project
,
title:
label
)
end
issue
.
labels
<<
labels
end
end
end
\ No newline at end of file
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