rollout 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/rollout_spec.rb CHANGED
@@ -1,132 +1,130 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe "Rollout" do
4
- before do
5
- @rollout = Rollout.new(Redis.current)
6
- end
4
+ let(:rollout) { Rollout.new($redis) }
7
5
 
8
6
  describe "when a group is activated" do
9
7
  before do
10
- @rollout.define_group(:fivesonly) { |user| user.id == 5 }
11
- @rollout.activate_group(:chat, :fivesonly)
8
+ rollout.define_group(:fivesonly) { |user| user.id == 5 }
9
+ rollout.activate_group(:chat, :fivesonly)
12
10
  end
13
11
 
14
12
  it "the feature is active for users for which the block evaluates to true" do
15
- expect(@rollout).to be_active(:chat, double(id: 5))
13
+ expect(rollout).to be_active(:chat, double(id: 5))
16
14
  end
17
15
 
18
16
  it "is not active for users for which the block evaluates to false" do
19
- expect(@rollout).not_to be_active(:chat, double(id: 1))
17
+ expect(rollout).not_to be_active(:chat, double(id: 1))
20
18
  end
21
19
 
22
20
  it "is not active if a group is found in Redis but not defined in Rollout" do
23
- @rollout.activate_group(:chat, :fake)
24
- expect(@rollout).not_to be_active(:chat, double(id: 1))
21
+ rollout.activate_group(:chat, :fake)
22
+ expect(rollout).not_to be_active(:chat, double(id: 1))
25
23
  end
26
24
  end
27
25
 
28
26
  describe "the default all group" do
29
27
  before do
30
- @rollout.activate_group(:chat, :all)
28
+ rollout.activate_group(:chat, :all)
31
29
  end
32
30
 
33
31
  it "evaluates to true no matter what" do
34
- expect(@rollout).to be_active(:chat, double(id: 0))
32
+ expect(rollout).to be_active(:chat, double(id: 0))
35
33
  end
36
34
  end
37
35
 
38
36
  describe "deactivating a group" do
39
37
  before do
40
- @rollout.define_group(:fivesonly) { |user| user.id == 5 }
41
- @rollout.activate_group(:chat, :all)
42
- @rollout.activate_group(:chat, :some)
43
- @rollout.activate_group(:chat, :fivesonly)
44
- @rollout.deactivate_group(:chat, :all)
45
- @rollout.deactivate_group(:chat, "some")
38
+ rollout.define_group(:fivesonly) { |user| user.id == 5 }
39
+ rollout.activate_group(:chat, :all)
40
+ rollout.activate_group(:chat, :some)
41
+ rollout.activate_group(:chat, :fivesonly)
42
+ rollout.deactivate_group(:chat, :all)
43
+ rollout.deactivate_group(:chat, "some")
46
44
  end
47
45
 
48
46
  it "deactivates the rules for that group" do
49
- expect(@rollout).not_to be_active(:chat, double(id: 10))
47
+ expect(rollout).not_to be_active(:chat, double(id: 10))
50
48
  end
51
49
 
52
50
  it "leaves the other groups active" do
53
- expect(@rollout.get(:chat).groups).to eq [:fivesonly]
51
+ expect(rollout.get(:chat).groups).to eq [:fivesonly]
54
52
  end
55
53
 
56
54
  it "leaves the other groups active using sets" do
57
- @options = @rollout.instance_variable_get("@options")
55
+ @options = rollout.instance_variable_get("@options")
58
56
  @options[:use_sets] = true
59
- expect(@rollout.get(:chat).groups).to eq [:fivesonly].to_set
57
+ expect(rollout.get(:chat).groups).to eq [:fivesonly].to_set
60
58
  end
61
59
  end
62
60
 
63
61
  describe "deactivating a feature completely" do
64
62
  before do
65
- @rollout.define_group(:fivesonly) { |user| user.id == 5 }
66
- @rollout.activate_group(:chat, :all)
67
- @rollout.activate_group(:chat, :fivesonly)
68
- @rollout.activate_user(:chat, double(id: 51))
69
- @rollout.activate_percentage(:chat, 100)
70
- @rollout.activate(:chat)
71
- @rollout.deactivate(:chat)
63
+ rollout.define_group(:fivesonly) { |user| user.id == 5 }
64
+ rollout.activate_group(:chat, :all)
65
+ rollout.activate_group(:chat, :fivesonly)
66
+ rollout.activate_user(:chat, double(id: 51))
67
+ rollout.activate_percentage(:chat, 100)
68
+ rollout.activate(:chat)
69
+ rollout.deactivate(:chat)
72
70
  end
73
71
 
74
72
  it "removes all of the groups" do
75
- expect(@rollout).not_to be_active(:chat, double(id: 0))
73
+ expect(rollout).not_to be_active(:chat, double(id: 0))
76
74
  end
