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
d2686fe9
Commit
d2686fe9
authored
Oct 02, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature flags controller specs
parent
7b2af27a
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
254 additions
and
105 deletions
+254
-105
ee/app/controllers/projects/feature_flags_controller.rb
ee/app/controllers/projects/feature_flags_controller.rb
+4
-4
ee/app/helpers/ee/projects_helper.rb
ee/app/helpers/ee/projects_helper.rb
+2
-2
ee/app/models/operations/feature_flag.rb
ee/app/models/operations/feature_flag.rb
+2
-0
ee/app/policies/ee/project_policy.rb
ee/app/policies/ee/project_policy.rb
+5
-4
ee/app/views/projects/feature_flags/_configure_feature_flags_button.html.haml
...s/feature_flags/_configure_feature_flags_button.html.haml
+3
-2
ee/app/views/projects/feature_flags/_configure_feature_flags_modal.html.haml
...ts/feature_flags/_configure_feature_flags_modal.html.haml
+55
-54
ee/app/views/projects/feature_flags/_delete_feature_flag_modal.html.haml
...ojects/feature_flags/_delete_feature_flag_modal.html.haml
+25
-24
ee/app/views/projects/feature_flags/_errors.html.haml
ee/app/views/projects/feature_flags/_errors.html.haml
+4
-0
ee/app/views/projects/feature_flags/_form.html.haml
ee/app/views/projects/feature_flags/_form.html.haml
+1
-4
ee/app/views/projects/feature_flags/_new_feature_flag_button.html.haml
...projects/feature_flags/_new_feature_flag_button.html.haml
+1
-1
ee/app/views/projects/feature_flags/_table.html.haml
ee/app/views/projects/feature_flags/_table.html.haml
+12
-10
ee/spec/controllers/projects/feature_flags_controller_spec.rb
...pec/controllers/projects/feature_flags_controller_spec.rb
+140
-0
No files found.
ee/app/controllers/projects/feature_flags_controller.rb
View file @
d2686fe9
class
Projects::FeatureFlagsController
<
Projects
::
ApplicationController
respond_to
:html
before_action
:authorize_read_feature_flag
s
!
before_action
:authorize_update_feature_flag
s
!
,
only:
[
:edit
,
:update
]
before_action
:authorize_
admin_feature_flags
!
,
only:
[
:destroy
]
before_action
:authorize_read_feature_flag!
before_action
:authorize_update_feature_flag!
,
only:
[
:edit
,
:update
]
before_action
:authorize_
destroy_feature_flag
!
,
only:
[
:destroy
]
before_action
:feature_flag
,
only:
[
:edit
,
:update
,
:destroy
]
def
index
@feature_flags
=
project
.
operations_feature_flags
.
order
(
:name
)
.
order
ed
.
page
(
params
[
:page
]).
per
(
30
)
end
...
...
ee/app/helpers/ee/projects_helper.rb
View file @
d2686fe9
...
...
@@ -25,7 +25,7 @@ module EE
nav_tabs
<<
:packages
end
if
can?
(
current_user
,
:read_feature_flag
s
,
project
)
&&
!
nav_tabs
.
include?
(
:operations
)
if
can?
(
current_user
,
:read_feature_flag
,
project
)
&&
!
nav_tabs
.
include?
(
:operations
)
nav_tabs
<<
:operations
end
...
...
@@ -35,7 +35,7 @@ module EE
override
:tab_ability_map
def
tab_ability_map
tab_ability_map
=
super
tab_ability_map
[
:feature_flags
]
=
:read_feature_flag
s
tab_ability_map
[
:feature_flags
]
=
:read_feature_flag
tab_ability_map
end
...
...
ee/app/models/operations/feature_flag.rb
View file @
d2686fe9
...
...
@@ -14,5 +14,7 @@ module Operations
}
validates
:name
,
uniqueness:
{
scope: :project_id
}
validates
:description
,
allow_blank:
true
,
length:
0
..
255
scope
:ordered
,
->
{
order
(
:name
)
}
end
end
ee/app/policies/ee/project_policy.rb
View file @
d2686fe9
...
...
@@ -99,9 +99,11 @@ module EE
enable
:admin_board
enable
:admin_vulnerability_feedback
enable
:create_package
enable
:read_feature_flags
enable
:create_feature_flags
enable
:update_feature_flags
enable
:read_feature_flag
enable
:create_feature_flag
enable
:update_feature_flag
enable
:destroy_feature_flag
enable
:admin_feature_flag
end
rule
{
can?
(
:public_access
)
}.
enable
:read_package
...
...
@@ -125,7 +127,6 @@ module EE
enable
:admin_path_locks
enable
:update_approvers
enable
:destroy_package
enable
:admin_feature_flags
end
rule
{
license_management_enabled
&
can?
(
:maintainer_access
)
}.
enable
:admin_software_license_policy
...
...
ee/app/views/projects/feature_flags/_configure_feature_flags_button.html.haml
View file @
d2686fe9
%button
.btn.btn-primary.btn-inverted.append-right-8
{
type:
'button'
,
data:
{
toggle:
'modal'
,
target:
'#configure-feature-flags-modal'
}
}
>
-
if
can?
(
current_user
,
:admin_feature_flag
,
@project
)
%button
.btn.btn-primary.btn-inverted.append-right-8
{
type:
'button'
,
data:
{
toggle:
'modal'
,
target:
'#configure-feature-flags-modal'
}
}
>
=
s_
(
'FeatureFlags|Configure'
)
ee/app/views/projects/feature_flags/_configure_feature_flags_modal.html.haml
View file @
d2686fe9
#configure-feature-flags-modal
.modal
{
tabindex:
-
1
,
-
if
can?
(
current_user
,
:admin_feature_flag
,
@project
)
#configure-feature-flags-modal
.modal
{
tabindex:
-
1
,
role:
'dialog'
}
.modal-dialog
{
role:
'document'
}
.modal-content
...
...
ee/app/views/projects/feature_flags/_delete_feature_flag_modal.html.haml
View file @
d2686fe9
.modal
{
id:
"delete-feature-flag-modal-#{feature_flag.id}"
,
-
if
can?
(
current_user
,
:destroy_feature_flag
,
@project
)
.modal
{
id:
"delete-feature-flag-modal-#{feature_flag.id}"
,
tabindex:
-
1
,
role:
'dialog'
}
.modal-dialog
{
role:
'document'
}
...
...
ee/app/views/projects/feature_flags/_errors.html.haml
0 → 100644
View file @
d2686fe9
#error_explanation
.alert.alert-danger
-
@feature_flag
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
ee/app/views/projects/feature_flags/_form.html.haml
View file @
d2686fe9
-
if
@feature_flag
.
errors
.
any?
#error_explanation
.alert.alert-danger
-
@feature_flag
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
=
render
'errors'
%fieldset
.row
...
...
ee/app/views/projects/feature_flags/_new_feature_flag_button.html.haml
View file @
d2686fe9
-
if
can?
(
current_user
,
:create_feature_flag
s
,
@project
)
-
if
can?
(
current_user
,
:create_feature_flag
,
@project
)
=
link_to
new_project_feature_flag_path
(
@project
),
class:
'btn btn-success'
do
=
s_
(
'FeatureFlags|New Feature Flag'
)
ee/app/views/projects/feature_flags/_table.html.haml
View file @
d2686fe9
...
...
@@ -24,12 +24,14 @@
.table-section.section-40.table-button-footer
{
role:
'gridcell'
}
.table-action-buttons.btn-group
-
if
can?
(
current_user
,
:update_feature_flag
,
@project
)
=
link_to
edit_project_feature_flag_path
(
@project
,
feature_flag
),
class:
'btn btn-default has-tooltip'
,
type:
'button'
,
title:
_
(
'Edit'
)
do
=
sprite_icon
(
'pencil'
,
size:
16
)
-
if
can?
(
current_user
,
:destroy_feature_flag
,
@project
)
%button
.btn.btn-danger.has-tooltip
{
type:
'button'
,
data:
{
toggle:
'modal'
,
target:
"#delete-feature-flag-modal-#{feature_flag.id}"
},
...
...
ee/spec/controllers/projects/feature_flags_controller_spec.rb
0 → 100644
View file @
d2686fe9
require
'spec_helper'
describe
Projects
::
FeatureFlagsController
do
include
Rails
.
application
.
routes
.
url_helpers
set
(
:user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
)
}
before
do
project
.
add_developer
(
user
)
sign_in
(
user
)
end
describe
'GET index'
do
render_views
subject
{
get
(
:index
,
view_params
)
}
context
'when there is no feature flags'
do
before
do
subject
end
it
'shows an empty state with buttons'
do
expect
(
response
).
to
be_ok
expect
(
response
).
to
render_template
(
'_empty_state'
)
expect
(
response
).
to
render_template
(
'_configure_feature_flags_button'
)
expect
(
response
).
to
render_template
(
'_new_feature_flag_button'
)
end
end
context
'for a list of feature flags'
do
let!
(
:feature_flags
)
{
create_list
(
:operations_feature_flag
,
50
,
project:
project
)
}
before
do
subject
end
it
'shows an list of feature flags with buttons'
do
expect
(
response
).
to
be_ok
expect
(
response
).
to
render_template
(
'_table'
)
expect
(
response
).
to
render_template
(
'_configure_feature_flags_button'
)
expect
(
response
).
to
render_template
(
'_new_feature_flag_button'
)
end
end
end
describe
'GET new'
do
render_views
subject
{
get
(
:new
,
view_params
)
}
it
'renders the form'
do
subject
expect
(
response
).
to
be_ok
expect
(
response
).
to
render_template
(
'new'
)
expect
(
response
).
to
render_template
(
'_form'
)
end
end
describe
'POST create'
do
render_views
subject
{
post
(
:create
,
params
)
}
context
'when creating a new feature flag'
do
let
(
:params
)
do
view_params
.
merge
(
operations_feature_flag:
{
name:
'my_feature_flag'
,
active:
true
})
end
it
'creates and redirects to list'
do
subject
expect
(
response
).
to
redirect_to
(
project_feature_flags_path
(
project
))
end
end
context
'when a feature flag already exists'
do
let!
(
:feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
,
name:
'my_feature_flag'
)
}
let
(
:params
)
do
view_params
.
merge
(
operations_feature_flag:
{
name:
'my_feature_flag'
,
active:
true
})
end
it
'shows an error'
do
subject
expect
(
response
).
to
render_template
(
'new'
)
expect
(
response
).
to
render_template
(
'_errors'
)
end
end
end
describe
'PUT update'
do
let!
(
:feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
,
name:
'my_feature_flag'
)
}
render_views
subject
{
post
(
:create
,
params
)
}
context
'when updating an existing feature flag'
do
let
(
:params
)
do
view_params
.
merge
(
id:
feature_flag
.
id
,
operations_feature_flag:
{
name:
'my_feature_flag_v2'
,
active:
true
}
)
end
it
'updates and redirects to list'
do
subject
expect
(
response
).
to
redirect_to
(
project_feature_flags_path
(
project
))
end
end
context
'when using existing name of the feature flag'
do
let!
(
:other_feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
,
name:
'other_feature_flag'
)
}
let
(
:params
)
do
view_params
.
merge
(
operations_feature_flag:
{
name:
'other_feature_flag'
,
active:
true
})
end
it
'shows an error'
do
subject
expect
(
response
).
to
render_template
(
'new'
)
expect
(
response
).
to
render_template
(
'_errors'
)
end
end
end
private
def
view_params
{
namespace_id:
project
.
namespace
,
project_id:
project
}
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