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
61b0e8ca
Commit
61b0e8ca
authored
Jul 25, 2018
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spec instance statistics
parent
fb6375a5
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
181 additions
and
15 deletions
+181
-15
app/controllers/instance_statistics/application_controller.rb
...controllers/instance_statistics/application_controller.rb
+2
-2
app/controllers/instance_statistics/cohorts_controller.rb
app/controllers/instance_statistics/cohorts_controller.rb
+2
-0
app/policies/global_policy.rb
app/policies/global_policy.rb
+3
-1
config/routes/instance_statistics.rb
config/routes/instance_statistics.rb
+1
-1
spec/controllers/instance_statistics/cohorts_controller_spec.rb
...ontrollers/instance_statistics/cohorts_controller_spec.rb
+7
-0
spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb
...stics/conversational_development_index_controller_spec.rb
+7
-0
spec/features/dashboard/active_tab_spec.rb
spec/features/dashboard/active_tab_spec.rb
+17
-11
spec/features/dashboard/instance_statistics_spec.rb
spec/features/dashboard/instance_statistics_spec.rb
+60
-0
spec/policies/global_policy_spec.rb
spec/policies/global_policy_spec.rb
+34
-0
spec/routing/instance_statistics_routing_spec.rb
spec/routing/instance_statistics_routing_spec.rb
+11
-0
spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb
...amples/instance_statistics_controllers_shared_examples.rb
+37
-0
No files found.
app/controllers/instance_statistics/application_controller.rb
View file @
61b0e8ca
class
InstanceStatistics::ApplicationController
<
ApplicationController
before_action
:auth
enticate_user
!
before_action
:auth
orize_read_instance_statistics
!
layout
'instance_statistics'
def
auth
enticate_user
!
def
auth
orize_read_instance_statistics
!
render_404
unless
can?
(
current_user
,
:read_instance_statistics
)
end
end
app/controllers/instance_statistics/cohorts_controller.rb
View file @
61b0e8ca
# frozen_string_literal: true
class
InstanceStatistics::CohortsController
<
InstanceStatistics
::
ApplicationController
def
index
if
Gitlab
::
CurrentSettings
.
usage_ping_enabled
...
...
app/policies/global_policy.rb
View file @
61b0e8ca
...
...
@@ -20,7 +20,9 @@ class GlobalPolicy < BasePolicy
end
condition
(
:private_instance_statistics
,
score:
0
)
{
Gitlab
::
CurrentSettings
.
instance_statistics_visibility_private?
}
rule
{
admin
|
~
private_instance_statistics
}.
enable
:read_instance_statistics
rule
{
admin
|
(
~
private_instance_statistics
&
~
anonymous
)
}
.
enable
:read_instance_statistics
rule
{
anonymous
}.
policy
do
prevent
:log_in
...
...
config/routes/instance_statistics.rb
View file @
61b0e8ca
namespace
:instance_statistics
do
root
to:
redirect
(
'-/instance_statistics/conversational_development_index'
)
root
to:
redirect
(
'
/
-/instance_statistics/conversational_development_index'
)
resources
:cohorts
,
only: :index
resources
:conversational_development_index
,
only: :index
...
...
spec/controllers/instance_statistics/cohorts_controller_spec.rb
0 → 100644
View file @
61b0e8ca
# frozen_string_literal: true
require
'spec_helper'
describe
InstanceStatistics
::
CohortsController
do
it_behaves_like
'instance statistics availability'
end
spec/controllers/instance_statistics/conversational_development_index_controller_spec.rb
0 → 100644
View file @
61b0e8ca
# frozen_string_literal: true
require
'spec_helper'
describe
InstanceStatistics
::
ConversationalDevelopmentIndexController
do
it_behaves_like
'instance statistics availability'
end
spec/features/dashboard/active_tab_spec.rb
View file @
61b0e8ca
...
...
@@ -7,32 +7,38 @@ RSpec.describe 'Dashboard Active Tab', :js do
shared_examples
'page has active tab'
do
|
title
|
it
"
#{
title
}
tab"
do
subject
expect
(
page
).
to
have_selector
(
'.navbar-sub-nav li.active'
,
count:
1
)
expect
(
find
(
'.navbar-sub-nav li.active'
)).
to
have_content
(
title
)
end
end
context
'on dashboard projects'
do
before
do
visit
dashboard_projects_path
it_behaves_like
'page has active tab'
,
'Projects'
do
subject
{
visit
dashboard_projects_path
}
end
it_behaves_like
'page has active tab'
,
'Projects'
end
context
'on dashboard groups'
do
before
do
visit
dashboard_groups_path
it_behaves_like
'page has active tab'
,
'Groups'
do
subject
{
visit
dashboard_groups_path
}
end
it_behaves_like
'page has active tab'
,
'Groups'
end
context
'on activity projects'
do
before
do
visit
activity_dashboard_path
it_behaves_like
'page has active tab'
,
'Activity'
do
subject
{
visit
activity_dashboard_path
}
end
end
it_behaves_like
'page has active tab'
,
'Activity'
context
'on instance statistics'
do
subject
{
visit
instance_statistics_root_path
}
it
'shows Instance Statistics` as active'
do
subject
expect
(
find
(
'.navbar-sub-nav li.active'
)).
to
have_link
(
'Instance Statistics'
)
end
end
end
spec/features/dashboard/instance_statistics_spec.rb
0 → 100644
View file @
61b0e8ca
# frozen_string_literal: true
require
'spec_helper'
describe
'Showing instance statistics'
do
before
do
sign_in
user
if
user
end
# Using a path that is publicly accessible
subject
{
visit
explore_projects_path
}
context
'for unauthenticated users'
do
let
(
:user
)
{
nil
}
it
'does not show the instance statistics link'
do
subject
expect
(
page
).
not_to
have_link
(
'Instance Statistics'
)
end
end
context
'for regular users'
do
let
(
:user
)
{
create
(
:user
)
}
context
'when instance statistics are publicly available'
do
before
do
stub_application_setting
(
instance_statistics_visibility_private:
false
)
end
it
'shows the instance statistics link'
do
subject
expect
(
page
).
to
have_link
(
'Instance Statistics'
)
end
end
context
'when instance statistics are not publicly available'
do
before
do
stub_application_setting
(
instance_statistics_visibility_private:
true
)
end
it
'shows the instance statistics link'
do
subject
expect
(
page
).
not_to
have_link
(
'Instance Statistics'
)
end
end
end
context
'for admins'
do
let
(
:user
)
{
create
(
:admin
)
}
it
'shows the instance statistics link'
do
subject
expect
(
page
).
to
have_link
(
'Instance Statistics'
)
end
end
end
spec/policies/global_policy_spec.rb
View file @
61b0e8ca
...
...
@@ -180,4 +180,38 @@ describe GlobalPolicy do
end
end
end
describe
'read instance statistics'
do
context
'regular user'
do
it
{
is_expected
.
to
be_allowed
(
:read_instance_statistics
)
}
context
'when instance statistics are set to private'
do
before
do
stub_application_setting
(
instance_statistics_visibility_private:
true
)
end
it
{
is_expected
.
not_to
be_allowed
(
:read_instance_statistics
)
}
end
end
context
'admin'
do
let
(
:current_user
)
{
create
(
:admin
)
}
it
{
is_expected
.
to
be_allowed
(
:read_instance_statistics
)
}
context
'when instance statistics are set to private'
do
before
do
stub_application_setting
(
instance_statistics_visibility_private:
true
)
end
it
{
is_expected
.
to
be_allowed
(
:read_instance_statistics
)
}
end
end
context
'anonymous'
do
let
(
:current_user
)
{
nil
}
it
{
is_expected
.
not_to
be_allowed
(
:read_instance_statistics
)
}
end
end
end
spec/routing/instance_statistics_routing_spec.rb
0 → 100644
View file @
61b0e8ca
# frozen_string_literal: true
require
'spec_helper'
describe
'Instance Statistics'
,
'routing'
do
include
RSpec
::
Rails
::
RequestExampleGroup
it
"routes '/-/instance_statistics' to conversational development index"
do
expect
(
get
(
'/-/instance_statistics'
)).
to
redirect_to
(
'/-/instance_statistics/conversational_development_index'
)
end
end
spec/support/shared_examples/instance_statistics_controllers_shared_examples.rb
0 → 100644
View file @
61b0e8ca
# frozen_string_literal: true
shared_examples
'instance statistics availability'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
describe
'GET #index'
do
it
'is available when the feature is available publicly'
do
get
:index
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
end
it
'renders a 404 when the feature is not available publicly'
do
stub_application_setting
(
instance_statistics_visibility_private:
true
)
get
:index
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
context
'for admins'
do
let
(
:user
)
{
create
(
:admin
)
}
it
'allows access when the feature is not available publicly'
do
stub_application_setting
(
instance_statistics_visibility_private:
true
)
get
:index
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
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