ablab 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ablab.rb +14 -0
- data/lib/ablab/version.rb +1 -1
- data/spec/ablab_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c219d83840f4a52ae52811bc0c803f2cb95d8faf
|
4
|
+
data.tar.gz: 24add236be0845a00b3e6bf7c612d4b7c4c1eee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a6c8a7b1435b14d2c26c84a33bc4a30abc191cf6962e54933e1d828509701034af2c211925caf3ccc5477e3a9ef43e2c0680219eed85449b005562c479e05a
|
7
|
+
data.tar.gz: 070f411383393068498bef039dd214d2e9426c1b3b1f45cd1e665916bacdf8155b90b34d3db72364026d8a9af79f40bbdbe94c5843f331e41214e53ee025fdf8
|
data/lib/ablab.rb
CHANGED
@@ -121,6 +121,9 @@ module Ablab
|
|
121
121
|
|
122
122
|
def group
|
123
123
|
return @group unless @group.nil?
|
124
|
+
if forced = forced_group
|
125
|
+
return forced
|
126
|
+
end
|
124
127
|
size = 1000.0 * (experiment.percentage_of_visitors) / 100.0
|
125
128
|
idx = (draw * experiment.groups.size / size).floor
|
126
129
|
@group = experiment.groups[idx].try(:name)
|
@@ -140,6 +143,17 @@ module Ablab
|
|
140
143
|
cbk.call(event, experiment.name, group, session_id, request)
|
141
144
|
end
|
142
145
|
end
|
146
|
+
|
147
|
+
private def forced_group
|
148
|
+
return nil unless request && request.respond_to?(:params)
|
149
|
+
return nil unless forced = request.params[:ablab_group]
|
150
|
+
hash = forced.split(/\s*,\s*/).map do |s|
|
151
|
+
exp_group = s.split(/\s*:\s*/).take(2)
|
152
|
+
exp_group if exp_group.size == 2
|
153
|
+
end.compact.to_h
|
154
|
+
group = hash[experiment.name.to_s]
|
155
|
+
group.to_sym if group && experiment.groups.map { |g| g.name.to_s }.include?(group)
|
156
|
+
end
|
143
157
|
end
|
144
158
|
|
145
159
|
class Group
|
data/lib/ablab/version.rb
CHANGED
data/spec/ablab_spec.rb
CHANGED
@@ -217,6 +217,13 @@ describe Ablab do
|
|
217
217
|
it "returns one of the groups" do
|
218
218
|
expect(Ablab::Run.new(experiment, rand(12345).to_s, request).group).to be_in([:a, :b, :control])
|
219
219
|
end
|
220
|
+
|
221
|
+
it "returns the forced group, if set with the 'ablab_group' param" do
|
222
|
+
params = { ablab_group: 'bar:baz,foo:a' }
|
223
|
+
allow(request).to receive(:params).and_return(params)
|
224
|
+
run = Ablab::Run.new(experiment, '6q5wed', request)
|
225
|
+
expect(run.group).to eq(:a)
|
226
|
+
end
|
220
227
|
end
|
221
228
|
|
222
229
|
describe "#track_view!" do
|