flipper-api 0.20.1 → 0.21.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flipper/api/v1/actions/percentage_of_actors_gate.rb +9 -1
- data/lib/flipper/api/v1/actions/percentage_of_time_gate.rb +9 -1
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb +47 -21
- data/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb +67 -21
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e0517903aa3777454c8331c011ef4fd1d28339f85759a748f20b34362ede9c3
|
4
|
+
data.tar.gz: d42d45b7e75d5193af042b4c330d44e8dbc0bfeeb758336a39bed6fdb31e1ecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b323439f1f33c9801aecdc828a29352621c732724477f2889c2d9f24c9a3ef96ff33f378522be3fe3e57b787c657487f2141fdac9f5b8ddc3c279918c2695faa
|
7
|
+
data.tar.gz: 358b98fa02347608e5008d6209c2e4391119ad305b5e6f455fe5fb7be69d330d4eac690361142b4446f018af46ccf42e7b87036e973f2e2b516d9acef83be292
|
@@ -30,9 +30,17 @@ module Flipper
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
def percentage_param
|
34
|
+
@percentage_param ||= params['percentage'].to_s
|
35
|
+
end
|
36
|
+
|
33
37
|
def percentage
|
34
38
|
@percentage ||= begin
|
35
|
-
|
39
|
+
unless percentage_param.match(/\d/)
|
40
|
+
raise ArgumentError, "invalid numeric value: #{percentage_param}"
|
41
|
+
end
|
42
|
+
|
43
|
+
Flipper::Types::Percentage.new(percentage_param).value
|
36
44
|
rescue ArgumentError, TypeError
|
37
45
|
-1
|
38
46
|
end
|
@@ -31,9 +31,17 @@ module Flipper
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def percentage_param
|
35
|
+
@percentage_param ||= params['percentage'].to_s
|
36
|
+
end
|
37
|
+
|
34
38
|
def percentage
|
35
39
|
@percentage ||= begin
|
36
|
-
|
40
|
+
unless percentage_param.match(/\d/)
|
41
|
+
raise ArgumentError, "invalid numeric value: #{percentage_param}"
|
42
|
+
end
|
43
|
+
|
44
|
+
Flipper::Types::Percentage.new(percentage_param).value
|
37
45
|
rescue ArgumentError, TypeError
|
38
46
|
-1
|
39
47
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -4,53 +4,79 @@ RSpec.describe Flipper::Api::V1::Actions::PercentageOfActorsGate do
|
|
4
4
|
let(:app) { build_api(flipper) }
|
5
5
|
|
6
6
|
describe 'enable' do
|
7
|
+
shared_examples 'gates with percentage' do
|
8
|
+
it 'enables gate for feature' do
|
9
|
+
expect(flipper[path].enabled_gate_names).to include(:percentage_of_actors)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns decorated feature with gate enabled for a percent of actors' do
|
13
|
+
gate = json_response['gates'].find { |gate| gate['name'] == 'percentage_of_actors' }
|
14
|
+
expect(gate['value']).to eq(percentage)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
context 'for feature with slash in name' do
|
19
|
+
let(:path) { 'my/feature' }
|
20
|
+
|
8
21
|
before do
|
9
|
-
flipper[
|
10
|
-
post
|
22
|
+
flipper[path].disable
|
23
|
+
post "/features/#{path}/percentage_of_actors", percentage: percentage
|
11
24
|
end
|
12
25
|
|
13
|
-
|
14
|
-
|
26
|
+
context 'with integer percentage' do
|
27
|
+
let(:percentage) { '10' }
|
28
|
+
|
29
|
+
it_behaves_like 'gates with percentage'
|
15
30
|
end
|
16
31
|
|
17
|
-
|
18
|
-
|
19
|
-
|
32
|
+
context 'with decimal percentage' do
|
33
|
+
let(:percentage) { '0.05' }
|
34
|
+
|
35
|
+
it_behaves_like 'gates with percentage'
|
20
36
|
end
|
21
37
|
end
|
22
38
|
|
23
39
|
context 'url-encoded request' do
|
40
|
+
let(:path) { :my_feature }
|
41
|
+
|
24
42
|
before do
|
25
43
|
flipper[:my_feature].disable
|
26
|
-
post
|
44
|
+
post "/features/#{path}/percentage_of_actors", percentage: percentage
|
27
45
|
end
|
28
46
|
|
29
|
-
|
30
|
-
|
47
|
+
context 'with integer percentage' do
|
48
|
+
let(:percentage) { '10' }
|
49
|
+
|
50
|
+
it_behaves_like 'gates with percentage'
|
31
51
|
end
|
32
52
|
|
33
|
-
|
34
|
-
|
35
|
-
|
53
|
+
context 'with decimal percentage' do
|
54
|
+
let(:percentage) { '0.05' }
|
55
|
+
|
56
|
+
it_behaves_like 'gates with percentage'
|
36
57
|
end
|
37
58
|
end
|
38
59
|
|
39
60
|
context 'json request' do
|
61
|
+
let(:path) { :my_feature }
|
62
|
+
|
40
63
|
before do
|
41
64
|
flipper[:my_feature].disable
|
42
|
-
post
|
43
|
-
JSON.generate(percentage:
|
65
|
+
post "/features/#{path}/percentage_of_actors",
|
66
|
+
JSON.generate(percentage: percentage),
|
44
67
|
'CONTENT_TYPE' => 'application/json'
|
45
68
|
end
|
46
69
|
|
47
|
-
|
48
|
-
|
70
|
+
context 'with integer percentage' do
|
71
|
+
let(:percentage) { '10' }
|
72
|
+
|
73
|
+
it_behaves_like 'gates with percentage'
|
49
74
|
end
|
50
75
|
|
51
|
-
|
52
|
-
|
53
|
-
|
76
|
+
context 'with decimal percentage' do
|
77
|
+
let(:percentage) { '0.05' }
|
78
|
+
|
79
|
+
it_behaves_like 'gates with percentage'
|
54
80
|
end
|
55
81
|
end
|
56
82
|
end
|
@@ -113,7 +139,7 @@ RSpec.describe Flipper::Api::V1::Actions::PercentageOfActorsGate do
|
|
113
139
|
end
|
114
140
|
end
|
115
141
|
|
116
|
-
describe 'percentage parameter not
|
142
|
+
describe 'percentage parameter not a number' do
|
117
143
|
before do
|
118
144
|
flipper[:my_feature].disable
|
119
145
|
post '/features/my_feature/percentage_of_actors', percentage: 'foo'
|
@@ -4,34 +4,80 @@ RSpec.describe Flipper::Api::V1::Actions::PercentageOfTimeGate do
|
|
4
4
|
let(:app) { build_api(flipper) }
|
5
5
|
|
6
6
|
describe 'enable' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
shared_examples 'gates with percentage' do
|
8
|
+
it 'enables gate for feature' do
|
9
|
+
expect(flipper[path].enabled_gate_names).to include(:percentage_of_time)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
it 'returns decorated feature with gate enabled for a percent of times' do
|
13
|
+
gate = json_response['gates'].find { |gate| gate['name'] == 'percentage_of_time' }
|
14
|
+
expect(gate['value']).to eq(percentage)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
expect(gate['value']).to eq('10')
|
19
|
-
end
|
20
|
-
end
|
18
|
+
context 'for feature with slash in name' do
|
19
|
+
let(:path) { 'my/feature' }
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
before do
|
22
|
+
flipper[path].disable
|
23
|
+
post "/features/#{path}/percentage_of_time", percentage: percentage
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with integer percentage' do
|
27
|
+
let(:percentage) { '10' }
|
28
|
+
|
29
|
+
it_behaves_like 'gates with percentage'
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with decimal percentage' do
|
33
|
+
let(:percentage) { '0.05' }
|
34
|
+
|
35
|
+
it_behaves_like 'gates with percentage'
|
36
|
+
end
|
26
37
|
end
|
27
38
|
|
28
|
-
|
29
|
-
|
39
|
+
context 'url-encoded request' do
|
40
|
+
let(:path) { :my_feature }
|
41
|
+
|
42
|
+
before do
|
43
|
+
flipper[:my_feature].disable
|
44
|
+
post "/features/#{path}/percentage_of_time", percentage: percentage
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with integer percentage' do
|
48
|
+
let(:percentage) { '10' }
|
49
|
+
|
50
|
+
it_behaves_like 'gates with percentage'
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with decimal percentage' do
|
54
|
+
let(:percentage) { '0.05' }
|
55
|
+
|
56
|
+
it_behaves_like 'gates with percentage'
|
57
|
+
end
|
30
58
|
end
|
31
59
|
|
32
|
-
|
33
|
-
|
34
|
-
|
60
|
+
context 'json request' do
|
61
|
+
let(:path) { :my_feature }
|
62
|
+
|
63
|
+
before do
|
64
|
+
flipper[:my_feature].disable
|
65
|
+
post "/features/#{path}/percentage_of_time",
|
66
|
+
JSON.generate(percentage: percentage),
|
67
|
+
'CONTENT_TYPE' => 'application/json'
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with integer percentage' do
|
71
|
+
let(:percentage) { '10' }
|
72
|
+
|
73
|
+
it_behaves_like 'gates with percentage'
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with decimal percentage' do
|
77
|
+
let(:percentage) { '0.05' }
|
78
|
+
|
79
|
+
it_behaves_like 'gates with percentage'
|
80
|
+
end
|
35
81
|
end
|
36
82
|
end
|
37
83
|
|
@@ -93,7 +139,7 @@ RSpec.describe Flipper::Api::V1::Actions::PercentageOfTimeGate do
|
|
93
139
|
end
|
94
140
|
end
|
95
141
|
|
96
|
-
describe 'percentage parameter not an
|
142
|
+
describe 'percentage parameter not an number' do
|
97
143
|
before do
|
98
144
|
flipper[:my_feature].disable
|
99
145
|
post '/features/my_feature/percentage_of_time', percentage: 'foo'
|
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.
|
4
|
+
version: 0.21.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-08 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.
|
39
|
+
version: 0.21.0.rc2
|
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.
|
46
|
+
version: 0.21.0.rc2
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
- nunemaker@gmail.com
|
@@ -101,9 +101,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - ">"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: 1.3.1
|
107
107
|
requirements: []
|
108
108
|
rubygems_version: 3.0.3
|
109
109
|
signing_key:
|