77
75
 
78
76
  it "removes all of the users" do
79
- expect(@rollout).not_to be_active(:chat, double(id: 51))
77
+ expect(rollout).not_to be_active(:chat, double(id: 51))
80
78
  end
81
79
 
82
80
  it "removes the percentage" do
83
- expect(@rollout).not_to be_active(:chat, double(id: 24))
81
+ expect(rollout).not_to be_active(:chat, double(id: 24))
84
82
  end
85
83
 
86
84
  it "removes globally" do
87
- expect(@rollout).not_to be_active(:chat)
85
+ expect(rollout).not_to be_active(:chat)
88
86
  end
89
87
  end
90
88
 
91
89
  describe "activating a specific user" do
92
90
  before do
93
- @rollout.activate_user(:chat, double(id: 42))
91
+ rollout.activate_user(:chat, double(id: 42))
94
92
  end
95
93
 
96
94
  it "is active for that user" do
97
- expect(@rollout).to be_active(:chat, double(id: 42))
95
+ expect(rollout).to be_active(:chat, double(id: 42))
98
96
  end
99
97
 
100
98
  it "remains inactive for other users" do
101
- expect(@rollout).not_to be_active(:chat, double(id: 24))
99
+ expect(rollout).not_to be_active(:chat, double(id: 24))
102
100
  end
103
101
  end
104
102
 
105
103
  describe "activating a specific user by ID" do
106
104
  before do
107
- @rollout.activate_user(:chat, 42)
105
+ rollout.activate_user(:chat, 42)
108
106
  end
109
107
 
110
108
  it "is active for that user" do
111
- expect(@rollout).to be_active(:chat, double(id: 42))
109
+ expect(rollout).to be_active(:chat, double(id: 42))
112
110
  end
113
111
 
114
112
  it "remains inactive for other users" do
115
- expect(@rollout).not_to be_active(:chat, double(id: 24))
113
+ expect(rollout).not_to be_active(:chat, double(id: 24))
116
114
  end
117
115
  end
118
116
 
119
117
  describe "activating a specific user with a string id" do
120
118
  before do
121
- @rollout.activate_user(:chat, double(id: "user-72"))
119
+ rollout.activate_user(:chat, double(id: "user-72"))
122
120
  end
123
121
 
124
122
  it "is active for that user" do
125
- expect(@rollout).to be_active(:chat, double(id: "user-72"))
123
+ expect(rollout).to be_active(:chat, double(id: "user-72"))
126
124
  end
127
125
 
128
126
  it "remains inactive for other users" do
129
- expect(@rollout).not_to be_active(:chat, double(id: "user-12"))
127
+ expect(rollout).not_to be_active(:chat, double(id: "user-12"))
130
128
  end
131
129
  end
132
130
 
@@ -134,56 +132,56 @@ RSpec.describe "Rollout" do
134
132
  context "specified by user objects" do
135
133
  let(:users) { [double(id: 1), double(id: 2), double(id: 3)] }
136
134
 
137
- before { @rollout.activate_users(:chat, users) }
135
+ before { rollout.activate_users(:chat, users) }
138
136
 
139
137
  it "is active for the given users" do
140
- users.each { |user| expect(@rollout).to be_active(:chat, user) }
138
+ users.each { |user| expect(rollout).to be_active(:chat, user) }
141
139
  end
142
140
 
143
141
  it "remains inactive for other users" do
144
- expect(@rollout).not_to be_active(:chat, double(id: 4))
142
+ expect(rollout).not_to be_active(:chat, double(id: 4))
145
143
  end
146
144
  end
147
145
 
148
146
  context "specified by user ids" do
149
147
  let(:users) { [1, 2, 3] }
150
148
 
151
- before { @rollout.activate_users(:chat, users) }
149
+ before { rollout.activate_users(:chat, users) }
152
150
 
153
151
  it "is active for the given users" do
154
- users.each { |user| expect(@rollout).to be_active(:chat, user) }
152
+ users.each { |user| expect(rollout).to be_active(:chat, user) }
155
153
  end
156
154
 
157
155
  it "remains inactive for other users" do
158
- expect(@rollout).not_to be_active(:chat, 4)
156
+ expect(rollout).not_to be_active(:chat, 4)
159
157
  end
160
158
  end
161
159
  end
162
160
 
163
161
  describe "deactivating a specific user" do
164
162
  before do
