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
38ba59be
Commit
38ba59be
authored
Aug 14, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix starrers counters after searching
parent
90328145
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
56 deletions
+114
-56
app/controllers/projects/starrers_controller.rb
app/controllers/projects/starrers_controller.rb
+2
-16
spec/controllers/projects/starrers_controller_spec.rb
spec/controllers/projects/starrers_controller_spec.rb
+112
-40
No files found.
app/controllers/projects/starrers_controller.rb
View file @
38ba59be
...
@@ -5,23 +5,9 @@ class Projects::StarrersController < Projects::ApplicationController
...
@@ -5,23 +5,9 @@ class Projects::StarrersController < Projects::ApplicationController
def
index
def
index
@starrers
=
UsersStarProjectsFinder
.
new
(
@project
,
params
,
current_user:
@current_user
).
execute
@starrers
=
UsersStarProjectsFinder
.
new
(
@project
,
params
,
current_user:
@current_user
).
execute
@public_count
=
@project
.
starrers
.
with_public_profile
.
size
# Normally the number of public starrers is equal to the number of visible
# starrers. We need to fix the counts in two cases: when the current user
# is an admin (and can see everything) and when the current user has a
# private profile and has starred the project (and can see itself).
@public_count
=
if
@current_user
&
.
admin?
@starrers
.
with_public_profile
.
count
elsif
@current_user
&
.
private_profile
&&
has_starred_project?
(
@starrers
)
@starrers
.
size
-
1
else
@starrers
.
size
end
@total_count
=
@project
.
starrers
.
size
@total_count
=
@project
.
starrers
.
size
@private_count
=
@total_count
-
@public_count
@private_count
=
@total_count
-
@public_count
@sort
=
params
[
:sort
].
presence
||
sort_value_name
@sort
=
params
[
:sort
].
presence
||
sort_value_name
@starrers
=
@starrers
.
sort_by_attribute
(
@sort
).
page
(
params
[
:page
])
@starrers
=
@starrers
.
sort_by_attribute
(
@sort
).
page
(
params
[
:page
])
end
end
...
...
spec/controllers/projects/starrers_controller_spec.rb
View file @
38ba59be
...
@@ -3,23 +3,33 @@
...
@@ -3,23 +3,33 @@
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
StarrersController
do
describe
Projects
::
StarrersController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user_1
)
{
create
(
:user
,
name:
'John'
)
}
let
(
:private_user
)
{
create
(
:user
,
private_profile:
true
)
}
let
(
:user_2
)
{
create
(
:user
,
name:
'Michael'
)
}
let
(
:private_user
)
{
create
(
:user
,
name:
'Michael Douglas'
,
private_profile:
true
)
}
let
(
:admin
)
{
create
(
:user
,
admin:
true
)
}
let
(
:admin
)
{
create
(
:user
,
admin:
true
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
before
do
before
do
user
.
toggle_star
(
project
)
user_1
.
toggle_star
(
project
)
user_2
.
toggle_star
(
project
)
private_user
.
toggle_star
(
project
)
private_user
.
toggle_star
(
project
)
end
end
describe
'GET index'
do
describe
'GET index'
do
def
get_starrers
def
get_starrers
(
search:
nil
)
get
:index
,
get
:index
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
search:
search
}
params:
{
end
namespace_id:
project
.
namespace
,
project_id:
project
def
user_ids
}
assigns
[
:starrers
].
map
{
|
s
|
s
[
'user_id'
]
}
end
shared_examples
'starrers counts'
do
it
'starrers counts are correct'
do
expect
(
assigns
[
:total_count
]).
to
eq
(
3
)
expect
(
assigns
[
:public_count
]).
to
eq
(
2
)
expect
(
assigns
[
:private_count
]).
to
eq
(
1
)
end
end
end
context
'when project is public'
do
context
'when project is public'
do
...
@@ -28,55 +38,118 @@ describe Projects::StarrersController do
...
@@ -28,55 +38,118 @@ describe Projects::StarrersController do
end
end
context
'when no user is logged in'
do
context
'when no user is logged in'
do
context
'with no searching'
do
before
do
before
do
get_starrers
get_starrers
end
end
it
'only public starrers are visible'
do
it
'only users with public profiles are visible'
do
user_ids
=
assigns
[
:starrers
].
map
{
|
s
|
s
[
'user_id'
]
}
expect
(
user_ids
).
to
contain_exactly
(
user_1
.
id
,
user_2
.
id
)
expect
(
user_ids
).
to
include
(
user
.
id
)
expect
(
user_ids
).
not_to
include
(
private_user
.
id
)
end
end
it
'public/private starrers counts are correct'
do
include_examples
'starrers counts'
expect
(
assigns
[
:public_count
]).
to
eq
(
1
)
end
expect
(
assigns
[
:private_count
]).
to
eq
(
1
)
context
'when searching by user'
do
before
do
get_starrers
(
search:
'Michael'
)
end
it
'only users with public profiles are visible'
do
expect
(
user_ids
).
to
contain_exactly
(
user_2
.
id
)
end
include_examples
'starrers counts'
end
end
context
'when public user is logged in'
do
before
do
sign_in
(
user_1
)
end
context
'with no searching'
do
before
do
get_starrers
end
it
'their star is also visible'
do
expect
(
user_ids
).
to
contain_exactly
(
user_1
.
id
,
user_2
.
id
)
end
include_examples
'starrers counts'
end
context
'when searching by user'
do
before
do
get_starrers
(
search:
'Michael'
)
end
it
'only users with public profiles are visible'
do
expect
(
user_ids
).
to
contain_exactly
(
user_2
.
id
)
end
include_examples
'starrers counts'
end
end
end
end
context
'when private user is logged in'
do
context
'when private user is logged in'
do
before
do
before
do
sign_in
(
private_user
)
sign_in
(
private_user
)
end
context
'with no searching'
do
before
do
get_starrers
get_starrers
end
end
it
'their star is also visible'
do
it
'their star is also visible'
do
user_ids
=
assigns
[
:starrers
].
map
{
|
s
|
s
[
'user_id'
]
}
expect
(
user_ids
).
to
contain_exactly
(
user_1
.
id
,
user_2
.
id
,
private_user
.
id
)
expect
(
user_ids
).
to
include
(
user
.
id
,
private_user
.
id
)
end
end
it
'public/private starrers counts are correct'
do
include_examples
'starrers counts'
expect
(
assigns
[
:public_count
]).
to
eq
(
1
)
end
expect
(
assigns
[
:private_count
]).
to
eq
(
1
)
context
'when searching by user'
do
before
do
get_starrers
(
search:
'Michael'
)
end
it
'only users with public profiles are visible'
do
expect
(
user_ids
).
to
contain_exactly
(
user_2
.
id
,
private_user
.
id
)
end
include_examples
'starrers counts'
end
end
end
end
context
'when admin is logged in'
do
context
'when admin is logged in'
do
before
do
before
do
sign_in
(
admin
)
sign_in
(
admin
)
end
context
'with no searching'
do
before
do
get_starrers
get_starrers
end
end
it
'all stars are visible'
do
it
'all users are visible'
do
user_ids
=
assigns
[
:starrers
].
map
{
|
s
|
s
[
'user_id'
]
}
expect
(
user_ids
).
to
include
(
user_1
.
id
,
user_2
.
id
,
private_user
.
id
)
expect
(
user_ids
).
to
include
(
user
.
id
,
private_user
.
id
)
end
end
it
'public/private starrers counts are correct'
do
include_examples
'starrers counts'
expect
(
assigns
[
:public_count
]).
to
eq
(
1
)
end
expect
(
assigns
[
:private_count
]).
to
eq
(
1
)
context
'when searching by user'
do
before
do
get_starrers
(
search:
'Michael'
)
end
it
'public and private starrers are visible'
do
expect
(
user_ids
).
to
contain_exactly
(
user_2
.
id
,
private_user
.
id
)
end
include_examples
'starrers counts'
end
end
end
end
end
end
...
@@ -95,15 +168,14 @@ describe Projects::StarrersController do
...
@@ -95,15 +168,14 @@ describe Projects::StarrersController do
context
'when user is logged in'
do
context
'when user is logged in'
do
before
do
before
do
sign_in
(
project
.
creator
)
sign_in
(
project
.
creator
)
end
it
'only public starrers are visible'
do
get_starrers
get_starrers
end
user_ids
=
assigns
[
:starrers
].
map
{
|
s
|
s
[
'user_id'
]
}
it
'only users with public profiles are visible'
do
expect
(
user_ids
).
to
include
(
user
.
id
)
expect
(
user_ids
).
to
contain_exactly
(
user_1
.
id
,
user_2
.
id
)
expect
(
user_ids
).
not_to
include
(
private_user
.
id
)
end
end
include_examples
'starrers counts'
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