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
Boxiang Sun
gitlab-ce
Commits
345b3d4b
Commit
345b3d4b
authored
Feb 25, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests and fix Finders readme
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
645e8d47
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
40 deletions
+52
-40
app/finders/README.md
app/finders/README.md
+3
-5
spec/finders/issues_finder_spec.rb
spec/finders/issues_finder_spec.rb
+7
-30
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+37
-0
spec/finders/projects_finder_spec.rb
spec/finders/projects_finder_spec.rb
+5
-5
No files found.
app/finders/README.md
View file @
345b3d4b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
This type of classes responsible for collectiong items based on different conditions.
This type of classes responsible for collectiong items based on different conditions.
To prevent lookup methods in models like this:
To prevent lookup methods in models like this:
```
```
ruby
class
Project
class
Project
def
issues_for_user_filtered_by
(
user
,
filter
)
def
issues_for_user_filtered_by
(
user
,
filter
)
# A lot of logic not related to project model itself
# A lot of logic not related to project model itself
...
@@ -15,10 +15,8 @@ issues = project.issues_for_user_filtered_by(user, params)
...
@@ -15,10 +15,8 @@ issues = project.issues_for_user_filtered_by(user, params)
Better use this:
Better use this:
```
```
ruby
selector = Finders::Issues.new
issues
=
IssuesFinder
.
new
.
execute
(
project
,
user
,
filter
)
issues = selector.execute(project, user, filter)
```
```
It will help keep models thiner
It will help keep models thiner
spec/
services/filtering_service
_spec.rb
→
spec/
finders/issues_finder
_spec.rb
View file @
345b3d4b
require
'spec_helper'
require
'spec_helper'
describe
FilteringService
do
describe
IssuesFinder
do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:user2
)
{
create
:user
}
let
(
:user2
)
{
create
:user
}
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:merge_request1
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project1
,
target_project:
project2
)
}
let
(
:merge_request2
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project1
)
}
let
(
:merge_request3
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project2
)
}
let
(
:issue1
)
{
create
(
:issue
,
assignee:
user
,
project:
project1
)
}
let
(
:issue1
)
{
create
(
:issue
,
assignee:
user
,
project:
project1
)
}
let
(
:issue2
)
{
create
(
:issue
,
assignee:
user
,
project:
project2
)
}
let
(
:issue2
)
{
create
(
:issue
,
assignee:
user
,
project:
project2
)
}
let
(
:issue3
)
{
create
(
:issue
,
assignee:
user2
,
project:
project2
)
}
let
(
:issue3
)
{
create
(
:issue
,
assignee:
user2
,
project:
project2
)
}
...
@@ -18,27 +15,7 @@ describe FilteringService do
...
@@ -18,27 +15,7 @@ describe FilteringService do
project2
.
team
<<
[
user2
,
:developer
]
project2
.
team
<<
[
user2
,
:developer
]
end
end
describe
'merge requests'
do
describe
:execute
do
before
:each
do
merge_request1
merge_request2
merge_request3
end
it
'should filter by scope'
do
params
=
{
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
FilteringService
.
new
.
execute
(
MergeRequest
,
user
,
params
)
merge_requests
.
size
.
should
==
3
end
it
'should filter by project'
do
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
FilteringService
.
new
.
execute
(
MergeRequest
,
user
,
params
)
merge_requests
.
size
.
should
==
1
end
end
describe
'issues'
do
before
:each
do
before
:each
do
issue1
issue1
issue2
issue2
...
@@ -47,31 +24,31 @@ describe FilteringService do
...
@@ -47,31 +24,31 @@ describe FilteringService do
it
'should filter by all'
do
it
'should filter by all'
do
params
=
{
scope:
"all"
,
state:
'opened'
}
params
=
{
scope:
"all"
,
state:
'opened'
}
issues
=
FilteringService
.
new
.
execute
(
Issue
,
user
,
params
)
issues
=
IssuesFinder
.
new
.
execute
(
user
,
params
)
issues
.
size
.
should
==
3
issues
.
size
.
should
==
3
end
end
it
'should filter by assignee'
do
it
'should filter by assignee'
do
params
=
{
scope:
"assigned-to-me"
,
state:
'opened'
}
params
=
{
scope:
"assigned-to-me"
,
state:
'opened'
}
issues
=
FilteringService
.
new
.
execute
(
Issue
,
user
,
params
)
issues
=
IssuesFinder
.
new
.
execute
(
user
,
params
)
issues
.
size
.
should
==
2
issues
.
size
.
should
==
2
end
end
it
'should filter by project'
do
it
'should filter by project'
do
params
=
{
scope:
"assigned-to-me"
,
state:
'opened'
,
project_id:
project1
.
id
}
params
=
{
scope:
"assigned-to-me"
,
state:
'opened'
,
project_id:
project1
.
id
}
issues
=
FilteringService
.
new
.
execute
(
Issue
,
user
,
params
)
issues
=
IssuesFinder
.
new
.
execute
(
user
,
params
)
issues
.
size
.
should
==
1
issues
.
size
.
should
==
1
end
end
it
'should be empty for unauthorized user'
do
it
'should be empty for unauthorized user'
do
params
=
{
scope:
"all"
,
state:
'opened'
}
params
=
{
scope:
"all"
,
state:
'opened'
}
issues
=
FilteringService
.
new
.
execute
(
Issue
,
nil
,
params
)
issues
=
IssuesFinder
.
new
.
execute
(
nil
,
params
)
issues
.
size
.
should
be_zero
issues
.
size
.
should
be_zero
end
end
it
'should not include unauthorized issues'
do
it
'should not include unauthorized issues'
do
params
=
{
scope:
"all"
,
state:
'opened'
}
params
=
{
scope:
"all"
,
state:
'opened'
}
issues
=
FilteringService
.
new
.
execute
(
Issue
,
user2
,
params
)
issues
=
IssuesFinder
.
new
.
execute
(
user2
,
params
)
issues
.
size
.
should
==
2
issues
.
size
.
should
==
2
issues
.
should_not
include
(
issue1
)
issues
.
should_not
include
(
issue1
)
issues
.
should
include
(
issue2
)
issues
.
should
include
(
issue2
)
...
...
spec/finders/merge_requests_finder_spec.rb
0 → 100644
View file @
345b3d4b
require
'spec_helper'
describe
MergeRequestsFinder
do
let
(
:user
)
{
create
:user
}
let
(
:user2
)
{
create
:user
}
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:merge_request1
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project1
,
target_project:
project2
)
}
let
(
:merge_request2
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project1
)
}
let
(
:merge_request3
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project2
)
}
before
do
project1
.
team
<<
[
user
,
:master
]
project2
.
team
<<
[
user
,
:developer
]
project2
.
team
<<
[
user2
,
:developer
]
end
describe
:execute
do
before
:each
do
merge_request1
merge_request2
merge_request3
end
it
'should filter by scope'
do
params
=
{
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
MergeRequestsFinder
.
new
.
execute
(
user
,
params
)
merge_requests
.
size
.
should
==
3
end
it
'should filter by project'
do
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
MergeRequestsFinder
.
new
.
execute
(
user
,
params
)
merge_requests
.
size
.
should
==
1
end
end
end
spec/
services/projects_collect_service
_spec.rb
→
spec/
finders/projects_finder
_spec.rb
View file @
345b3d4b
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
CollectService
do
describe
Projects
Finder
do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:group
)
{
create
:group
}
let
(
:group
)
{
create
:group
}
...
@@ -10,7 +10,7 @@ describe Projects::CollectService do
...
@@ -10,7 +10,7 @@ describe Projects::CollectService do
let
(
:project4
)
{
create
(
:empty_project
,
group:
group
,
visibility_level:
Project
::
PRIVATE
)
}
let
(
:project4
)
{
create
(
:empty_project
,
group:
group
,
visibility_level:
Project
::
PRIVATE
)
}
context
'non authenticated'
do
context
'non authenticated'
do
subject
{
Projects
::
CollectService
.
new
.
execute
(
nil
,
group:
group
)
}
subject
{
Projects
Finder
.
new
.
execute
(
nil
,
group:
group
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project1
)
}
it
{
should_not
include
(
project2
)
}
it
{
should_not
include
(
project2
)
}
...
@@ -19,7 +19,7 @@ describe Projects::CollectService do
...
@@ -19,7 +19,7 @@ describe Projects::CollectService do
end
end
context
'authenticated'
do
context
'authenticated'
do
subject
{
Projects
::
CollectService
.
new
.
execute
(
user
,
group:
group
)
}
subject
{
Projects
Finder
.
new
.
execute
(
user
,
group:
group
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project2
)
}
it
{
should
include
(
project2
)
}
...
@@ -30,7 +30,7 @@ describe Projects::CollectService do
...
@@ -30,7 +30,7 @@ describe Projects::CollectService do
context
'authenticated, project member'
do
context
'authenticated, project member'
do
before
{
project3
.
team
<<
[
user
,
:developer
]
}
before
{
project3
.
team
<<
[
user
,
:developer
]
}
subject
{
Projects
::
CollectService
.
new
.
execute
(
user
,
group:
group
)
}
subject
{
Projects
Finder
.
new
.
execute
(
user
,
group:
group
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project2
)
}
it
{
should
include
(
project2
)
}
...
@@ -41,7 +41,7 @@ describe Projects::CollectService do
...
@@ -41,7 +41,7 @@ describe Projects::CollectService do
context
'authenticated, group member'
do
context
'authenticated, group member'
do
before
{
group
.
add_user
(
user
,
Gitlab
::
Access
::
DEVELOPER
)
}
before
{
group
.
add_user
(
user
,
Gitlab
::
Access
::
DEVELOPER
)
}
subject
{
Projects
::
CollectService
.
new
.
execute
(
user
,
group:
group
)
}
subject
{
Projects
Finder
.
new
.
execute
(
user
,
group:
group
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project1
)
}
it
{
should
include
(
project2
)
}
it
{
should
include
(
project2
)
}
...
...
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