165
- @rollout.activate_user(:chat, double(id: 42))
166
- @rollout.activate_user(:chat, double(id: 4242))
167
- @rollout.activate_user(:chat, double(id: 24))
168
- @rollout.deactivate_user(:chat, double(id: 42))
169
- @rollout.deactivate_user(:chat, double(id: "4242"))
163
+ rollout.activate_user(:chat, double(id: 42))
164
+ rollout.activate_user(:chat, double(id: 4242))
165
+ rollout.activate_user(:chat, double(id: 24))
166
+ rollout.deactivate_user(:chat, double(id: 42))
167
+ rollout.deactivate_user(:chat, double(id: "4242"))
170
168
  end
171
169
 
172
170
  it "that user should no longer be active" do
173
- expect(@rollout).not_to be_active(:chat, double(id: 42))
171
+ expect(rollout).not_to be_active(:chat, double(id: 42))
174
172
  end
175
173
 
176
174
  it "remains active for other active users" do
177
- @options = @rollout.instance_variable_get("@options")
175
+ @options = rollout.instance_variable_get("@options")
178
176
  @options[:use_sets] = false
179
- expect(@rollout.get(:chat).users).to eq %w(24)
177
+ expect(rollout.get(:chat).users).to eq %w(24)
180
178
  end
181
179
 
182
180
  it "remains active for other active users using sets" do
183
- @options = @rollout.instance_variable_get("@options")
181
+ @options = rollout.instance_variable_get("@options")
184
182
  @options[:use_sets] = true
185
183
 
186
- expect(@rollout.get(:chat).users).to eq %w(24).to_set
184
+ expect(rollout.get(:chat).users).to eq %w(24).to_set
187
185
  end
188
186
  end
189
187
 
@@ -193,16 +191,16 @@ RSpec.describe "Rollout" do
193
191
  let(:inactive_users) { [double(id: 3), double(id: 4)] }
194
192
 
195
193
  before do
196
- @rollout.activate_users(:chat, active_users + inactive_users)
197
- @rollout.deactivate_users(:chat, inactive_users)
194
+ rollout.activate_users(:chat, active_users + inactive_users)
195
+ rollout.deactivate_users(:chat, inactive_users)
198
196
  end
199
197
 
200
198
  it "is active for the active users" do
201
- active_users.each { |user| expect(@rollout).to be_active(:chat, user) }
199
+ active_users.each { |user| expect(rollout).to be_active(:chat, user) }
202
200
  end
203
201
 
204
202
  it "is not active for inactive users" do
205
- inactive_users.each { |user| expect(@rollout).not_to be_active(:chat, user) }
203
+ inactive_users.each { |user| expect(rollout).not_to be_active(:chat, user) }
206
204
  end
207
205
  end
208
206
 
@@ -211,16 +209,16 @@ RSpec.describe "Rollout" do
211
209
  let(:inactive_users) { [3, 4] }
212
210
 
213
211
  before do
214
- @rollout.activate_users(:chat, active_users + inactive_users)
215
- @rollout.deactivate_users(:chat, inactive_users)
212
+ rollout.activate_users(:chat, active_users + inactive_users)
213
+ rollout.deactivate_users(:chat, inactive_users)
216
214
  end
217
215
 
218
216
  it "is active for the active users" do
219
- active_users.each { |user| expect(@rollout).to be_active(:chat, user) }
217
+ active_users.each { |user| expect(rollout).to be_active(:chat, user) }
220
218
  end
221
219
 
222
220
  it "is not active for inactive users" do
223
- inactive_users.each { |user| expect(@rollout).not_to be_active(:chat, user) }
221
+ inactive_users.each { |user| expect(rollout).not_to be_active(:chat, user) }
224
222
  end
225
223
  end
226
224
  end
@@ -229,200 +227,200 @@ RSpec.describe "Rollout" do
229
227
  describe 'set a group of users' do
230
228
  it 'should replace the users with the given array' do
231
229
  users = %w(1 2 3 4)
232
- @rollout.activate_users(:chat, %w(10 20 30))
233
- @rollout.set_users(:chat, users)
234
- expect(@rollout.get(:chat).users).to eq(users)
230
+ rollout.activate_users(:chat, %w(10 20 30))
231
+ rollout.set_users(:chat, users)
232
+ expect(rollout.get(:chat).users).to eq(users)
235
233
  end
236
234
  end
237
235
 
238
236
  describe "activating a feature globally" do
239
237
  before do
240
- @rollout.activate(:chat)
238
+ rollout.activate(:chat)
241
239
  end
242
240
 
243
241
  it "activates the feature" do
244
- expect(@rollout).to be_active(:chat)
242
+ expect(rollout).to be_active(:chat)
245
243
  end
246
244
 
247
245
  it "sets @data to empty hash" do
248
- expect(@rollout.get(:chat).data).to eq({})
246
+ expect(rollout.get(:chat).data).to eq({})
249
247
  end
250
248
  end
251
249
 
252
250
  describe "activating a feature for a percentage of users" do
253
251
  before do
