flipper 0.6.3 → 0.7.0.beta1
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/.travis.yml +2 -2
- data/Gemfile +10 -10
- data/Guardfile +2 -1
- data/README.md +54 -23
- data/Rakefile +1 -1
- data/examples/dsl.rb +2 -2
- data/examples/{percentage_of_random.rb → percentage_of_time.rb} +1 -1
- data/lib/flipper.rb +25 -12
- data/lib/flipper/dsl.rb +96 -8
- data/lib/flipper/feature.rb +216 -37
- data/lib/flipper/gate.rb +6 -38
- data/lib/flipper/gate_values.rb +42 -0
- data/lib/flipper/gates/actor.rb +11 -13
- data/lib/flipper/gates/boolean.rb +3 -12
- data/lib/flipper/gates/group.rb +14 -16
- data/lib/flipper/gates/percentage_of_actors.rb +12 -13
- data/lib/flipper/gates/{percentage_of_random.rb → percentage_of_time.rb} +8 -11
- data/lib/flipper/instrumentation/log_subscriber.rb +1 -1
- data/lib/flipper/instrumentation/subscriber.rb +1 -1
- data/lib/flipper/spec/shared_adapter_specs.rb +16 -16
- data/lib/flipper/type.rb +1 -1
- data/lib/flipper/typecast.rb +44 -0
- data/lib/flipper/types/actor.rb +2 -5
- data/lib/flipper/types/group.rb +6 -0
- data/lib/flipper/types/percentage.rb +7 -1
- data/lib/flipper/types/{percentage_of_random.rb → percentage_of_time.rb} +1 -1
- data/lib/flipper/version.rb +1 -1
- data/script/bootstrap +21 -0
- data/script/guard +15 -0
- data/script/release +15 -0
- data/script/test +30 -0
- data/spec/flipper/dsl_spec.rb +67 -8
- data/spec/flipper/feature_spec.rb +424 -12
- data/spec/flipper/gate_spec.rb +1 -20
- data/spec/flipper/gate_values_spec.rb +134 -0
- data/spec/flipper/gates/actor_spec.rb +1 -21
- data/spec/flipper/gates/boolean_spec.rb +3 -71
- data/spec/flipper/gates/group_spec.rb +3 -23
- data/spec/flipper/gates/percentage_of_actors_spec.rb +5 -26
- data/spec/flipper/gates/percentage_of_time_spec.rb +23 -0
- data/spec/flipper/middleware/memoizer_spec.rb +1 -2
- data/spec/flipper/typecast_spec.rb +63 -0
- data/spec/flipper/types/group_spec.rb +21 -1
- data/spec/flipper/types/percentage_of_time_spec.rb +6 -0
- data/spec/flipper/types/percentage_spec.rb +20 -0
- data/spec/flipper_spec.rb +31 -9
- data/spec/helper.rb +1 -3
- data/spec/integration_spec.rb +22 -22
- metadata +21 -11
- data/spec/flipper/gates/percentage_of_random_spec.rb +0 -46
- data/spec/flipper/types/percentage_of_random_spec.rb +0 -6
data/script/guard
ADDED
data/script/release
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#/ Usage: release
|
3
|
+
#/
|
4
|
+
#/ Package and release the gem to rubyforge.
|
5
|
+
#/
|
6
|
+
|
7
|
+
set -e
|
8
|
+
cd $(dirname "$0")/..
|
9
|
+
|
10
|
+
[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
|
11
|
+
grep '^#/' <"$0"| cut -c4-
|
12
|
+
exit 0
|
13
|
+
}
|
14
|
+
|
15
|
+
script/bootstrap && bundle exec rake release
|
data/script/test
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#/ Usage: test [individual test file]
|
3
|
+
#/
|
4
|
+
#/ Bootstrap and run all tests or an individual test.
|
5
|
+
#/
|
6
|
+
#/ Examples:
|
7
|
+
#/
|
8
|
+
#/ # run all tests
|
9
|
+
#/ test
|
10
|
+
#/
|
11
|
+
#/ # run individual test
|
12
|
+
#/ test spec/qu_spec.rb
|
13
|
+
#/
|
14
|
+
|
15
|
+
set -e
|
16
|
+
cd $(dirname "$0")/..
|
17
|
+
|
18
|
+
[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
|
19
|
+
grep '^#/' <"$0"| cut -c4-
|
20
|
+
exit 0
|
21
|
+
}
|
22
|
+
|
23
|
+
specs="spec/"
|
24
|
+
|
25
|
+
if [ $# -gt 0 ]
|
26
|
+
then
|
27
|
+
specs=$@
|
28
|
+
fi
|
29
|
+
|
30
|
+
script/bootstrap && bundle exec rspec $specs
|
data/spec/flipper/dsl_spec.rb
CHANGED
@@ -5,8 +5,7 @@ require 'flipper/adapters/memory'
|
|
5
5
|
describe Flipper::DSL do
|
6
6
|
subject { Flipper::DSL.new(adapter) }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:adapter) { Flipper::Adapters::Memory.new(source) }
|
8
|
+
let(:adapter) { Flipper::Adapters::Memory.new }
|
10
9
|
|
11
10
|
describe "#initialize" do
|
12
11
|
it "sets adapter" do
|
@@ -115,21 +114,21 @@ describe Flipper::DSL do
|
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
118
|
-
describe "#
|
117
|
+
describe "#time" do
|
119
118
|
before do
|
120
|
-
@result = subject.
|
119
|
+
@result = subject.time(5)
|
121
120
|
end
|
122
121
|
|
123
|
-
it "returns percentage of
|
124
|
-
@result.should be_instance_of(Flipper::Types::
|
122
|
+
it "returns percentage of time" do
|
123
|
+
@result.should be_instance_of(Flipper::Types::PercentageOfTime)
|
125
124
|
end
|
126
125
|
|
127
126
|
it "sets value" do
|
128
127
|
@result.value.should eq(5)
|
129
128
|
end
|
130
129
|
|
131
|
-
it "is aliased to
|
132
|
-
@result.should eq(subject.
|
130
|
+
it "is aliased to percentage_of_time" do
|
131
|
+
@result.should eq(subject.percentage_of_time(@result.value))
|
133
132
|
end
|
134
133
|
end
|
135
134
|
|
@@ -174,4 +173,64 @@ describe Flipper::DSL do
|
|
174
173
|
end
|
175
174
|
end
|
176
175
|
end
|
176
|
+
|
177
|
+
describe "#enable/disable" do
|
178
|
+
it "enables and disables the feature" do
|
179
|
+
subject[:stats].boolean_value.should eq(false)
|
180
|
+
subject.enable(:stats)
|
181
|
+
subject[:stats].boolean_value.should eq(true)
|
182
|
+
|
183
|
+
subject.disable(:stats)
|
184
|
+
subject[:stats].boolean_value.should eq(false)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#enable_actor/disable_actor" do
|
189
|
+
it "enables and disables the feature for actor" do
|
190
|
+
actor = Struct.new(:flipper_id).new(5)
|
191
|
+
|
192
|
+
subject[:stats].actors_value.should be_empty
|
193
|
+
subject.enable_actor(:stats, actor)
|
194
|
+
subject[:stats].actors_value.should eq(Set["5"])
|
195
|
+
|
196
|
+
subject.disable_actor(:stats, actor)
|
197
|
+
subject[:stats].actors_value.should be_empty
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#enable_group/disable_group" do
|
202
|
+
it "enables and disables the feature for group" do
|
203
|
+
actor = Struct.new(:flipper_id).new(5)
|
204
|
+
group = Flipper.register(:fives) { |actor| actor.flipper_id == 5 }
|
205
|
+
|
206
|
+
subject[:stats].groups_value.should be_empty
|
207
|
+
subject.enable_group(:stats, :fives)
|
208
|
+
subject[:stats].groups_value.should eq(Set["fives"])
|
209
|
+
|
210
|
+
subject.disable_group(:stats, :fives)
|
211
|
+
subject[:stats].groups_value.should be_empty
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "#enable_percentage_of_time/disable_percentage_of_time" do
|
216
|
+
it "enables and disables the feature for percentage of time" do
|
217
|
+
subject[:stats].percentage_of_time_value.should be(0)
|
218
|
+
subject.enable_percentage_of_time(:stats, 6)
|
219
|
+
subject[:stats].percentage_of_time_value.should be(6)
|
220
|
+
|
221
|
+
subject.disable_percentage_of_time(:stats)
|
222
|
+
subject[:stats].percentage_of_time_value.should be(0)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "#enable_percentage_of_actors/disable_percentage_of_actors" do
|
227
|
+
it "enables and disables the feature for percentage of time" do
|
228
|
+
subject[:stats].percentage_of_actors_value.should be(0)
|
229
|
+
subject.enable_percentage_of_actors(:stats, 6)
|
230
|
+
subject[:stats].percentage_of_actors_value.should be(6)
|
231
|
+
|
232
|
+
subject.disable_percentage_of_actors(:stats)
|
233
|
+
subject[:stats].percentage_of_actors_value.should be(0)
|
234
|
+
end
|
235
|
+
end
|
177
236
|
end
|
@@ -6,8 +6,7 @@ require 'flipper/instrumenters/memory'
|
|
6
6
|
describe Flipper::Feature do
|
7
7
|
subject { described_class.new(:search, adapter) }
|
8
8
|
|
9
|
-
let(:
|
10
|
-
let(:adapter) { Flipper::Adapters::Memory.new(source) }
|
9
|
+
let(:adapter) { Flipper::Adapters::Memory.new }
|
11
10
|
|
12
11
|
describe "#initialize" do
|
13
12
|
it "sets name" do
|
@@ -37,6 +36,20 @@ describe Flipper::Feature do
|
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
39
|
+
describe "#to_s" do
|
40
|
+
it "returns name as string" do
|
41
|
+
feature = described_class.new(:search, adapter)
|
42
|
+
feature.to_s.should eq("search")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#to_param" do
|
47
|
+
it "returns name as string" do
|
48
|
+
feature = described_class.new(:search, adapter)
|
49
|
+
feature.to_param.should eq("search")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
40
53
|
describe "#gate_for" do
|
41
54
|
context "with percentage of actors" do
|
42
55
|
it "returns percentage of actors gate" do
|
@@ -48,13 +61,11 @@ describe Flipper::Feature do
|
|
48
61
|
end
|
49
62
|
|
50
63
|
describe "#gates" do
|
51
|
-
it "returns array of gates
|
52
|
-
|
53
|
-
instance = described_class.new(:search, adapter, :instrumenter => instrumenter)
|
64
|
+
it "returns array of gates" do
|
65
|
+
instance = described_class.new(:search, adapter)
|
54
66
|
instance.gates.should be_instance_of(Array)
|
55
67
|
instance.gates.each do |gate|
|
56
68
|
gate.should be_a(Flipper::Gate)
|
57
|
-
gate.instrumenter.should be(instrumenter)
|
58
69
|
end
|
59
70
|
instance.gates.size.should be(5)
|
60
71
|
end
|
@@ -63,15 +74,13 @@ describe Flipper::Feature do
|
|
63
74
|
describe "#gate" do
|
64
75
|
context "with symbol name" do
|
65
76
|
it "returns gate by name" do
|
66
|
-
|
67
|
-
subject.gate(:boolean).should eq(boolean_gate)
|
77
|
+
subject.gate(:boolean).should be_instance_of(Flipper::Gates::Boolean)
|
68
78
|
end
|
69
79
|
end
|
70
80
|
|
71
81
|
context "with string name" do
|
72
82
|
it "returns gate by name" do
|
73
|
-
|
74
|
-
subject.gate('boolean').should eq(boolean_gate)
|
83
|
+
subject.gate('boolean').should be_instance_of(Flipper::Gates::Boolean)
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
@@ -155,6 +164,18 @@ describe Flipper::Feature do
|
|
155
164
|
it "returns :on" do
|
156
165
|
subject.state.should be(:on)
|
157
166
|
end
|
167
|
+
|
168
|
+
it "returns true for on?" do
|
169
|
+
subject.on?.should be(true)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "returns false for off?" do
|
173
|
+
subject.off?.should be(false)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns false for conditional?" do
|
177
|
+
subject.conditional?.should be(false)
|
178
|
+
end
|
158
179
|
end
|
159
180
|
|
160
181
|
context "fully off" do
|
@@ -165,16 +186,40 @@ describe Flipper::Feature do
|
|
165
186
|
it "returns :off" do
|
166
187
|
subject.state.should be(:off)
|
167
188
|
end
|
189
|
+
|
190
|
+
it "returns false for on?" do
|
191
|
+
subject.on?.should be(false)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "returns true for off?" do
|
195
|
+
subject.off?.should be(true)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "returns false for conditional?" do
|
199
|
+
subject.conditional?.should be(false)
|
200
|
+
end
|
168
201
|
end
|
169
202
|
|
170
203
|
context "partially on" do
|
171
204
|
before do
|
172
|
-
subject.enable Flipper::Types::
|
205
|
+
subject.enable Flipper::Types::PercentageOfTime.new(5)
|
173
206
|
end
|
174
207
|
|
175
208
|
it "returns :conditional" do
|
176
209
|
subject.state.should be(:conditional)
|
177
210
|
end
|
211
|
+
|
212
|
+
it "returns false for on?" do
|
213
|
+
subject.on?.should be(false)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "returns false for off?" do
|
217
|
+
subject.off?.should be(false)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "returns true for conditional?" do
|
221
|
+
subject.conditional?.should be(true)
|
222
|
+
end
|
178
223
|
end
|
179
224
|
end
|
180
225
|
|
@@ -202,7 +247,7 @@ describe Flipper::Feature do
|
|
202
247
|
context "partially on" do
|
203
248
|
before do
|
204
249
|
actor = Struct.new(:flipper_id).new(5)
|
205
|
-
subject.enable Flipper::Types::
|
250
|
+
subject.enable Flipper::Types::PercentageOfTime.new(5)
|
206
251
|
subject.enable actor
|
207
252
|
end
|
208
253
|
|
@@ -211,4 +256,371 @@ describe Flipper::Feature do
|
|
211
256
|
end
|
212
257
|
end
|
213
258
|
end
|
259
|
+
|
260
|
+
describe "#enabled_groups" do
|
261
|
+
context "when no groups enabled" do
|
262
|
+
it "returns empty set" do
|
263
|
+
subject.enabled_groups.should eq(Set.new)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "when one or more groups enabled" do
|
268
|
+
before do
|
269
|
+
@staff = Flipper.register(:staff) { |thing| true }
|
270
|
+
@preview_features = Flipper.register(:preview_features) { |thing| true }
|
271
|
+
@not_enabled = Flipper.register(:not_enabled) { |thing| true }
|
272
|
+
@disabled = Flipper.register(:disabled) { |thing| true }
|
273
|
+
subject.enable @staff
|
274
|
+
subject.enable @preview_features
|
275
|
+
subject.disable @disabled
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns set of enabled groups" do
|
279
|
+
subject.enabled_groups.should eq(Set.new([
|
280
|
+
@staff,
|
281
|
+
@preview_features,
|
282
|
+
]))
|
283
|
+
end
|
284
|
+
|
285
|
+
it "does not include groups that have not been enabled" do
|
286
|
+
subject.enabled_groups.should_not include(@not_enabled)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "does not include disabled groups" do
|
290
|
+
subject.enabled_groups.should_not include(@disabled)
|
291
|
+
end
|
292
|
+
|
293
|
+
it "is aliased to groups" do
|
294
|
+
subject.enabled_groups.should eq(subject.groups)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe "#disabled_groups" do
|
300
|
+
context "when no groups enabled" do
|
301
|
+
it "returns empty set" do
|
302
|
+
subject.disabled_groups.should eq(Set.new)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "when one or more groups enabled" do
|
307
|
+
before do
|
308
|
+
@staff = Flipper.register(:staff) { |thing| true }
|
309
|
+
@preview_features = Flipper.register(:preview_features) { |thing| true }
|
310
|
+
@not_enabled = Flipper.register(:not_enabled) { |thing| true }
|
311
|
+
@disabled = Flipper.register(:disabled) { |thing| true }
|
312
|
+
subject.enable @staff
|
313
|
+
subject.enable @preview_features
|
314
|
+
subject.disable @disabled
|
315
|
+
end
|
316
|
+
|
317
|
+
it "returns set of groups that are not enabled" do
|
318
|
+
subject.disabled_groups.should eq(Set[
|
319
|
+
@not_enabled,
|
320
|
+
@disabled,
|
321
|
+
])
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "#groups_value" do
|
327
|
+
context "when no groups enabled" do
|
328
|
+
it "returns empty set" do
|
329
|
+
subject.groups_value.should eq(Set.new)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when one or more groups enabled" do
|
334
|
+
before do
|
335
|
+
@staff = Flipper.register(:staff) { |thing| true }
|
336
|
+
@preview_features = Flipper.register(:preview_features) { |thing| true }
|
337
|
+
@not_enabled = Flipper.register(:not_enabled) { |thing| true }
|
338
|
+
@disabled = Flipper.register(:disabled) { |thing| true }
|
339
|
+
subject.enable @staff
|
340
|
+
subject.enable @preview_features
|
341
|
+
subject.disable @disabled
|
342
|
+
end
|
343
|
+
|
344
|
+
it "returns set of enabled groups" do
|
345
|
+
subject.groups_value.should eq(Set.new([
|
346
|
+
@staff.name.to_s,
|
347
|
+
@preview_features.name.to_s,
|
348
|
+
]))
|
349
|
+
end
|
350
|
+
|
351
|
+
it "does not include groups that have not been enabled" do
|
352
|
+
subject.groups_value.should_not include(@not_enabled.name.to_s)
|
353
|
+
end
|
354
|
+
|
355
|
+
it "does not include disabled groups" do
|
356
|
+
subject.groups_value.should_not include(@disabled.name.to_s)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "#actors_value" do
|
362
|
+
context "when no groups enabled" do
|
363
|
+
it "returns empty set" do
|
364
|
+
subject.actors_value.should eq(Set.new)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context "when one or more actors are enabled" do
|
369
|
+
before do
|
370
|
+
subject.enable Flipper::Types::Actor.new(Struct.new(:flipper_id).new("User:5"))
|
371
|
+
subject.enable Flipper::Types::Actor.new(Struct.new(:flipper_id).new("User:22"))
|
372
|
+
end
|
373
|
+
|
374
|
+
it "returns set of actor ids" do
|
375
|
+
subject.actors_value.should eq(Set.new(["User:5", "User:22"]))
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "#boolean_value" do
|
381
|
+
context "when not enabled or disabled" do
|
382
|
+
it "returns false" do
|
383
|
+
subject.boolean_value.should be(false)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
context "when enabled" do
|
388
|
+
before do
|
389
|
+
subject.enable
|
390
|
+
end
|
391
|
+
|
392
|
+
it "returns true" do
|
393
|
+
subject.boolean_value.should be(true)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "when disabled" do
|
398
|
+
before do
|
399
|
+
subject.disable
|
400
|
+
end
|
401
|
+
|
402
|
+
it "returns false" do
|
403
|
+
subject.boolean_value.should be(false)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
describe "#percentage_of_actors_value" do
|
409
|
+
context "when not enabled or disabled" do
|
410
|
+
it "returns nil" do
|
411
|
+
subject.percentage_of_actors_value.should be(0)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
context "when enabled" do
|
416
|
+
before do
|
417
|
+
subject.enable Flipper::Types::PercentageOfActors.new(5)
|
418
|
+
end
|
419
|
+
|
420
|
+
it "returns true" do
|
421
|
+
subject.percentage_of_actors_value.should eq(5)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
context "when disabled" do
|
426
|
+
before do
|
427
|
+
subject.disable
|
428
|
+
end
|
429
|
+
|
430
|
+
it "returns nil" do
|
431
|
+
subject.percentage_of_actors_value.should be(0)
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
describe "#percentage_of_time_value" do
|
437
|
+
context "when not enabled or disabled" do
|
438
|
+
it "returns nil" do
|
439
|
+
subject.percentage_of_time_value.should be(0)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
context "when enabled" do
|
444
|
+
before do
|
445
|
+
subject.enable Flipper::Types::PercentageOfTime.new(5)
|
446
|
+
end
|
447
|
+
|
448
|
+
it "returns true" do
|
449
|
+
subject.percentage_of_time_value.should eq(5)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
context "when disabled" do
|
454
|
+
before do
|
455
|
+
subject.disable
|
456
|
+
end
|
457
|
+
|
458
|
+
it "returns nil" do
|
459
|
+
subject.percentage_of_time_value.should be(0)
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
describe "#gate_values" do
|
465
|
+
context "when no gates are set in adapter" do
|
466
|
+
it "returns default gate values" do
|
467
|
+
subject.gate_values.should eq(Flipper::GateValues.new({
|
468
|
+
:actors => Set.new,
|
469
|
+
:groups => Set.new,
|
470
|
+
:boolean => nil,
|
471
|
+
:percentage_of_actors => nil,
|
472
|
+
:percentage_of_time => nil,
|
473
|
+
}))
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context "with gate values set in adapter" do
|
478
|
+
before do
|
479
|
+
subject.enable Flipper::Types::Boolean.new(true)
|
480
|
+
subject.enable Flipper::Types::Actor.new(Struct.new(:flipper_id).new(5))
|
481
|
+
subject.enable Flipper::Types::Group.new(:admins)
|
482
|
+
subject.enable Flipper::Types::PercentageOfTime.new(50)
|
483
|
+
subject.enable Flipper::Types::PercentageOfActors.new(25)
|
484
|
+
end
|
485
|
+
|
486
|
+
it "returns gate values" do
|
487
|
+
subject.gate_values.should eq(Flipper::GateValues.new({
|
488
|
+
:actors => Set.new(["5"]),
|
489
|
+
:groups => Set.new(["admins"]),
|
490
|
+
:boolean => "true",
|
491
|
+
:percentage_of_time => "50",
|
492
|
+
:percentage_of_actors => "25",
|
493
|
+
}))
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
describe "#enable_actor/disable_actor" do
|
499
|
+
context "with object that responds to flipper_id" do
|
500
|
+
it "updates the gate values to include the actor" do
|
501
|
+
actor = Struct.new(:flipper_id).new(5)
|
502
|
+
subject.gate_values.actors.should be_empty
|
503
|
+
subject.enable_actor(actor)
|
504
|
+
subject.gate_values.actors.should eq(Set["5"])
|
505
|
+
subject.disable_actor(actor)
|
506
|
+
subject.gate_values.actors.should be_empty
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
context "with actor instance" do
|
511
|
+
it "updates the gate values to include the actor" do
|
512
|
+
actor = Struct.new(:flipper_id).new(5)
|
513
|
+
instance = Flipper::Types::Actor.wrap(actor)
|
514
|
+
subject.gate_values.actors.should be_empty
|
515
|
+
subject.enable_actor(instance)
|
516
|
+
subject.gate_values.actors.should eq(Set["5"])
|
517
|
+
subject.disable_actor(instance)
|
518
|
+
subject.gate_values.actors.should be_empty
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
describe "#enable_group/disable_group" do
|
524
|
+
context "with symbol group name" do
|
525
|
+
it "updates the gate values to include the group" do
|
526
|
+
actor = Struct.new(:flipper_id).new(5)
|
527
|
+
group = Flipper.register(:five_only) { |actor| actor.flipper_id == 5 }
|
528
|
+
subject.gate_values.groups.should be_empty
|
529
|
+
subject.enable_group(:five_only)
|
530
|
+
subject.gate_values.groups.should eq(Set["five_only"])
|
531
|
+
subject.disable_group(:five_only)
|
532
|
+
subject.gate_values.groups.should be_empty
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
context "with string group name" do
|
537
|
+
it "updates the gate values to include the group" do
|
538
|
+
actor = Struct.new(:flipper_id).new(5)
|
539
|
+
group = Flipper.register(:five_only) { |actor| actor.flipper_id == 5 }
|
540
|
+
subject.gate_values.groups.should be_empty
|
541
|
+
subject.enable_group("five_only")
|
542
|
+
subject.gate_values.groups.should eq(Set["five_only"])
|
543
|
+
subject.disable_group("five_only")
|
544
|
+
subject.gate_values.groups.should be_empty
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
context "with group instance" do
|
549
|
+
it "updates the gate values for the group" do
|
550
|
+
actor = Struct.new(:flipper_id).new(5)
|
551
|
+
group = Flipper.register(:five_only) { |actor| actor.flipper_id == 5 }
|
552
|
+
subject.gate_values.groups.should be_empty
|
553
|
+
subject.enable_group(group)
|
554
|
+
subject.gate_values.groups.should eq(Set["five_only"])
|
555
|
+
subject.disable_group(group)
|
556
|
+
subject.gate_values.groups.should be_empty
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
describe "#enable_percentage_of_time/disable_percentage_of_time" do
|
562
|
+
context "with integer" do
|
563
|
+
it "updates the gate values" do
|
564
|
+
subject.gate_values.percentage_of_time.should be(0)
|
565
|
+
subject.enable_percentage_of_time(56)
|
566
|
+
subject.gate_values.percentage_of_time.should be(56)
|
567
|
+
subject.disable_percentage_of_time
|
568
|
+
subject.gate_values.percentage_of_time.should be(0)
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
context "with string" do
|
573
|
+
it "updates the gate values" do
|
574
|
+
subject.gate_values.percentage_of_time.should be(0)
|
575
|
+
subject.enable_percentage_of_time("56")
|
576
|
+
subject.gate_values.percentage_of_time.should be(56)
|
577
|
+
subject.disable_percentage_of_time
|
578
|
+
subject.gate_values.percentage_of_time.should be(0)
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
context "with percentage of time instance" do
|
583
|
+
it "updates the gate values" do
|
584
|
+
percentage = Flipper::Types::PercentageOfTime.new(56)
|
585
|
+
subject.gate_values.percentage_of_time.should be(0)
|
586
|
+
subject.enable_percentage_of_time(percentage)
|
587
|
+
subject.gate_values.percentage_of_time.should be(56)
|
588
|
+
subject.disable_percentage_of_time
|
589
|
+
subject.gate_values.percentage_of_time.should be(0)
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
describe "#enable_percentage_of_actors/disable_percentage_of_actors" do
|
595
|
+
context "with integer" do
|
596
|
+
it "updates the gate values" do
|
597
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
598
|
+
subject.enable_percentage_of_actors(56)
|
599
|
+
subject.gate_values.percentage_of_actors.should be(56)
|
600
|
+
subject.disable_percentage_of_actors
|
601
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
context "with string" do
|
606
|
+
it "updates the gate values" do
|
607
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
608
|
+
subject.enable_percentage_of_actors("56")
|
609
|
+
subject.gate_values.percentage_of_actors.should be(56)
|
610
|
+
subject.disable_percentage_of_actors
|
611
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
615
|
+
context "with percentage of actors instance" do
|
616
|
+
it "updates the gate values" do
|
617
|
+
percentage = Flipper::Types::PercentageOfActors.new(56)
|
618
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
619
|
+
subject.enable_percentage_of_actors(percentage)
|
620
|
+
subject.gate_values.percentage_of_actors.should be(56)
|
621
|
+
subject.disable_percentage_of_actors
|
622
|
+
subject.gate_values.percentage_of_actors.should be(0)
|
623
|
+
end
|
624
|
+
end
|
625
|
+
end
|
214
626
|
end
|