BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
fbbb985a
Unverified
Commit
fbbb985a
authored
Aug 23, 2017
by
Maxim Rydkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract finder and add first test
parent
5d952f75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
22 deletions
+129
-22
autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+1
-22
yet_another_users_finder.rb
app/finders/yet_another_users_finder.rb
+42
-0
yet_another_users_finder_spec.rb
spec/finders/yet_another_users_finder_spec.rb
+86
-0
No files found.
app/controllers/autocomplete_controller.rb
View file @
fbbb985a
...
...
@@ -6,28 +6,7 @@ class AutocompleteController < ApplicationController
before_action
:find_users
,
only:
[
:users
]
def
users
@users
||=
User
.
none
@users
=
@users
.
active
@users
=
@users
.
reorder
(
:name
)
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
where
.
not
(
id:
params
[
:skip_users
])
if
params
[
:skip_users
].
present?
@users
=
@users
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
])
if
params
[
:todo_filter
].
present?
&&
current_user
@users
=
@users
.
todo_authors
(
current_user
.
id
,
params
[
:todo_state_filter
])
end
if
params
[
:search
].
blank?
# Include current user if available to filter by "Me"
if
params
[
:current_user
].
present?
&&
current_user
@users
=
[
current_user
,
*
@users
].
uniq
end
if
params
[
:author_id
].
present?
&&
current_user
author
=
User
.
find_by_id
(
params
[
:author_id
])
@users
=
[
author
,
*
@users
].
uniq
if
author
end
end
@users
=
YetAnotherUsersFinder
.
new
(
params:
params
,
current_user:
current_user
,
users:
@users
).
execute
render
json:
@users
,
only:
[
:name
,
:username
,
:id
],
methods:
[
:avatar_url
]
end
...
...
app/finders/yet_another_users_finder.rb
0 → 100644
View file @
fbbb985a
class
YetAnotherUsersFinder
attr_reader
:current_user
,
:users
,
:search
,
:skip_users
,
:page
,
:per_page
,
:author_id
,
:params
def
initialize
(
params
:,
current_user
:,
users:
nil
)
@current_user
=
current_user
@users
=
users
@search
=
params
[
:search
]
@skip_users
=
params
[
:skip_users
]
@page
=
params
[
:page
]
@per_page
=
params
[
:per_page
]
@author_id
=
params
[
:author_id
]
@params
=
params
end
def
execute
items
=
users
||
User
.
none
items
=
items
.
active
items
=
items
.
reorder
(
:name
)
items
=
items
.
search
(
search
)
if
search
.
present?
items
=
items
.
where
.
not
(
id:
skip_users
)
if
skip_users
.
present?
items
=
items
.
page
(
page
).
per
(
per_page
)
if
params
[
:todo_filter
].
present?
&&
current_user
items
=
items
.
todo_authors
(
current_user
.
id
,
params
[
:todo_state_filter
])
end
if
search
.
blank?
# Include current user if available to filter by "Me"
if
params
[
:current_user
].
present?
&&
current_user
items
=
[
current_user
,
*
items
].
uniq
end
if
author_id
.
present?
&&
current_user
author
=
User
.
find_by_id
(
author_id
)
items
=
[
author
,
*
items
].
uniq
if
author
end
end
items
end
end
spec/finders/yet_another_users_finder_spec.rb
0 → 100644
View file @
fbbb985a
require
'spec_helper'
describe
YetAnotherUsersFinder
do
describe
'#execute'
do
let!
(
:user1
)
{
create
(
:user
,
username:
'johndoe'
)
}
let!
(
:user2
)
{
create
(
:user
,
:blocked
,
username:
'notsorandom'
)
}
let!
(
:external_user
)
{
create
(
:user
,
:external
)
}
let!
(
:omniauth_user
)
{
create
(
:omniauth_user
,
provider:
'twitter'
,
extern_uid:
'123456'
)
}
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:params
)
{
{}
}
it
'returns no users'
do
users
=
described_class
.
new
(
params:
params
,
current_user:
current_user
).
execute
expect
(
users
.
size
).
to
eq
(
0
)
end
# context 'with a normal user' do
# let(:user) { create(:user) }
# it 'returns all users' do
# users = described_class.new(user).execute
# expect(users).to contain_exactly(user, user1, user2, omniauth_user)
# end
# it 'filters by username' do
# users = described_class.new(user, username: 'johndoe').execute
# expect(users).to contain_exactly(user1)
# end
# it 'filters by search' do
# users = described_class.new(user, search: 'orando').execute
# expect(users).to contain_exactly(user2)
# end
# it 'filters by blocked users' do
# users = described_class.new(user, blocked: true).execute
# expect(users).to contain_exactly(user2)
# end
# it 'filters by active users' do
# users = described_class.new(user, active: true).execute
# expect(users).to contain_exactly(user, user1, omniauth_user)
# end
# it 'returns no external users' do
# users = described_class.new(user, external: true).execute
# expect(users).to contain_exactly(user, user1, user2, omniauth_user)
# end
# it 'filters by created_at' do
# filtered_user_before = create(:user, created_at: 3.days.ago)
# filtered_user_after = create(:user, created_at: Time.now + 3.days)
# users = described_class.new(user,
# created_after: 2.days.ago,
# created_before: Time.now + 2.days).execute
# expect(users.map(&:username)).not_to include([filtered_user_before.username, filtered_user_after.username])
# end
# end
# context 'with an admin user' do
# let(:admin) { create(:admin) }
# it 'filters by external users' do
# users = described_class.new(admin, external: true).execute
# expect(users).to contain_exactly(external_user)
# end
# it 'returns all users' do
# users = described_class.new(admin).execute
# expect(users).to contain_exactly(admin, user1, user2, external_user, omniauth_user)
# 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