flipper-api 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/flipper/api/middleware.rb +2 -1
- data/lib/flipper/api/v1/actions/features.rb +39 -0
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/api/v1/actions/features_spec.rb +106 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 602b1d466a68b777063b76d351ab845843057406
|
4
|
+
data.tar.gz: a0a32a90d8accbce74b0dec3b2157cf9bb669dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81401173dd23fe114cde4087e1469ddb5289cf2032f99062225247ad88933c858401c88d60810d16d9ccd51a2ea18bc030b7b3ba42183e3cb1c49c1da33fbce4
|
7
|
+
data.tar.gz: 8dcdac503eefc843e1c1e61e0e465f70a01d4b4ec556a0212d8c6f373d84663df9b3e0cfc9a10a55d7d2e2cc85c447c87315c1d3c6c319a1d7715a97eebd414a
|
@@ -7,7 +7,7 @@ Pathname(__FILE__).dirname.join('v1/actions').each_child(false) do |name|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module Flipper
|
10
|
-
module Api
|
10
|
+
module Api
|
11
11
|
class Middleware
|
12
12
|
# Public: Initializes an instance of the API middleware.
|
13
13
|
#
|
@@ -37,6 +37,7 @@ module Flipper
|
|
37
37
|
@action_collection = ActionCollection.new
|
38
38
|
@action_collection.add Api::V1::Actions::BooleanGate
|
39
39
|
@action_collection.add Api::V1::Actions::Feature
|
40
|
+
@action_collection.add Api::V1::Actions::Features
|
40
41
|
end
|
41
42
|
|
42
43
|
def flipper
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'flipper/api/action'
|
2
|
+
require 'flipper/api/v1/decorators/feature'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Flipper
|
6
|
+
module Api
|
7
|
+
module V1
|
8
|
+
module Actions
|
9
|
+
class Features < Api::Action
|
10
|
+
|
11
|
+
route %r{api/v1/features\Z}
|
12
|
+
|
13
|
+
def get
|
14
|
+
features = flipper.features.map { |feature|
|
15
|
+
Decorators::Feature.new(feature).as_json
|
16
|
+
}
|
17
|
+
|
18
|
+
json_response({
|
19
|
+
features: features
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def post
|
24
|
+
feature_name = params.fetch('name') do
|
25
|
+
json_response({
|
26
|
+
errors: [{
|
27
|
+
message: 'Missing post parameter: name',
|
28
|
+
}]
|
29
|
+
}, 422)
|
30
|
+
end
|
31
|
+
|
32
|
+
flipper.adapter.add(flipper[feature_name])
|
33
|
+
json_response({}, 200)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/flipper/version.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.describe Flipper::Api::V1::Actions::Features do
|
4
|
+
let(:app) { build_api(flipper) }
|
5
|
+
let(:feature) { build_feature }
|
6
|
+
let(:admin) { double 'Fake Fliper Thing', flipper_id: 10 }
|
7
|
+
|
8
|
+
describe 'get' do
|
9
|
+
context 'with flipper features' do
|
10
|
+
before do
|
11
|
+
flipper[:my_feature].enable
|
12
|
+
flipper[:my_feature].enable(admin)
|
13
|
+
get 'api/v1/features'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds with correct attributes' do
|
17
|
+
expected_response = {
|
18
|
+
"features" => [
|
19
|
+
{
|
20
|
+
"key" =>"my_feature",
|
21
|
+
"state" => "on",
|
22
|
+
"gates" => [
|
23
|
+
{
|
24
|
+
"key"=> "boolean",
|
25
|
+
"name"=> "boolean",
|
26
|
+
"value" => true},
|
27
|
+
{
|
28
|
+
"key" =>"groups",
|
29
|
+
"name" => "group",
|
30
|
+
"value" =>[],
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"key" => "actors",
|
34
|
+
"name"=>"actor",
|
35
|
+
"value"=>["10"],
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"key" => "percentage_of_actors",
|
39
|
+
"name" => "percentage_of_actors",
|
40
|
+
"value" => 0,
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"key"=> "percentage_of_time",
|
44
|
+
"name"=> "percentage_of_time",
|
45
|
+
"value"=> 0,
|
46
|
+
},
|
47
|
+
],
|
48
|
+
},
|
49
|
+
]
|
50
|
+
}
|
51
|
+
expect(last_response.status).to eq(200)
|
52
|
+
expect(json_response).to eq(expected_response)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with no flipper features' do
|
57
|
+
before do
|
58
|
+
get 'api/v1/features'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns empty array for features key' do
|
62
|
+
expected_response = {
|
63
|
+
"features" => []
|
64
|
+
}
|
65
|
+
expect(last_response.status).to eq(200)
|
66
|
+
expect(json_response).to eq(expected_response)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'post' do
|
72
|
+
context 'succesful request' do
|
73
|
+
before do
|
74
|
+
post 'api/v1/features', { name: 'my_feature' }
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'responds 200 on success' do
|
78
|
+
expect(last_response.status).to eq(200)
|
79
|
+
expect(json_response).to eq({})
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'adds feature' do
|
83
|
+
expect(flipper.features.map(&:key)).to include('my_feature')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'does not enable feature' do
|
87
|
+
expect(flipper['my_feature'].enabled?).to be_falsy
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'bad request' do
|
92
|
+
before do
|
93
|
+
post 'api/v1/features'
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns correct status code' do
|
97
|
+
expect(last_response.status).to eq(422)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns formatted error' do
|
101
|
+
errors = json_response['errors']
|
102
|
+
expect(errors.first['message']).to eq('Missing post parameter: name')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.9.
|
39
|
+
version: 0.9.2
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.9.
|
46
|
+
version: 0.9.2
|
47
47
|
description: Rack middleware that provides an API for the flipper gem.
|
48
48
|
email:
|
49
49
|
- nunemaker@gmail.com
|
@@ -60,12 +60,14 @@ files:
|
|
60
60
|
- lib/flipper/api/middleware.rb
|
61
61
|
- lib/flipper/api/v1/actions/boolean_gate.rb
|
62
62
|
- lib/flipper/api/v1/actions/feature.rb
|
63
|
+
- lib/flipper/api/v1/actions/features.rb
|
63
64
|
- lib/flipper/api/v1/decorators/feature.rb
|
64
65
|
- lib/flipper/api/v1/decorators/gate.rb
|
65
66
|
- lib/flipper/version.rb
|
66
67
|
- spec/flipper/api/action_spec.rb
|
67
68
|
- spec/flipper/api/v1/actions/boolean_gate_spec.rb
|
68
69
|
- spec/flipper/api/v1/actions/feature_spec.rb
|
70
|
+
- spec/flipper/api/v1/actions/features_spec.rb
|
69
71
|
homepage: https://github.com/jnunemaker/flipper
|
70
72
|
licenses:
|
71
73
|
- MIT
|
@@ -94,3 +96,4 @@ test_files:
|
|
94
96
|
- spec/flipper/api/action_spec.rb
|
95
97
|
- spec/flipper/api/v1/actions/boolean_gate_spec.rb
|
96
98
|
- spec/flipper/api/v1/actions/feature_spec.rb
|
99
|
+
- spec/flipper/api/v1/actions/features_spec.rb
|