split 4.0.0.pre → 4.0.0.pre2

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
  SHA256:
3
- metadata.gz: 1a8ee5e18e49d1020baf846f2e2403d9f54705c551690335e4898c43cffb93b9
4
- data.tar.gz: 84db3159654293b4cda8905138f9bb0dbb0b8ba4e130580eb6758d74e3d70873
3
+ metadata.gz: 8bc6c9cfc3470eb28463fe0d286124b8ad89132e458963cfea9035f82d2dc484
4
+ data.tar.gz: 5cacccff1115b056ecafcea231ea27fff5d564ee9630b4279d8ce1fa5d8282ca
5
5
  SHA512:
6
- metadata.gz: 846c82ad7655d028ab719c85d3bc1589453f55adbc0bae011f1b4f4c28d478f121dc1905b3d4b5d81a39b7884d5e7c20ba7d06bf6bdb7d5216b5b07974587031
7
- data.tar.gz: ca6166dc4dec2102ba82c80f4cb73308a9b4e87785276f4bb63ef5e702b55e2cc71146a537fd1306005aad2f77916c096484812f85bc90887400ca280a73a4b1
6
+ metadata.gz: bca228077d8dbecf7e06f21f411070effcc520c64d09b055c41fea4da7d786bedb81dbdd4f389a20f9166e08d9abf26ff75ea60bd1daf43c2555f5621adbb1e0
7
+ data.tar.gz: ad2aca522d8d7f7bad54ee256c8626dd7747ae6c65aaf6da40d0de4c56d78f2bddd34af4c22be9d9fc943538446e523bf1f6ae7bf43e59505eddd350507b168d
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,61 @@
1
+ name: split
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ matrix:
9
+ include:
10
+ - gemfile: 5.2.gemfile
11
+ ruby: 2.5
12
+
13
+ - gemfile: 5.2.gemfile
14
+ ruby: 2.6
15
+
16
+ - gemfile: 5.2.gemfile
17
+ ruby: 2.7
18
+
19
+ - gemfile: 6.0.gemfile
20
+ ruby: 2.5
21
+
22
+ - gemfile: 6.0.gemfile
23
+ ruby: 2.6
24
+
25
+ - gemfile: 6.0.gemfile
26
+ ruby: 2.7
27
+
28
+ - gemfile: 6.0.gemfile
29
+ ruby: '3.0'
30
+
31
+ runs-on: ubuntu-latest
32
+
33
+ services:
34
+ redis:
35
+ image: redis
36
+ ports: ['6379:6379']
37
+ options: >-
38
+ --health-cmd "redis-cli ping"
39
+ --health-interval 10s
40
+ --health-timeout 5s
41
+ --health-retries 5
42
+
43
+ steps:
44
+ - uses: actions/checkout@v2
45
+
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+
50
+ - name: Install dependencies
51
+ run: |
52
+ bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/${{ matrix.gemfile }}"
53
+ bundle install --jobs 4 --retry 3
54
+
55
+ - name: Display Ruby version
56
+ run: ruby -v
57
+
58
+ - name: Test
59
+ run: bundle exec rspec
60
+ env:
61
+ REDIS_URL: redis:6379
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 4.0.0.pre
1
+ ## 4.0.0.pre2
2
2
 
3
3
  Bugfixes:
