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
2be223b6
Commit
2be223b6
authored
Jan 07, 2019
by
Shinya Maeda
Committed by
Kamil Trzciński
Jan 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add summary endpoint to feature flag controller
Use one endpoint fix a ok Dry up more
parent
3e9a7657
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
16 deletions
+113
-16
ee/app/controllers/projects/feature_flags_controller.rb
ee/app/controllers/projects/feature_flags_controller.rb
+14
-4
ee/app/serializers/feature_flag_summary_entity.rb
ee/app/serializers/feature_flag_summary_entity.rb
+19
-0
ee/app/serializers/feature_flag_summary_serializer.rb
ee/app/serializers/feature_flag_summary_serializer.rb
+5
-0
ee/spec/controllers/projects/feature_flags_controller_spec.rb
...pec/controllers/projects/feature_flags_controller_spec.rb
+18
-10
ee/spec/fixtures/api/schemas/feature_flags.json
ee/spec/fixtures/api/schemas/feature_flags.json
+11
-2
ee/spec/serializers/feature_flag_summary_entity_spec.rb
ee/spec/serializers/feature_flag_summary_entity_spec.rb
+23
-0
ee/spec/serializers/feature_flag_summary_serializer_spec.rb
ee/spec/serializers/feature_flag_summary_serializer_spec.rb
+23
-0
No files found.
ee/app/controllers/projects/feature_flags_controller.rb
View file @
2be223b6
...
...
@@ -21,10 +21,7 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
format
.
json
do
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
10_000
)
render
json:
FeatureFlagSerializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
represent
(
@feature_flags
)
render
json:
{
feature_flags:
feature_flags_json
}.
merge
(
summary_json
)
end
end
end
...
...
@@ -77,4 +74,17 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
params
.
require
(
:operations_feature_flag
)
.
permit
(
:name
,
:description
,
:active
)
end
def
feature_flags_json
FeatureFlagSerializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
represent
(
@feature_flags
)
end
def
summary_json
FeatureFlagSummarySerializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
represent
(
@project
)
end
end
ee/app/serializers/feature_flag_summary_entity.rb
0 → 100644
View file @
2be223b6
# frozen_string_literal: true
class
FeatureFlagSummaryEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:count
do
expose
:all
do
|
project
|
project
.
operations_feature_flags
.
count
end
expose
:enabled
do
|
project
|
project
.
operations_feature_flags
.
enabled
.
count
end
expose
:disabled
do
|
project
|
project
.
operations_feature_flags
.
disabled
.
count
end
end
end
ee/app/serializers/feature_flag_summary_serializer.rb
0 → 100644
View file @
2be223b6
# frozen_string_literal: true
class
FeatureFlagSummarySerializer
<
BaseSerializer
entity
FeatureFlagSummaryEntity
end
ee/spec/controllers/projects/feature_flags_controller_spec.rb
View file @
2be223b6
...
...
@@ -74,16 +74,24 @@ describe Projects::FeatureFlagsController do
it
'returns all feature flags as json response'
do
subject
expect
(
json_response
.
count
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
feature_flag_active
.
name
)
expect
(
json_response
.
second
[
'name'
]).
to
eq
(
feature_flag_inactive
.
name
)
expect
(
json_response
[
'feature_flags'
]
.
count
).
to
eq
(
2
)
expect
(
json_response
[
'feature_flags'
]
.
first
[
'name'
]).
to
eq
(
feature_flag_active
.
name
)
expect
(
json_response
[
'feature_flags'
]
.
second
[
'name'
]).
to
eq
(
feature_flag_inactive
.
name
)
end
it
'returns edit path and destroy path'
do
subject
expect
(
json_response
.
first
[
'edit_path'
]).
not_to
be_nil
expect
(
json_response
.
first
[
'destroy_path'
]).
not_to
be_nil
expect
(
json_response
[
'feature_flags'
].
first
[
'edit_path'
]).
not_to
be_nil
expect
(
json_response
[
'feature_flags'
].
first
[
'destroy_path'
]).
not_to
be_nil
end
it
'returns the summary of feature flags'
do
subject
expect
(
json_response
[
'count'
][
'all'
]).
to
eq
(
2
)
expect
(
json_response
[
'count'
][
'enabled'
]).
to
eq
(
1
)
expect
(
json_response
[
'count'
][
'disabled'
]).
to
eq
(
1
)
end
it
'matches json schema'
do
...
...
@@ -103,7 +111,7 @@ describe Projects::FeatureFlagsController do
it
'returns all feature flags'
do
subject
expect
(
json_response
.
count
).
to
eq
(
2
)
expect
(
json_response
[
'feature_flags'
]
.
count
).
to
eq
(
2
)
end
end
...
...
@@ -113,8 +121,8 @@ describe Projects::FeatureFlagsController do
it
'returns enabled feature flags'
do
subject
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'active'
]).
to
be_truthy
expect
(
json_response
[
'feature_flags'
]
.
count
).
to
eq
(
1
)
expect
(
json_response
[
'feature_flags'
]
.
first
[
'active'
]).
to
be_truthy
end
end
...
...
@@ -124,8 +132,8 @@ describe Projects::FeatureFlagsController do
it
'returns disabled feature flags'
do
subject
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'active'
]).
to
be_falsy
expect
(
json_response
[
'feature_flags'
]
.
count
).
to
eq
(
1
)
expect
(
json_response
[
'feature_flags'
]
.
first
[
'active'
]).
to
be_falsy
end
end
end
...
...
ee/spec/fixtures/api/schemas/feature_flags.json
View file @
2be223b6
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"feature_flag.json"
}
"required"
:
[
"feature_flags"
,
"count"
],
"feature_flags"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"feature_flag.json"
}
},
"count"
:
{
"type"
:
"object"
,
"properties"
:
{
"all"
:
{
"type"
:
"integer"
},
"enabled"
:
{
"type"
:
"integer"
},
"disabled"
:
{
"type"
:
"integer"
}
},
"additionalProperties"
:
false
}
}
ee/spec/serializers/feature_flag_summary_entity_spec.rb
0 → 100644
View file @
2be223b6
# frozen_string_literal: true
require
'spec_helper'
describe
FeatureFlagSummaryEntity
do
let!
(
:feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:request
)
{
double
(
'request'
,
current_user:
user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:entity
)
{
described_class
.
new
(
project
,
request:
request
)
}
before
do
project
.
add_developer
(
user
)
stub_licensed_features
(
feature_flags:
true
)
end
subject
{
entity
.
as_json
}
it
'has summary information'
do
expect
(
subject
).
to
include
(
:count
)
end
end
ee/spec/serializers/feature_flag_summary_serializer_spec.rb
0 → 100644
View file @
2be223b6
# frozen_string_literal: true
require
'spec_helper'
describe
FeatureFlagSummarySerializer
do
let
(
:serializer
)
{
described_class
.
new
(
project:
project
,
current_user:
user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let!
(
:feature_flags
)
{
create
(
:operations_feature_flag
,
project:
project
)
}
before
do
stub_licensed_features
(
feature_flags:
true
)
project
.
add_developer
(
user
)
end
describe
'#represent'
do
subject
{
serializer
.
represent
(
project
)
}
it
'has summary information'
do
expect
(
subject
).
to
include
(
:count
)
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