254
- @rollout.activate_percentage(:chat, 20)
252
+ rollout.activate_percentage(:chat, 20)
255
253
  end
256
254
 
257
255
  it "activates the feature for that percentage of the users" do
258
- expect((1..100).select { |id| @rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(20)
256
+ expect((1..100).select { |id| rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(20)
259
257
  end
260
258
  end
261
259
 
262
260
  describe "activating a feature for a percentage of users" do
263
261
  before do
264
- @rollout.activate_percentage(:chat, 20)
262
+ rollout.activate_percentage(:chat, 20)
265
263
  end
266
264
 
267
265
  it "activates the feature for that percentage of the users" do
268
- expect((1..200).select { |id| @rollout.active?(:chat, double(id: id)) }.length).to be_within(4).of(40)
266
+ expect((1..200).select { |id| rollout.active?(:chat, double(id: id)) }.length).to be_within(4).of(40)
269
267
  end
270
268
  end
271
269
 
272
270
  describe "activating a feature for a percentage of users" do
273
271
  before do
274
- @rollout.activate_percentage(:chat, 5)
272
+ rollout.activate_percentage(:chat, 5)
275
273
  end
276
274
 
277
275
  it "activates the feature for that percentage of the users" do
278
- expect((1..100).select { |id| @rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(5)
276
+ expect((1..100).select { |id| rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(5)
279
277
  end
280
278
  end
281
279
 
282
280
  describe "activating a feature for a percentage of users" do
283
281
  before do
284
- @rollout.activate_percentage(:chat, 0.1)
282
+ rollout.activate_percentage(:chat, 0.1)
285
283
  end
286
284
 
287
285
  it "activates the feature for that percentage of the users" do
288
- expect((1..10_000).to_set.select { |id| @rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(10)
286
+ expect((1..10_000).to_set.select { |id| rollout.active?(:chat, double(id: id)) }.length).to be_within(2).of(10)
289
287
  end
290
288
  end
291
289
 
292
290
  describe "activating a feature for a percentage of users" do
293
291
  before do
294
- @rollout.activate_percentage(:chat, 20)
295
- @rollout.activate_percentage(:beta, 20)
296
- @options = @rollout.instance_variable_get("@options")
292
+ rollout.activate_percentage(:chat, 20)
293
+ rollout.activate_percentage(:beta, 20)
294
+ @options = rollout.instance_variable_get("@options")
297
295
  end
298
296
 
299
297
  it "activates the feature for a random set of users when opt is set" do
300
298
  @options[:randomize_percentage] = true
301
- chat_users = (1..100).select { |id| @rollout.active?(:chat, double(id: id)) }
302
- beta_users = (1..100).select { |id| @rollout.active?(:beta, double(id: id)) }
299
+ chat_users = (1..100).select { |id| rollout.active?(:chat, double(id: id)) }
300
+ beta_users = (1..100).select { |id| rollout.active?(:beta, double(id: id)) }
303
301
  expect(chat_users).not_to eq beta_users
304
302
  end
305
303
  it "activates the feature for the same set of users when opt is not set" do
306
304
  @options[:randomize_percentage] = false
307
- chat_users = (1..100).select { |id| @rollout.active?(:chat, double(id: id)) }
308
- beta_users = (1..100).select { |id| @rollout.active?(:beta, double(id: id)) }
305
+ chat_users = (1..100).select { |id| rollout.active?(:chat, double(id: id)) }
306
+ beta_users = (1..100).select { |id| rollout.active?(:beta, double(id: id)) }
309
307
  expect(chat_users).to eq beta_users
310
308
  end
311
309
  end
312
310
 
313
311
  describe "activating a feature for a group as a string" do
314
312
  before do
315
- @rollout.define_group(:admins) { |user| user.id == 5 }
316
- @rollout.activate_group(:chat, "admins")
313
+ rollout.define_group(:admins) { |user| user.id == 5 }
314
+ rollout.activate_group(:chat, "admins")
317
315
  end
318
316
 
319
317
  it "the feature is active for users for which the block evaluates to true" do
320
- expect(@rollout).to be_active(:chat, double(id: 5))
318
+ expect(rollout).to be_active(:chat, double(id: 5))
321
319
  end
322
320
 
323
321
  it "is not active for users for which the block evaluates to false" do
324
- expect(@rollout).not_to be_active(:chat, double(id: 1))
322
+ expect(rollout).not_to be_active(:chat, double(id: 1))
325
323
  end
326
324
  end
327
325
 
328
326
  describe "deactivating the percentage of users" do
329
327
  before do
330
- @rollout.activate_percentage(:chat, 100)
331
- @rollout.deactivate_percentage(:chat)
328
+ rollout.activate_percentage(:chat, 100)
329
+ rollout.deactivate_percentage(:chat)
332
330
  end
333
331
 
334
332
  it "becomes inactivate for all users" do
335
- expect(@rollout).not_to be_active(:chat, double(id: 24))
333
+ expect(rollout).not_to be_active(:chat, double(id: 24))
336
334
  end
337
335
  end
338
336
 
339
337
  describe "deactivating the feature globally" do
340
338
  before do
341
- @rollout.activate(:chat)
342
- @rollout.deactivate(:chat)
339
+ rollout.activate(:chat)
340
+ rollout.deactivate(:chat)
343
341
  end
344
342
 
345
343
  it "becomes inactivate" do
346
- expect(@rollout).not_to be_active(:chat)
344
+ expect(rollout).not_to be_active(:chat)
347
345
  end
348
346
  end
349
347
 
350
348
  describe "setting a feature on" do
351
349
  before do
352
- @rollout.set(:chat, true)
350
+ rollout.set(:chat, true)
353
351
  end
354
352
 
355
353
  it "becomes activated" do
356
- expect(@rollout).to be_active(:chat)
354
+ expect(rollout).to be_active(:chat)
357
355
  end
358
356
  end
359
357
 
360
358
  describe "setting a feature off" do
361
359
  before do
362
- @rollout.set(:chat, false)
360
+ rollout.set(:chat, false)
363
361
  end
364
362
 
365
363
  it "becomes inactivated" do
366
- expect(@rollout).not_to be_active(:chat)
364
+ expect(rollout).not_to be_active(:chat)
367
365
  end
368
366
  end
369
367
 
370
368
  describe "deleting a feature" do
371
369
  before do
372
- @rollout.set(:chat, true)
370
+ rollout.set(:chat, true)
373
371
  end
374
372
 
375
373
  context "when feature was passed as string" do
376
374
  it "should be removed from features list" do
377
- expect(@rollout.features.size).to eq 1
378
- @rollout.delete('chat')
379
- expect(@rollout.features.size).to eq 0
375
+ expect(rollout.features.size).to eq 1
376
+ rollout.delete('chat')
377
+ expect(rollout.features.size).to eq 0
380
378
  end
381
379
  end
382
380
 
383
381
  it "should be removed from features list" do
384
- expect(@rollout.features.size).to eq 1
385
- @rollout.delete(:chat)
386
- expect(@rollout.features.size).to eq 0
382
+ expect(rollout.features.size).to eq 1
383
+ rollout.delete(:chat)
384
+ expect(rollout.features.size).to eq 0
387
385
  end
388
386
 
389
387
  it "should have metadata cleared" do
390
- expect(@rollout.get(:chat).percentage).to eq 100
391
- @rollout.delete(:chat)
392
- expect(@rollout.get(:chat).percentage).to eq 0
388
+ expect(rollout.get(:chat).percentage).to eq 100
389
+ rollout.delete(:chat)
390
+ expect(rollout.get(:chat).percentage).to eq 0
393
391
  end
394
392
  end
395
393
 
396
394
  describe "keeps a list of features" do
397
395
  it "saves the feature" do
398
- @rollout.activate(:chat)
399
- expect(@rollout.features).to be_include(:chat)
396
+ rollout.activate(:chat)
397
+ expect(rollout.features).to be_include(:chat)
400
398
  end
401
399
 
402
400
  it "does not contain doubles" do
403
- @rollout.activate(:chat)
404
- @rollout.activate(:chat)
405
- expect(@rollout.features.size).to eq(1)
401
+ rollout.activate(:chat)
402
+ rollout.activate(:chat)
403
+ expect(rollout.features.size).to eq(1)
406
404
  end
407
405
 
408
406
  it "does not contain doubles when using string" do
409
- @rollout.activate(:chat)
410
- @rollout.activate("chat")
411
- expect(@rollout.features.size).to eq(1)
407
+ rollout.activate(:chat)
408
+ rollout.activate("chat")
409
+ expect(rollout.features.size).to eq(1)
412
410
  end
413
411
  end
414
412
 
415
413
  describe "#get" do
416
414
  before do
417
- @rollout.activate_percentage(:chat, 10)
418
- @rollout.activate_group(:chat, :caretakers)
419
- @rollout.activate_group(:chat, :greeters)
420
- @rollout.activate(:signup)
421
- @rollout.activate_user(:chat, double(id: 42))
415
+ rollout.activate_percentage(:chat, 10)
416
+ rollout.activate_group(:chat, :caretakers)
417
+ rollout.activate_group(:chat, :greeters)
418
+ rollout.activate(:signup)
419
+ rollout.activate_user(:chat, double(id: 42))
422
420
  end
423
421
 
424
422
  it "returns the feature object" do
425
- feature = @rollout.get(:chat)
423
+ feature = rollout.get(:chat)
426
424
  expect(feature.groups).to eq [:caretakers, :greeters]
427
425
  expect(feature.percentage).to eq 10
428
426
  expect(feature.users).to eq %w(42)
@@ -433,17 +431,17 @@ RSpec.describe "Rollout" do
433
431
  data: {},
434
432
  )
435
433
 
436
- feature = @rollout.get(:signup)
434
+ feature = rollout.get(:signup)
437
435
  expect(feature.groups).to be_empty
438
436
  expect(feature.users).to be_empty
439
437
  expect(feature.percentage).to eq(100)
440
438
  end
441
439
 
442
440
  it "returns the feature objects using sets" do
443
- @options = @rollout.instance_variable_get("@options")
441
+ @options = rollout.instance_variable_get("@options")
444
442
  @options[:use_sets] = true
445
443
 
446
- feature = @rollout.get(:chat)
444
+ feature = rollout.get(:chat)
447
445
  expect(feature.groups).to eq [:caretakers, :greeters].to_set
448
446
  expect(feature.percentage).to eq 10
449
447
  expect(feature.users).to eq %w(42).to_set
@@ -454,7 +452,7 @@ RSpec.describe "Rollout" do
454
452
  data: {},
455
453
  )
456
454
 
457
- feature = @rollout.get(:signup)
455
+ feature = rollout.get(:signup)
458
456
  expect(feature.groups).to be_empty
459
457
  expect(feature.users).to be_empty
460
458
  expect(feature.percentage).to eq(100)
@@ -465,14 +463,14 @@ RSpec.describe "Rollout" do
465
463
  let(:features) { %w(signup beta alpha gm) }
466
464
 
467
465
  before do
468
- features.each { |f| @rollout.activate(f) }
466
+ features.each { |f| rollout.activate(f) }
469
467
 
470
- @rollout.clear!
468
+ rollout.clear!
471
469
  end
472
470
 
473
471
  it "each feature is cleared" do
474
472
  features.each do |feature|
475
- expect(@rollout.get(feature).to_hash).to eq(
473
+ expect(rollout.get(feature).to_hash).to eq(
476
474
  percentage: 0,
477
475
  users: [],
478
476
  groups: [],
@@ -482,10 +480,10 @@ RSpec.describe "Rollout" do
482
480
  end
483
481
 
484
482
  it "each feature is cleared with sets" do
485
- @options = @rollout.instance_variable_get("@options")
483
+ @options = rollout.instance_variable_get("@options")
486
484
  @options[:use_sets] = true
487
485
  features.each do |feature|
488
- expect(@rollout.get(feature).to_hash).to eq(
486
+ expect(rollout.get(feature).to_hash).to eq(
489
487
  percentage: 0,
490
488
  users: Set.new,
491
489
  groups: Set.new,
@@ -495,7 +493,7 @@ RSpec.describe "Rollout" do
495
493
  end
496
494
 
497
495
  it "removes all features" do
498
- expect(@rollout.features).to be_empty
496
+ expect(rollout.features).to be_empty
499
497
  end
500
498
  end
501
499
 
@@ -503,35 +501,35 @@ RSpec.describe "Rollout" do
503
501
  let(:user_double) { double(id: 7) }
504
502
 
505
503
  before do
506
- @rollout.activate(:chat)
507
- @rollout.activate_user(:video, user_double)
508
- @rollout.deactivate(:vr)
504
+ rollout.activate(:chat)
505
+ rollout.activate_user(:video, user_double)
506
+ rollout.deactivate(:vr)
509
507
  end
510
508
 
511
509
  it "returns a hash" do
512
- expect(@rollout.feature_states).to be_a(Hash)
510
+ expect(rollout.feature_states).to be_a(Hash)
513
511
  end
514
512
 
515
513
  context "with user argument" do
516
514
  it "maps active feature as true" do
517
- state = @rollout.feature_states(user_double)[:video]
515
+ state = rollout.feature_states(user_double)[:video]
518
516
  expect(state).to eq(true)
519
517
  end
520
518
 
521
519
  it "maps inactive feature as false" do
522
- state = @rollout.feature_states[:vr]
520
+ state = rollout.feature_states[:vr]
523
521
  expect(state).to eq(false)
524
522
  end
525
523
  end
526
524
 
527
525
  context "with no argument" do
528
526
  it "maps active feature as true" do
529
- state = @rollout.feature_states[:chat]
527
+ state = rollout.feature_states[:chat]
530
528
  expect(state).to eq(true)
531
529
  end
532
530
 
533
531
  it "maps inactive feature as false" do
534
- state = @rollout.feature_states[:video]
532
+ state = rollout.feature_states[:video]
535
533
  expect(state).to eq(false)
536
534
  end
537
535
  end
@@ -541,36 +539,36 @@ RSpec.describe "Rollout" do
541
539
  let(:user_double) { double(id: 19) }
542
540
 
543
541
  before do
544
- @rollout.activate(:chat)
545
- @rollout.activate_user(:video, user_double)
546
- @rollout.deactivate(:vr)
542
+ rollout.activate(:chat)
543
+ rollout.activate_user(:video, user_double)
544
+ rollout.deactivate(:vr)
547
545
  end
548
546
 
549
547
  it "returns an array" do
550
- expect(@rollout.active_features).to be_a(Array)
548
+ expect(rollout.active_features).to be_a(Array)
551
549
  end
552
550
 
553
551
  context "with user argument" do
554
552
  it "includes active feature" do
555
- features = @rollout.active_features(user_double)
553
+ features = rollout.active_features(user_double)
556
554
  expect(features).to include(:video)
557
555
  expect(features).to include(:chat)
558
556
  end
559
557
 
560
558
  it "excludes inactive feature" do
561
- features = @rollout.active_features(user_double)
559
+ features = rollout.active_features(user_double)
562
560
  expect(features).to_not include(:vr)
563
561
  end
564
562
  end
565
563
 
566
564
  context "with no argument" do
567
565
  it "includes active feature" do
568
- features = @rollout.active_features
566
+ features = rollout.active_features
569
567
  expect(features).to include(:chat)
570
568
  end
571
569
 
572
570
  it "excludes inactive feature" do
573
- features = @rollout.active_features
571
+ features = rollout.active_features
574
572
  expect(features).to_not include(:video)
575
573
  end
576
574
  end
@@ -578,27 +576,27 @@ RSpec.describe "Rollout" do
578
576
 
579
577
  describe "#user_in_active_users?" do
580
578
  it "returns true if activated for user" do
581
- @rollout.activate_user(:chat, double(id: 5))
582
- expect(@rollout.user_in_active_users?(:chat, "5")).to eq(true)
579
+ rollout.activate_user(:chat, double(id: 5))
580
+ expect(rollout.user_in_active_users?(:chat, "5")).to eq(true)
583
581
  end
584
582
 
585
583
  it "returns false if activated for group" do
586
- @rollout.activate_group(:chat, :all)
587
- expect(@rollout.user_in_active_users?(:chat, "5")).to eq(false)
584
+ rollout.activate_group(:chat, :all)
585
+ expect(rollout.user_in_active_users?(:chat, "5")).to eq(false)
588
586
  end
589
587
  end
590
588
 
591
589
  describe "#multi_get" do
592
590
  before do
593
- @rollout.activate_percentage(:chat, 10)
594
- @rollout.activate_group(:chat, :caretakers)
595
- @rollout.activate_group(:videos, :greeters)
596
- @rollout.activate(:signup)
597
- @rollout.activate_user(:photos, double(id: 42))
591
+ rollout.activate_percentage(:chat, 10)
592
+ rollout.activate_group(:chat, :caretakers)
593
+ rollout.activate_group(:videos, :greeters)
594
+ rollout.activate(:signup)
595
+ rollout.activate_user(:photos, double(id: 42))
598
596
  end
599
597
 
600
598
  it "returns an array of features" do
601
- features = @rollout.multi_get(:chat, :videos, :signup)
599
+ features = rollout.multi_get(:chat, :videos, :signup)
602
600
  expect(features[0].name).to eq :chat
603
601
  expect(features[0].groups).to eq [:caretakers]
604
602
  expect(features[0].percentage).to eq 10
@@ -611,120 +609,69 @@ RSpec.describe "Rollout" do
611
609
 
612
610
  describe 'when given feature keys is empty' do
613
611
  it 'returns empty array' do
614
- expect(@rollout.multi_get(*[])).to match_array([])
612
+ expect(rollout.multi_get(*[])).to match_array([])
615
613
  end
616
614
  end
617
615
  end
618
616
 
619
617
  describe "#set_feature_data" do
620
618
  before do
621
- @rollout.set_feature_data(:chat, description: 'foo', release_date: 'bar')
619
+ rollout.set_feature_data(:chat, description: 'foo', release_date: 'bar')
622
620
  end
623
621
 
624
622
  it 'sets the data attribute on feature' do
625
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
623
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
626
624
  end
627
625
 
628
626
  it 'updates a data attribute' do
629
- @rollout.set_feature_data(:chat, description: 'baz')
630
- expect(@rollout.get(:chat).data).to include('description' => 'baz', 'release_date' => 'bar')
627
+ rollout.set_feature_data(:chat, description: 'baz')
628
+ expect(rollout.get(:chat).data).to include('description' => 'baz', 'release_date' => 'bar')
631
629
  end
632
630
 
633
631
  it 'only sets data on specified feature' do
634
- @rollout.set_feature_data(:talk, image_url: 'kittens.png')
635
- expect(@rollout.get(:chat).data).not_to include('image_url' => 'kittens.png')
636
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
632
+ rollout.set_feature_data(:talk, image_url: 'kittens.png')
633
+ expect(rollout.get(:chat).data).not_to include('image_url' => 'kittens.png')
634
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
637
635
  end
638
636
 
639
637
  it 'does not modify @data if param is nil' do
640
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
641
- @rollout.set_feature_data(:chat, nil)
642
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
638
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
639
+ rollout.set_feature_data(:chat, nil)
640
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
643
641
  end
644
642
 
645
643
  it 'does not modify @data if param is empty string' do
646
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
647
- @rollout.set_feature_data(:chat, " ")
648
- expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
644
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
645
+ rollout.set_feature_data(:chat, " ")
646
+ expect(rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
649
647
  end
650
648
 
651
649
  it 'properly parses data when it contains a |' do
652
650
  user = double("User", id: 8)
653
- @rollout.activate_user(:chat, user)
654
- @rollout.set_feature_data(:chat, "|call||text|" => "a|bunch|of|stuff")
655
- expect(@rollout.get(:chat).data).to include("|call||text|" => "a|bunch|of|stuff")
656
- expect(@rollout.active?(:chat, user)).to be true
651
+ rollout.activate_user(:chat, user)
652
+ rollout.set_feature_data(:chat, "|call||text|" => "a|bunch|of|stuff")
653
+ expect(rollout.get(:chat).data).to include("|call||text|" => "a|bunch|of|stuff")
654
+ expect(rollout.active?(:chat, user)).to be true
657
655
  end
658
656
  end
659
657
 
660
658
  describe "#clear_feature_data" do
661
659
  it 'resets data to empty string' do
662
- @rollout.set_feature_data(:chat, description: 'foo')
663
- expect(@rollout.get(:chat).data).to include('description' => 'foo')
664
- @rollout.clear_feature_data(:chat)
665
- expect(@rollout.get(:chat).data).to eq({})
660
+ rollout.set_feature_data(:chat, description: 'foo')
661
+ expect(rollout.get(:chat).data).to include('description' => 'foo')
662
+ rollout.clear_feature_data(:chat)
663
+ expect(rollout.get(:chat).data).to eq({})
666
664
  end
667
665
  end
668
666
 
669
667
  describe 'Check if feature exists' do
670
668
  it 'it should return true if the feature is exist' do
671
- @rollout.activate_percentage(:chat, 1)
672
- expect(@rollout.exists?(:chat)).to be true
669
+ rollout.activate_percentage(:chat, 1)
670
+ expect(rollout.exists?(:chat)).to be true
673
671
  end
674
672
 
675
673
  it 'it should return false if the feature is not exist' do
676
- expect(@rollout.exists?(:chat)).to be false
677
- end
678
- end
679
- end
680
-
681
- describe "Rollout::Feature" do
682
- describe "#add_user" do
683
- it "ids a user using id_user_by" do
684
- user = double("User", email: "test@test.com")
685
- feature = Rollout::Feature.new(:chat, nil, id_user_by: :email)
686
- feature.add_user(user)
687
- expect(user).to have_received :email
688
- end
689
- end
690
-
691
- describe "#initialize" do
692
- describe "when string does not exist" do
693
- it 'clears feature attributes when string is not given' do
694
- feature = Rollout::Feature.new(:chat)
695
- expect(feature.groups).to be_empty
696
- expect(feature.users).to be_empty
697
- expect(feature.percentage).to eq 0
698
- expect(feature.data).to eq({})
699
- end
700
-
701
- it 'clears feature attributes when string is nil' do
702
- feature = Rollout::Feature.new(:chat, nil)
703
- expect(feature.groups).to be_empty
704
- expect(feature.users).to be_empty
705
- expect(feature.percentage).to eq 0
706
- expect(feature.data).to eq({})
707
- end
708
-
709
- it 'clears feature attributes when string is empty string' do
710
- feature = Rollout::Feature.new(:chat, "")
711
- expect(feature.groups).to be_empty
712
- expect(feature.users).to be_empty
713
- expect(feature.percentage).to eq 0
714
- expect(feature.data).to eq({})
715
- end
716
-
717
- describe "when there is no data" do
718
- it 'sets @data to empty hash' do
719
- feature = Rollout::Feature.new(:chat, "0||")
720
- expect(feature.data).to eq({})
721
- end
722
-
723
- it 'sets @data to empty hash' do
724
- feature = Rollout::Feature.new(:chat, "||| ")
725
- expect(feature.data).to eq({})
726
- end
727
- end
674
+ expect(rollout.exists?(:chat)).to be false
728
675
  end
729
676
  end
730
677
  end