4
4
  - ab_test must return metadata on error or if split is disabled/excluded user (@andrehjr, #622)
@@ -6,6 +6,8 @@ Bugfixes:
6
6
  - Only block Pinterest bot (@huoxito, #606)
7
7
  - Respect experiment defaults when loading experiments in initializer. (@mattwd7, #599)
8
8
  - Removes metadata key when it updated to nil (@andrehjr, #633)
9
+ - Force experiment does not count for metrics (@andrehjr, #637)
10
+ - Fix cleanup_old_versions! misbehaviour (@serggi, #661)
9
11
 
10
12
  Features:
11
13
  - Make goals accessible via on_trial_complete callbacks (@robin-phung, #625)
@@ -14,10 +16,11 @@ Features:
14
16
  - Add on_experiment_winner_choose callback (@GenaMinenkov, #574)
15
17
  - Add Split::Cache to reduce load on Redis (@rdh, #648)
16
18
  - Caching based optimization in the experiment#save path (@amangup, #652)
19
+ - Adds config option for cookie domain (@joedelia, #664)
17
20
 
18
21
  Misc:
19
22
  - Drop support for Ruby < 2.5 (@andrehjr, #627)
20
- - Drop support for Rails < 5 (@andrehkr, #607)
23
+ - Drop support for Rails < 5 (@andrehjr, #607)
21
24
  - Bump minimum required redis to 4.2 (@andrehjr, #628)
22
25
  - Removed repeated loading from config (@robin-phung, #619)
23
26
  - Simplify RedisInterface usage when persisting Experiment alternatives (@andrehjr, #632)
@@ -25,8 +28,10 @@ Misc:
25
28
  - Remove thread_safe config as redis-rb is thread_safe by default (@andrehjr, #630)
26
29
  - Fix typo of in `Split::Trial` class variable (TomasBarry, #644)
27
30
  - Single HSET to update values, instead of multiple ones (@andrehjr, #640)
31
+ - Use Redis#hmset to keep compatibility with Redis < 4.0 (@andrehjr, #659)
28
32
  - Remove 'set' parsing for alternatives. Sets were used as storage and deprecated on 0.x (@andrehjr, #639)
29
33
  - Adding documentation related to what is stored on cookies. (@andrehjr, #634)
34
+ - Keep railtie defined under the Split gem namespace (@avit, #666)
30
35
 
31
36
  ## 3.4.1 (November 12th, 2019)
32
37
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # [Split](https://libraries.io/rubygems/split)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/split.svg)](http://badge.fury.io/rb/split)
4
- [![Build Status](https://secure.travis-ci.org/splitrb/split.svg?branch=master)](https://travis-ci.org/splitrb/split)
4
+ ![Build status](https://github.com/splitrb/split/actions/workflows/ci.yml/badge.svg?branch=main)
5
5
  [![Code Climate](https://codeclimate.com/github/splitrb/split/badges/gpa.svg)](https://codeclimate.com/github/splitrb/split)
6
6
  [![Test Coverage](https://codeclimate.com/github/splitrb/split/badges/coverage.svg)](https://codeclimate.com/github/splitrb/split/coverage)
7
7
  [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
@@ -175,8 +175,10 @@ module SplitHelper
175
175
  # use_ab_test(signup_form: "single_page", pricing: "show_enterprise_prices")
176
176
  #
177
177
  def use_ab_test(alternatives_by_experiment)
178
- allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment|
179
- alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
178
+ allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment, &block|
179
+ variant = alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
180
+ block.call(variant) unless block.nil?
181
+ variant
180
182
  end
181
183
  end
182
184
  end
@@ -648,7 +650,7 @@ The API to define goals for an experiment is this:
648
650
  ab_test({link_color: ["purchase", "refund"]}, "red", "blue")
649
651
  ```
650
652
 
651
- or you can you can define them in a configuration file:
653
+ or you can define them in a configuration file:
652
654
 
653
655
  ```ruby
654
656
  Split.configure do |config|
@@ -786,7 +788,7 @@ library. To configure Split to use `Redis::Namespace`, do the following:
786
788
  ```
787
789
 
788
790
  2. Configure `Split.redis` to use a `Redis::Namespace` instance (possible in an
789
- intializer):
791
+ initializer):
790
792
 
791
793
  ```ruby
792
794
  redis = Redis.new(url: ENV['REDIS_URL']) # or whatever config you want
@@ -11,6 +11,7 @@ module Split
11
11
  attr_accessor :enabled
12
12
  attr_accessor :persistence
13
13
  attr_accessor :persistence_cookie_length
14
+ attr_accessor :persistence_cookie_domain
14
15
  attr_accessor :algorithm
15
16
  attr_accessor :store_override
16
17
  attr_accessor :start_manually
@@ -226,6 +227,7 @@ module Split
226
227
  @experiments = {}
227
228
  @persistence = Split::Persistence::SessionAdapter
228
229
  @persistence_cookie_length = 31536000 # One year from now
230
+ @persistence_cookie_domain = nil
229
231
  @algorithm = Split::Algorithms::WeightedSample
230
232
  @include_rails_helper = true
231
233
  @beta_probability_simulations = 10000
@@ -87,8 +87,8 @@ module Split
87
87
  persist_experiment_configuration
88
88
  end
89
89
 
90
- redis.hset(experiment_config_key, :resettable, resettable,
91
- :algorithm, algorithm.to_s)
90
+ redis.hmset(experiment_config_key, :resettable, resettable,
91
+ :algorithm, algorithm.to_s)
92
92
  self
93
93
  end
94
94
 
@@ -45,7 +45,7 @@ module Split
45
45
  end
46
46
 
47
47
  def default_options
48
- { expires: @expires, path: '/' }
48
+ { expires: @expires, path: '/', domain: cookie_domain_config }.compact
49
49
  end
50
50
 
51
51
  def set_cookie_via_rack(key, value)
@@ -87,6 +87,10 @@ module Split
87
87
  Split.configuration.persistence_cookie_length
88
88
  end
89
89
 
90
+ def cookie_domain_config
91
+ Split.configuration.persistence_cookie_domain
92
+ end
93
+
90
94
  def action_dispatch?
91
95
  defined?(Rails) && @response.is_a?(ActionDispatch::Response)
92
96
  end
data/lib/split/user.rb CHANGED
@@ -38,7 +38,7 @@ module Split
38
38
  end
39
39
 
40
40
  def cleanup_old_versions!(experiment)
41
- keys = user.keys.select { |k| k.match(Regexp.new(experiment.name)) }
41
+ keys = user.keys.select { |k| key_without_version(k) == experiment.name }
42
42
  keys_without_experiment(keys, experiment.key).each { |key| user.delete(key) }
43
43
  end
44
44
 
data/lib/split/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Split
4
- VERSION = "4.0.0.pre"
4
+ VERSION = "4.0.0.pre2"
5
5
  end
data/lib/split.rb CHANGED
@@ -74,7 +74,7 @@ end
74
74
 
75
75
  # Check to see if being run in a Rails application. If so, wait until before_initialize to run configuration so Gems that create ENV variables have the chance to initialize first.
76
76
  if defined?(::Rails)
77
- class Railtie < Rails::Railtie
77
+ class Split::Railtie < Rails::Railtie
78
78
  config.before_initialize { Split.configure {} }
79
79
  end
80
80
  else
@@ -214,7 +214,10 @@ describe Split::Configuration do
214
214
 
215
215
  context "redis configuration" do
216
216
  it "should default to local redis server" do
217
- expect(@config.redis).to eq("redis://localhost:6379")
217
+ old_redis_url = ENV['REDIS_URL']
218
+ ENV.delete('REDIS_URL')
219
+ expect(Split::Configuration.new.redis).to eq("redis://localhost:6379")
220
+ ENV['REDIS_URL'] = old_redis_url
218
221
  end
219
222
 
220
223
  it "should allow for redis url to be configured" do
@@ -224,9 +227,10 @@ describe Split::Configuration do
224
227
 
225
228
  context "provided REDIS_URL environment variable" do
226
229
  it "should use the ENV variable" do
230
+ old_redis_url = ENV['REDIS_URL']
227
231
  ENV['REDIS_URL'] = "env_redis_url"
228
232
  expect(Split::Configuration.new.redis).to eq("env_redis_url")
229
- ENV.delete('REDIS_URL')
233
+ ENV['REDIS_URL'] = old_redis_url
230
234
  end
231
235
  end
232
236
  end
@@ -242,4 +246,15 @@ describe Split::Configuration do
242
246
  end
243
247
  end
244
248
 
249
+ context "persistence cookie domain" do
250
+ it "should default to nil" do
251
+ expect(@config.persistence_cookie_domain).to eq(nil)
252
+ end
253
+
254
+ it "should allow the persistence cookie domain to be configured" do
255
+ @config.persistence_cookie_domain = '.acme.com'
256
+ expect(@config.persistence_cookie_domain).to eq('.acme.com')
257
+ end
258
+ end
259
+
245
260
  end
data/spec/user_spec.rb CHANGED
@@ -17,11 +17,25 @@ describe Split::User do
17
17
  end
18
18
 
19
19
  context '#cleanup_old_versions!' do
20
- let(:user_keys) { { 'link_color:1' => 'blue' } }
20
+ let(:experiment_version) { "#{experiment.name}:1" }
21
+ let(:second_experiment_version) { "#{experiment.name}_another:1" }
22
+ let(:third_experiment_version) { "variation_of_#{experiment.name}:1" }
23
+ let(:user_keys) do
24
+ {
25
+ experiment_version => 'blue',
26
+ second_experiment_version => 'red',
27
+ third_experiment_version => 'yellow'
28
+ }
29
+ end
30
+
31
+ before(:each) { @subject.cleanup_old_versions!(experiment) }
21
32
 
22
33
  it 'removes key if old experiment is found' do
23
- @subject.cleanup_old_versions!(experiment)
24
- expect(@subject.keys).to be_empty
34
+ expect(@subject.keys).not_to include(experiment_version)
35
+ end
36
+
37
+ it 'does not remove other keys' do
38
+ expect(@subject.keys).to include(second_experiment_version, third_experiment_version)
25
39
  end
26
40
  end
27
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.pre
4
+ version: 4.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -163,11 +163,12 @@ files:
163
163
  - ".eslintrc"
164
164
  - ".github/FUNDING.yml"
165
165
  - ".github/ISSUE_TEMPLATE/bug_report.md"
166
+ - ".github/dependabot.yml"
167
+ - ".github/workflows/ci.yml"
166
168
  - ".gitignore"
167
169
  - ".rspec"
168
170
  - ".rubocop.yml"
169
171
  - ".rubocop_todo.yml"
170
- - ".travis.yml"
171
172
  - Appraisals
172
173
  - CHANGELOG.md
173
174
  - CODE_OF_CONDUCT.md
data/.travis.yml DELETED
@@ -1,32 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5.7
4
- - 2.6.6
5
- - 2.7.1
6
-
7
- services:
8
- - redis-server
9
-
10
- gemfile:
11
- - gemfiles/5.0.gemfile
12
- - gemfiles/5.1.gemfile
13
- - gemfiles/5.2.gemfile
14
- - gemfiles/6.0.gemfile
15
-
16
- before_install:
17
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
18
- - gem install bundler --version=1.17.3
19
-
20
- before_script:
21
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
- - chmod +x ./cc-test-reporter
23
- - ./cc-test-reporter before-build
24
-
25
- script:
26
- - RAILS_ENV=test bundle exec rake spec
27
-
28
- after_script:
29
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
30
-
31
- cache: bundler
32
- sudo: false