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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a5e004cc3855d75784fb6725f3593f7aef46bae
4
- data.tar.gz: 884592f7d393d1a5c0609b72ce2b3d43d6fb514a
3
+ metadata.gz: c219d83840f4a52ae52811bc0c803f2cb95d8faf
4
+ data.tar.gz: 24add236be0845a00b3e6bf7c612d4b7c4c1eee1
5
5
  SHA512:
6
- metadata.gz: 5b35e42099d1eea2f4e92f5a295dedcf04dcb1a3e49e0b923b02fe321569266fc86703a9c23d0a5d5cf454db1d15e968be650aa1c390cbabfb74f420a0eca567
7
- data.tar.gz: d2ccb3dcec40eecc47889db8ed08277b7b1fda33fafa45c1dc332045e874406a5b368a2cb72e9e408487c41f76e73660137b08d8650cfeed27f69db1a0f77301
6
+ metadata.gz: 71a6c8a7b1435b14d2c26c84a33bc4a30abc191cf6962e54933e1d828509701034af2c211925caf3ccc5477e3a9ef43e2c0680219eed85449b005562c479e05a
7
+ data.tar.gz: 070f411383393068498bef039dd214d2e9426c1b3b1f45cd1e665916bacdf8155b90b34d3db72364026d8a9af79f40bbdbe94c5843f331e41214e53ee025fdf8
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ablab
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ablab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Ongaro