rollout 2.0.0b → 2.0.0c
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rollout/version.rb +1 -1
- data/lib/rollout.rb +11 -10
- data/spec/rollout_spec.rb +36 -8
- metadata +14 -14
data/lib/rollout/version.rb
CHANGED
data/lib/rollout.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rollout/legacy"
|
2
|
+
require "zlib"
|
2
3
|
|
3
4
|
class Rollout
|
4
5
|
class Feature
|
@@ -10,7 +11,7 @@ class Rollout
|
|
10
11
|
if string
|
11
12
|
raw_percentage,raw_users,raw_groups = string.split("|")
|
12
13
|
@percentage = raw_percentage.to_i
|
13
|
-
@users = (raw_users || "").split(",").map(&:
|
14
|
+
@users = (raw_users || "").split(",").map(&:to_s)
|
14
15
|
@groups = (raw_groups || "").split(",").map(&:to_sym)
|
15
16
|
else
|
16
17
|
clear
|
@@ -22,15 +23,15 @@ class Rollout
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def add_user(user)
|
25
|
-
@users << user.id unless @users.include?(user.id)
|
26
|
+
@users << user.id.to_s unless @users.include?(user.id.to_s)
|
26
27
|
end
|
27
28
|
|
28
29
|
def remove_user(user)
|
29
|
-
@users.delete(user.id.
|
30
|
+
@users.delete(user.id.to_s)
|
30
31
|
end
|
31
32
|
|
32
33
|
def add_group(group)
|
33
|
-
@groups << group unless @groups.include?(group)
|
34
|
+
@groups << group.to_sym unless @groups.include?(group.to_sym)
|
34
35
|
end
|
35
36
|
|
36
37
|
def remove_group(group)
|
@@ -61,11 +62,11 @@ class Rollout
|
|
61
62
|
|
62
63
|
private
|
63
64
|
def user_in_percentage?(user)
|
64
|
-
user.id % 100 < @percentage
|
65
|
+
Zlib.crc32(user.id.to_s) % 100 < @percentage
|
65
66
|
end
|
66
67
|
|
67
68
|
def user_in_active_users?(user)
|
68
|
-
@users.include?(user.id)
|
69
|
+
@users.include?(user.id.to_s)
|
69
70
|
end
|
70
71
|
|
71
72
|
def user_in_active_group?(user, rollout)
|
@@ -118,7 +119,7 @@ class Rollout
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def define_group(group, &block)
|
121
|
-
@groups[group] = block
|
122
|
+
@groups[group.to_sym] = block
|
122
123
|
end
|
123
124
|
|
124
125
|
def active?(feature, user = nil)
|
@@ -139,7 +140,7 @@ class Rollout
|
|
139
140
|
end
|
140
141
|
|
141
142
|
def active_in_group?(group, user)
|
142
|
-
f = @groups[group]
|
143
|
+
f = @groups[group.to_sym]
|
143
144
|
f && f.call(user)
|
144
145
|
end
|
145
146
|
|
@@ -151,8 +152,8 @@ class Rollout
|
|
151
152
|
info = @legacy.info(feature)
|
152
153
|
f = Feature.new(feature)
|
153
154
|
f.percentage = info[:percentage]
|
154
|
-
f.groups = info[:groups]
|
155
|
-
f.users = info[:users]
|
155
|
+
f.groups = info[:groups].map { |g| g.to_sym }
|
156
|
+
f.users = info[:users].map { |u| u.to_s }
|
156
157
|
save(f)
|
157
158
|
f
|
158
159
|
end
|
data/spec/rollout_spec.rb
CHANGED
@@ -97,6 +97,20 @@ describe "Rollout" do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
describe "activating a specific user with a string id" do
|
101
|
+
before do
|
102
|
+
@rollout.activate_user(:chat, stub(:id => 'user-72'))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "is active for that user" do
|
106
|
+
@rollout.should be_active(:chat, stub(:id => 'user-72'))
|
107
|
+
end
|
108
|
+
|
109
|
+
it "remains inactive for other users" do
|
110
|
+
@rollout.should_not be_active(:chat, stub(:id => 'user-12'))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
100
114
|
describe "deactivating a specific user" do
|
101
115
|
before do
|
102
116
|
@rollout.activate_user(:chat, stub(:id => 42))
|
@@ -111,7 +125,7 @@ describe "Rollout" do
|
|
111
125
|
end
|
112
126
|
|
113
127
|
it "remains active for other active users" do
|
114
|
-
@rollout.get(:chat).users.should ==
|
128
|
+
@rollout.get(:chat).users.should == %w(24)
|
115
129
|
end
|
116
130
|
end
|
117
131
|
|
@@ -131,7 +145,7 @@ describe "Rollout" do
|
|
131
145
|
end
|
132
146
|
|
133
147
|
it "activates the feature for that percentage of the users" do
|
134
|
-
(1..120).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should
|
148
|
+
(1..120).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should be_within(1).of(20)
|
135
149
|
end
|
136
150
|
end
|
137
151
|
|
@@ -141,7 +155,7 @@ describe "Rollout" do
|
|
141
155
|
end
|
142
156
|
|
143
157
|
it "activates the feature for that percentage of the users" do
|
144
|
-
(1..200).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should
|
158
|
+
(1..200).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should be_within(5).of(40)
|
145
159
|
end
|
146
160
|
end
|
147
161
|
|
@@ -151,10 +165,24 @@ describe "Rollout" do
|
|
151
165
|
end
|
152
166
|
|
153
167
|
it "activates the feature for that percentage of the users" do
|
154
|
-
(1..100).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should
|
168
|
+
(1..100).select { |id| @rollout.active?(:chat, stub(:id => id)) }.length.should be_within(2).of(5)
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
172
|
+
describe "activating a feature for a group as a string" do
|
173
|
+
before do
|
174
|
+
@rollout.define_group(:admins) { |user| user.id == 5 }
|
175
|
+
@rollout.activate_group(:chat, 'admins')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "the feature is active for users for which the block evaluates to true" do
|
179
|
+
@rollout.should be_active(:chat, stub(:id => 5))
|
180
|
+
end
|
181
|
+
|
182
|
+
it "is not active for users for which the block evaluates to false" do
|
183
|
+
@rollout.should_not be_active(:chat, stub(:id => 1))
|
184
|
+
end
|
185
|
+
end
|
158
186
|
|
159
187
|
describe "deactivating the percentage of users" do
|
160
188
|
before do
|
@@ -196,11 +224,11 @@ describe "Rollout" do
|
|
196
224
|
feature = @rollout.get(:chat)
|
197
225
|
feature.groups.should == [:caretakers, :greeters]
|
198
226
|
feature.percentage.should == 10
|
199
|
-
feature.users.should ==
|
227
|
+
feature.users.should == %w(42)
|
200
228
|
feature.to_hash.should == {
|
201
229
|
:groups => [:caretakers, :greeters],
|
202
230
|
:percentage => 10,
|
203
|
-
:users =>
|
231
|
+
:users => %w(42)
|
204
232
|
}
|
205
233
|
|
206
234
|
feature = @rollout.get(:signup)
|
@@ -223,13 +251,13 @@ describe "Rollout" do
|
|
223
251
|
it "imports the settings from the legacy rollout once" do
|
224
252
|
@rollout.get(:chat).to_hash.should == {
|
225
253
|
:percentage => 12,
|
226
|
-
:users =>
|
254
|
+
:users => %w(24 42),
|
227
255
|
:groups => [:dope_people]
|
228
256
|
}
|
229
257
|
@legacy.deactivate_all(:chat)
|
230
258
|
@rollout.get(:chat).to_hash.should == {
|
231
259
|
:percentage => 12,
|
232
|
-
:users =>
|
260
|
+
:users => %w(24 42),
|
233
261
|
:groups => [:dope_people]
|
234
262
|
}
|
235
263
|
@redis.get("feature:chat").should_not be_nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.0c
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70164526697800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.10.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70164526697800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70164526697160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70164526697160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70164526696700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70164526696700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bourne
|
49
|
-
requirement: &
|
49
|
+
requirement: &70164526696240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70164526696240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70164526695780 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.9.8
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70164526695780
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: redis
|
71
|
-
requirement: &
|
71
|
+
requirement: &70164526695380 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70164526695380
|
80
80
|
description: Feature flippers with redis.
|
81
81
|
email:
|
82
82
|
- jamesgolick@gmail.com
|