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
c445ef53
Commit
c445ef53
authored
Feb 20, 2018
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move default_project_view tests to presenter
parent
e0e3f1c2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
102 deletions
+97
-102
app/presenters/project_presenter.rb
app/presenters/project_presenter.rb
+2
-2
app/views/projects/show.html.haml
app/views/projects/show.html.haml
+1
-1
spec/helpers/preferences_helper_spec.rb
spec/helpers/preferences_helper_spec.rb
+0
-97
spec/presenters/project_presenter_spec.rb
spec/presenters/project_presenter_spec.rb
+94
-2
No files found.
app/presenters/project_presenter.rb
View file @
c445ef53
...
...
@@ -52,7 +52,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
].
compact
.
reject
{
|
i
|
i
[
:enabled
]
}
end
def
default_
project_
view
def
default_view
return
anonymous_project_view
unless
current_user
user_view
=
current_user
.
project_view
...
...
@@ -242,7 +242,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
{
enabled:
true
,
label:
_
(
'Readme'
),
link:
default_
project_
view
!=
'readme'
?
readme_path
:
'#readme'
link:
default_view
!=
'readme'
?
readme_path
:
'#readme'
}
end
end
...
...
app/views/projects/show.html.haml
View file @
c445ef53
...
...
@@ -27,7 +27,7 @@
=
icon
(
"exclamation-triangle fw"
)
#{
_
(
'Archived project! Repository is read-only'
)
}
-
view_path
=
@project
.
default_
project_
view
-
view_path
=
@project
.
default_view
-
if
show_auto_devops_callout?
(
@project
)
=
render
'shared/auto_devops_callout'
...
...
spec/helpers/preferences_helper_spec.rb
View file @
c445ef53
...
...
@@ -77,103 +77,6 @@ describe PreferencesHelper do
end
end
describe
'#default_project_view'
do
context
'user not signed in'
do
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
stub_user
end
context
'when repository is empty'
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
it
'returns activity if user has repository access'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
true
)
expect
(
helper
.
default_project_view
).
to
eq
(
'activity'
)
end
it
'returns activity if user does not have repository access'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
false
)
expect
(
helper
.
default_project_view
).
to
eq
(
'activity'
)
end
end
context
'when repository is not empty'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
it
'returns files and readme if user has repository access'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
true
)
expect
(
helper
.
default_project_view
).
to
eq
(
'files'
)
end
it
'returns activity if user does not have repository access'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
false
)
expect
(
helper
.
default_project_view
).
to
eq
(
'activity'
)
end
end
end
context
'user signed in'
do
let
(
:user
)
{
create
(
:user
,
:readme
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
context
'when the user is allowed to see the code'
do
it
'returns the project view'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
true
)
expect
(
helper
.
default_project_view
).
to
eq
(
'readme'
)
end
end
context
'with wikis enabled and the right policy for the user'
do
before
do
project
.
project_feature
.
update_attribute
(
:issues_access_level
,
0
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
end
it
'returns wiki if the user has the right policy'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
true
)
expect
(
helper
.
default_project_view
).
to
eq
(
'wiki'
)
end
it
'returns customize_workflow if the user does not have the right policy'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
helper
.
default_project_view
).
to
eq
(
'customize_workflow'
)
end
end
context
'with issues as a feature available'
do
it
'return issues'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
helper
.
default_project_view
).
to
eq
(
'projects/issues/issues'
)
end
end
context
'with no activity, no wikies and no issues'
do
it
'returns customize_workflow as default'
do
project
.
project_feature
.
update_attribute
(
:issues_access_level
,
0
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
helper
.
default_project_view
).
to
eq
(
'customize_workflow'
)
end
end
end
end
def
stub_user
(
messages
=
{})
if
messages
.
empty?
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
nil
)
...
...
spec/presenters/project_presenter_spec.rb
View file @
c445ef53
...
...
@@ -2,10 +2,11 @@ require 'spec_helper'
describe
ProjectPresenter
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:presenter
)
{
described_class
.
new
(
project
,
current_user:
user
)
}
describe
'#license_short_name'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:presenter
)
{
described_class
.
new
(
project
,
current_user:
user
)
}
context
'when project.repository has a license_key'
do
it
'returns the nickname of the license if present'
do
allow
(
project
.
repository
).
to
receive
(
:license_key
).
and_return
(
'agpl-3.0'
)
...
...
@@ -28,4 +29,95 @@ describe ProjectPresenter do
end
end
end
describe
'#default_view'
do
let
(
:presenter
)
{
described_class
.
new
(
project
,
current_user:
user
)
}
context
'user not signed in'
do
let
(
:user
)
{
nil
}
context
'when repository is empty'
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
it
'returns activity if user has repository access'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
true
)
expect
(
presenter
.
default_view
).
to
eq
(
'activity'
)
end
it
'returns activity if user does not have repository access'
do
allow
(
project
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
false
)
expect
(
presenter
.
default_view
).
to
eq
(
'activity'
)
end
end
context
'when repository is not empty'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
it
'returns files and readme if user has repository access'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
true
)
expect
(
presenter
.
default_view
).
to
eq
(
'files'
)
end
it
'returns activity if user does not have repository access'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
nil
,
:download_code
,
project
).
and_return
(
false
)
expect
(
presenter
.
default_view
).
to
eq
(
'activity'
)
end
end
end
context
'user signed in'
do
let
(
:user
)
{
create
(
:user
,
:readme
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
context
'when the user is allowed to see the code'
do
it
'returns the project view'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
true
)
expect
(
presenter
.
default_view
).
to
eq
(
'readme'
)
end
end
context
'with wikis enabled and the right policy for the user'
do
before
do
project
.
project_feature
.
update_attribute
(
:issues_access_level
,
0
)
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
end
it
'returns wiki if the user has the right policy'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
true
)
expect
(
presenter
.
default_view
).
to
eq
(
'wiki'
)
end
it
'returns customize_workflow if the user does not have the right policy'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
presenter
.
default_view
).
to
eq
(
'customize_workflow'
)
end
end
context
'with issues as a feature available'
do
it
'return issues'
do
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
presenter
.
default_view
).
to
eq
(
'projects/issues/issues'
)
end
end
context
'with no activity, no wikies and no issues'
do
it
'returns customize_workflow as default'
do
project
.
project_feature
.
update_attribute
(
:issues_access_level
,
0
)
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:download_code
,
project
).
and_return
(
false
)
allow
(
presenter
).
to
receive
(
:can?
).
with
(
user
,
:read_wiki
,
project
).
and_return
(
false
)
expect
(
presenter
.
default_view
).
to
eq
(
'customize_workflow'
)
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