split 4.0.0.pre2 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +14 -1
- data/.rubocop.yml +2 -5
- data/CHANGELOG.md +26 -2
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +2 -1
- data/README.md +4 -2
- data/Rakefile +4 -5
- data/gemfiles/5.2.gemfile +1 -3
- data/gemfiles/6.0.gemfile +1 -3
- data/gemfiles/{5.0.gemfile → 6.1.gemfile} +2 -4
- data/gemfiles/{5.1.gemfile → 7.0.gemfile} +3 -4
- data/lib/split/algorithms/block_randomization.rb +5 -6
- data/lib/split/algorithms/whiplash.rb +16 -18
- data/lib/split/algorithms.rb +22 -0
- data/lib/split/alternative.rb +21 -22
- data/lib/split/cache.rb +0 -1
- data/lib/split/combined_experiments_helper.rb +4 -4
- data/lib/split/configuration.rb +83 -84
- data/lib/split/dashboard/helpers.rb +6 -7
- data/lib/split/dashboard/pagination_helpers.rb +53 -54
- data/lib/split/dashboard/public/style.css +5 -2
- data/lib/split/dashboard/views/index.erb +19 -4
- data/lib/split/dashboard.rb +29 -23
- data/lib/split/encapsulated_helper.rb +4 -6
- data/lib/split/experiment.rb +84 -88
- data/lib/split/experiment_catalog.rb +6 -5
- data/lib/split/extensions/string.rb +1 -1
- data/lib/split/goals_collection.rb +8 -10
- data/lib/split/helper.rb +19 -19
- data/lib/split/metric.rb +4 -5
- data/lib/split/persistence/cookie_adapter.rb +44 -47
- data/lib/split/persistence/dual_adapter.rb +7 -8
- data/lib/split/persistence/redis_adapter.rb +2 -3
- data/lib/split/persistence/session_adapter.rb +0 -2
- data/lib/split/persistence.rb +4 -4
- data/lib/split/redis_interface.rb +1 -2
- data/lib/split/trial.rb +23 -24
- data/lib/split/user.rb +12 -13
- data/lib/split/version.rb +1 -1
- data/lib/split/zscore.rb +1 -3
- data/lib/split.rb +26 -25
- data/spec/algorithms/block_randomization_spec.rb +6 -5
- data/spec/algorithms/weighted_sample_spec.rb +6 -5
- data/spec/algorithms/whiplash_spec.rb +4 -5
- data/spec/alternative_spec.rb +35 -36
- data/spec/cache_spec.rb +15 -19
- data/spec/combined_experiments_helper_spec.rb +18 -17
- data/spec/configuration_spec.rb +32 -38
- data/spec/dashboard/pagination_helpers_spec.rb +69 -67
- data/spec/dashboard/paginator_spec.rb +10 -9
- data/spec/dashboard_helpers_spec.rb +19 -18
- data/spec/dashboard_spec.rb +67 -35
- data/spec/encapsulated_helper_spec.rb +12 -14
- data/spec/experiment_catalog_spec.rb +14 -13
- data/spec/experiment_spec.rb +121 -123
- data/spec/goals_collection_spec.rb +17 -15
- data/spec/helper_spec.rb +379 -382
- data/spec/metric_spec.rb +14 -14
- data/spec/persistence/cookie_adapter_spec.rb +23 -8
- data/spec/persistence/dual_adapter_spec.rb +71 -71
- data/spec/persistence/redis_adapter_spec.rb +25 -26
- data/spec/persistence/session_adapter_spec.rb +2 -3
- data/spec/persistence_spec.rb +1 -2
- data/spec/redis_interface_spec.rb +16 -14
- data/spec/spec_helper.rb +15 -13
- data/spec/split_spec.rb +11 -11
- data/spec/support/cookies_mock.rb +1 -2
- data/spec/trial_spec.rb +61 -60
- data/spec/user_spec.rb +36 -36
- data/split.gemspec +20 -20
- metadata +9 -10
- data/.rubocop_todo.yml +0 -226
- data/Appraisals +0 -19
@@ -1,57 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "split/combined_experiments_helper"
|
4
5
|
|
5
6
|
describe Split::CombinedExperimentsHelper do
|
6
7
|
include Split::CombinedExperimentsHelper
|
7
8
|
|
8
|
-
describe
|
9
|
+
describe "ab_combined_test" do
|
9
10
|
let!(:config_enabled) { true }
|
10
|
-
let!(:combined_experiments) { [:exp_1_click, :exp_1_scroll ]}
|
11
|
+
let!(:combined_experiments) { [:exp_1_click, :exp_1_scroll ] }
|
11
12
|
let!(:allow_multiple_experiments) { true }
|
12
13
|
|
13
14
|
before do
|
14
15
|
Split.configuration.experiments = {
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
16
|
+
combined_exp_1: {
|
17
|
+
alternatives: [ { "control"=> 0.5 }, { "test-alt"=> 0.5 } ],
|
18
|
+
metric: :my_metric,
|
19
|
+
combined_experiments: combined_experiments
|
19
20
|
}
|
20
21
|
}
|
21
22
|
Split.configuration.enabled = config_enabled
|
22
23
|
Split.configuration.allow_multiple_experiments = allow_multiple_experiments
|
23
24
|
end
|
24
25
|
|
25
|
-
context
|
26
|
+
context "without config enabled" do
|
26
27
|
let!(:config_enabled) { false }
|
27
28
|
|
28
29
|
it "raises an error" do
|
29
|
-
expect
|
30
|
+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
context
|
34
|
+
context "multiple experiments disabled" do
|
34
35
|
let!(:allow_multiple_experiments) { false }
|
35
36
|
|
36
37
|
it "raises an error if multiple experiments is disabled" do
|
37
|
-
expect
|
38
|
+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
+
context "without combined experiments" do
|
42
43
|
let!(:combined_experiments) { nil }
|
43
44
|
|
44
45
|
it "raises an error" do
|
45
|
-
expect
|
46
|
+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
50
|
it "uses same alternative for all sub experiments and returns the alternative" do
|
50
51
|
allow(self).to receive(:get_alternative) { "test-alt" }
|
51
|
-
expect(self).to receive(:ab_test).with(:exp_1_click, {"control"=>0.5}, {"test-alt"=>0.5}) { "test-alt" }
|
52
|
-
expect(self).to receive(:ab_test).with(:exp_1_scroll, [{"control" => 0, "test-alt" => 1}])
|
52
|
+
expect(self).to receive(:ab_test).with(:exp_1_click, { "control"=>0.5 }, { "test-alt"=>0.5 }) { "test-alt" }
|
53
|
+
expect(self).to receive(:ab_test).with(:exp_1_scroll, [{ "control" => 0, "test-alt" => 1 }])
|
53
54
|
|
54
|
-
expect(ab_combined_test(
|
55
|
+
expect(ab_combined_test("combined_exp_1")).to eq("test-alt")
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Split::Configuration do
|
6
6
|
before(:each) { @config = Split::Configuration.new }
|
7
7
|
|
8
8
|
it "should provide a default value for ignore_ip_addresses" do
|
@@ -58,17 +58,15 @@ describe Split::Configuration do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should load a metric" do
|
61
|
-
@config.experiments = {:
|
62
|
-
{:alternatives=>["control_opt", "other_opt"], :metric=>:my_metric}}
|
61
|
+
@config.experiments = { my_experiment: { alternatives: ["control_opt", "other_opt"], metric: :my_metric } }
|
63
62
|
|
64
63
|
expect(@config.metrics).not_to be_nil
|
65
64
|
expect(@config.metrics.keys).to eq([:my_metric])
|
66
65
|
end
|
67
66
|
|
68
67
|
it "should allow loading of experiment using experment_for" do
|
69
|
-
@config.experiments = {:
|
70
|
-
|
71
|
-
expect(@config.experiment_for(:my_experiment)).to eq({:alternatives=>["control_opt", ["other_opt"]]})
|
68
|
+
@config.experiments = { my_experiment: { alternatives: ["control_opt", "other_opt"], metric: :my_metric } }
|
69
|
+
expect(@config.experiment_for(:my_experiment)).to eq({ alternatives: ["control_opt", ["other_opt"]] })
|
72
70
|
end
|
73
71
|
|
74
72
|
context "when experiments are defined via YAML" do
|
@@ -82,12 +80,12 @@ describe Split::Configuration do
|
|
82
80
|
- Alt One
|
83
81
|
- Alt Two
|
84
82
|
resettable: false
|
85
|
-
|
83
|
+
eos
|
86
84
|
@config.experiments = YAML.load(experiments_yaml)
|
87
85
|
end
|
88
86
|
|
89
|
-
it
|
90
|
-
expect(@config.normalized_experiments).to eq({:
|
87
|
+
it "should normalize experiments" do
|
88
|
+
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: ["Control Opt", ["Alt One", "Alt Two"]] } })
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
@@ -110,14 +108,14 @@ describe Split::Configuration do
|
|
110
108
|
Alt Two:
|
111
109
|
text: 'Alternative Two'
|
112
110
|
resettable: false
|
113
|
-
|
111
|
+
eos
|
114
112
|
@config.experiments = YAML.load(experiments_yaml)
|
115
113
|
end
|
116
114
|
|
117
|
-
it
|
115
|
+
it "should have metadata on the experiment" do
|
118
116
|
meta = @config.normalized_experiments[:my_experiment][:metadata]
|
119
117
|
expect(meta).to_not be nil
|
120
|
-
expect(meta[
|
118
|
+
expect(meta["Control Opt"]["text"]).to eq("Control Option")
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
@@ -138,25 +136,23 @@ describe Split::Configuration do
|
|
138
136
|
alternatives:
|
139
137
|
- a
|
140
138
|
- b
|
141
|
-
|
139
|
+
eos
|
142
140
|
@config.experiments = YAML.load(experiments_yaml)
|
143
141
|
end
|
144
142
|
|
145
143
|
it "should normalize experiments" do
|
146
|
-
expect(@config.normalized_experiments).to eq({:
|
147
|
-
[{"Alt One"=>0.1}, {"Alt Two"=>0.23}]]}, :
|
144
|
+
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: [{ "Control Opt"=>0.67 },
|
145
|
+
[{ "Alt One"=>0.1 }, { "Alt Two"=>0.23 }]] }, another_experiment: { alternatives: ["a", ["b"]] } })
|
148
146
|
end
|
149
147
|
|
150
148
|
it "should recognize metrics" do
|
151
149
|
expect(@config.metrics).not_to be_nil
|
152
150
|
expect(@config.metrics.keys).to eq([:my_metric])
|
153
151
|
end
|
154
|
-
|
155
152
|
end
|
156
153
|
end
|
157
154
|
|
158
155
|
context "as symbols" do
|
159
|
-
|
160
156
|
context "with valid YAML" do
|
161
157
|
before do
|
162
158
|
experiments_yaml = <<-eos
|
@@ -166,21 +162,20 @@ describe Split::Configuration do
|
|
166
162
|
- Alt One
|
167
163
|
- Alt Two
|
168
164
|
:resettable: false
|
169
|
-
|
165
|
+
eos
|
170
166
|
@config.experiments = YAML.load(experiments_yaml)
|
171
167
|
end
|
172
168
|
|
173
169
|
it "should normalize experiments" do
|
174
|
-
expect(@config.normalized_experiments).to eq({:
|
170
|
+
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: ["Control Opt", ["Alt One", "Alt Two"]] } })
|
175
171
|
end
|
176
172
|
end
|
177
173
|
|
178
174
|
context "with invalid YAML" do
|
179
|
-
|
180
175
|
let(:yaml) { YAML.load(input) }
|
181
176
|
|
182
177
|
context "with an empty string" do
|
183
|
-
let(:input) {
|
178
|
+
let(:input) { "" }
|
184
179
|
|
185
180
|
it "should raise an error" do
|
186
181
|
expect { @config.experiments = yaml }.to raise_error(Split::InvalidExperimentsFormatError)
|
@@ -188,7 +183,7 @@ describe Split::Configuration do
|
|
188
183
|
end
|
189
184
|
|
190
185
|
context "with just the YAML header" do
|
191
|
-
let(:input) {
|
186
|
+
let(:input) { "---" }
|
192
187
|
|
193
188
|
it "should raise an error" do
|
194
189
|
expect { @config.experiments = yaml }.to raise_error(Split::InvalidExperimentsFormatError)
|
@@ -200,24 +195,24 @@ describe Split::Configuration do
|
|
200
195
|
|
201
196
|
it "should normalize experiments" do
|
202
197
|
@config.experiments = {
|
203
|
-
:
|
204
|
-
:
|
205
|
-
{ :
|
206
|
-
{ :
|
207
|
-
{ :
|
198
|
+
my_experiment: {
|
199
|
+
alternatives: [
|
200
|
+
{ name: "control_opt", percent: 67 },
|
201
|
+
{ name: "second_opt", percent: 10 },
|
202
|
+
{ name: "third_opt", percent: 23 },
|
208
203
|
],
|
209
204
|
}
|
210
205
|
}
|
211
206
|
|
212
|
-
expect(@config.normalized_experiments).to eq({:
|
207
|
+
expect(@config.normalized_experiments).to eq({ my_experiment: { alternatives: [{ "control_opt"=>0.67 }, [{ "second_opt"=>0.1 }, { "third_opt"=>0.23 }]] } })
|
213
208
|
end
|
214
209
|
|
215
210
|
context "redis configuration" do
|
216
211
|
it "should default to local redis server" do
|
217
|
-
old_redis_url = ENV[
|
218
|
-
ENV.delete(
|
212
|
+
old_redis_url = ENV["REDIS_URL"]
|
213
|
+
ENV.delete("REDIS_URL")
|
219
214
|
expect(Split::Configuration.new.redis).to eq("redis://localhost:6379")
|
220
|
-
ENV[
|
215
|
+
ENV["REDIS_URL"] = old_redis_url
|
221
216
|
end
|
222
217
|
|
223
218
|
it "should allow for redis url to be configured" do
|
@@ -227,10 +222,10 @@ describe Split::Configuration do
|
|
227
222
|
|
228
223
|
context "provided REDIS_URL environment variable" do
|
229
224
|
it "should use the ENV variable" do
|
230
|
-
old_redis_url = ENV[
|
231
|
-
ENV[
|
225
|
+
old_redis_url = ENV["REDIS_URL"]
|
226
|
+
ENV["REDIS_URL"] = "env_redis_url"
|
232
227
|
expect(Split::Configuration.new.redis).to eq("env_redis_url")
|
233
|
-
ENV[
|
228
|
+
ENV["REDIS_URL"] = old_redis_url
|
234
229
|
end
|
235
230
|
end
|
236
231
|
end
|
@@ -252,9 +247,8 @@ describe Split::Configuration do
|
|
252
247
|
end
|
253
248
|
|
254
249
|
it "should allow the persistence cookie domain to be configured" do
|
255
|
-
@config.persistence_cookie_domain =
|
256
|
-
expect(@config.persistence_cookie_domain).to eq(
|
250
|
+
@config.persistence_cookie_domain = ".acme.com"
|
251
|
+
expect(@config.persistence_cookie_domain).to eq(".acme.com")
|
257
252
|
end
|
258
253
|
end
|
259
|
-
|
260
254
|
end
|
@@ -1,108 +1,110 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "split/dashboard/pagination_helpers"
|
3
5
|
|
4
6
|
describe Split::DashboardPaginationHelpers do
|
5
7
|
include Split::DashboardPaginationHelpers
|
6
8
|
|
7
|
-
let(:url) {
|
9
|
+
let(:url) { "/split/" }
|
8
10
|
|
9
|
-
describe
|
10
|
-
context
|
11
|
+
describe "#pagination_per" do
|
12
|
+
context "when params empty" do
|
11
13
|
let(:params) { Hash[] }
|
12
14
|
|
13
|
-
it
|
15
|
+
it "returns the default (10)" do
|
14
16
|
default_per_page = Split.configuration.dashboard_pagination_default_per_page
|
15
17
|
expect(pagination_per).to eql default_per_page
|
16
18
|
expect(pagination_per).to eql 10
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
context
|
22
|
+
context "when params[:per] is 5" do
|
21
23
|
let(:params) { Hash[per: 5] }
|
22
24
|
|
23
|
-
it
|
25
|
+
it "returns 5" do
|
24
26
|
expect(pagination_per).to eql 5
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
describe
|
30
|
-
context
|
31
|
+
describe "#page_number" do
|
32
|
+
context "when params empty" do
|
31
33
|
let(:params) { Hash[] }
|
32
34
|
|
33
|
-
it
|
35
|
+
it "returns 1" do
|
34
36
|
expect(page_number).to eql 1
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
40
|
context 'when params[:page] is "2"' do
|
39
|
-
let(:params) { Hash[page:
|
41
|
+
let(:params) { Hash[page: "2"] }
|
40
42
|
|
41
|
-
it
|
43
|
+
it "returns 2" do
|
42
44
|
expect(page_number).to eql 2
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
describe
|
49
|
+
describe "#paginated" do
|
48
50
|
let(:collection) { (1..20).to_a }
|
49
|
-
let(:params) { Hash[per:
|
51
|
+
let(:params) { Hash[per: "5", page: "3"] }
|
50
52
|
|
51
53
|
it { expect(paginated(collection)).to eql [11, 12, 13, 14, 15] }
|
52
54
|
end
|
53
55
|
|
54
|
-
describe
|
55
|
-
context
|
56
|
+
describe "#show_first_page_tag?" do
|
57
|
+
context "when page is 1" do
|
56
58
|
it { expect(show_first_page_tag?).to be false }
|
57
59
|
end
|
58
60
|
|
59
|
-
context
|
60
|
-
let(:params) { Hash[page:
|
61
|
+
context "when page is 3" do
|
62
|
+
let(:params) { Hash[page: "3"] }
|
61
63
|
it { expect(show_first_page_tag?).to be true }
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
describe
|
67
|
+
describe "#first_page_tag" do
|
66
68
|
it { expect(first_page_tag).to eql '<a href="/split?page=1&per=10">1</a>' }
|
67
69
|
end
|
68
70
|
|
69
|
-
describe
|
70
|
-
context
|
71
|
+
describe "#show_first_ellipsis_tag?" do
|
72
|
+
context "when page is 1" do
|
71
73
|
it { expect(show_first_ellipsis_tag?).to be false }
|
72
74
|
end
|
73
75
|
|
74
|
-
context
|
75
|
-
let(:params) { Hash[page:
|
76
|
+
context "when page is 4" do
|
77
|
+
let(:params) { Hash[page: "4"] }
|
76
78
|
it { expect(show_first_ellipsis_tag?).to be true }
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
|
-
describe
|
81
|
-
it { expect(ellipsis_tag).to eql
|
82
|
+
describe "#ellipsis_tag" do
|
83
|
+
it { expect(ellipsis_tag).to eql "<span>...</span>" }
|
82
84
|
end
|
83
85
|
|
84
|
-
describe
|
85
|
-
context
|
86
|
+
describe "#show_prev_page_tag?" do
|
87
|
+
context "when page is 1" do
|
86
88
|
it { expect(show_prev_page_tag?).to be false }
|
87
89
|
end
|
88
90
|
|
89
|
-
context
|
90
|
-
let(:params) { Hash[page:
|
91
|
+
context "when page is 2" do
|
92
|
+
let(:params) { Hash[page: "2"] }
|
91
93
|
it { expect(show_prev_page_tag?).to be true }
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
|
-
describe
|
96
|
-
context
|
97
|
-
let(:params) { Hash[page:
|
97
|
+
describe "#prev_page_tag" do
|
98
|
+
context "when page is 2" do
|
99
|
+
let(:params) { Hash[page: "2"] }
|
98
100
|
|
99
101
|
it do
|
100
102
|
expect(prev_page_tag).to eql '<a href="/split?page=1&per=10">1</a>'
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
context
|
105
|
-
let(:params) { Hash[page:
|
106
|
+
context "when page is 3" do
|
107
|
+
let(:params) { Hash[page: "3"] }
|
106
108
|
|
107
109
|
it do
|
108
110
|
expect(prev_page_tag).to eql '<a href="/split?page=2&per=10">2</a>'
|
@@ -110,90 +112,90 @@ describe Split::DashboardPaginationHelpers do
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
113
|
-
describe
|
114
|
-
context
|
115
|
+
describe "#show_prev_page_tag?" do
|
116
|
+
context "when page is 1" do
|
115
117
|
it { expect(show_prev_page_tag?).to be false }
|
116
118
|
end
|
117
119
|
|
118
|
-
context
|
119
|
-
let(:params) { Hash[page:
|
120
|
+
context "when page is 2" do
|
121
|
+
let(:params) { Hash[page: "2"] }
|
120
122
|
it { expect(show_prev_page_tag?).to be true }
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
124
|
-
describe
|
125
|
-
context
|
126
|
-
let(:params) { Hash[page:
|
127
|
-
it { expect(current_page_tag).to eql
|
126
|
+
describe "#current_page_tag" do
|
127
|
+
context "when page is 1" do
|
128
|
+
let(:params) { Hash[page: "1"] }
|
129
|
+
it { expect(current_page_tag).to eql "<span><b>1</b></span>" }
|
128
130
|
end
|
129
131
|
|
130
|
-
context
|
131
|
-
let(:params) { Hash[page:
|
132
|
-
it { expect(current_page_tag).to eql
|
132
|
+
context "when page is 2" do
|
133
|
+
let(:params) { Hash[page: "2"] }
|
134
|
+
it { expect(current_page_tag).to eql "<span><b>2</b></span>" }
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
|
-
describe
|
137
|
-
context
|
138
|
-
let(:params) { Hash[page:
|
138
|
+
describe "#show_next_page_tag?" do
|
139
|
+
context "when page is 2" do
|
140
|
+
let(:params) { Hash[page: "2"] }
|
139
141
|
|
140
|
-
context
|
142
|
+
context "when collection length is 20" do
|
141
143
|
let(:collection) { (1..20).to_a }
|
142
144
|
it { expect(show_next_page_tag?(collection)).to be false }
|
143
145
|
end
|
144
146
|
|
145
|
-
context
|
147
|
+
context "when collection length is 25" do
|
146
148
|
let(:collection) { (1..25).to_a }
|
147
149
|
it { expect(show_next_page_tag?(collection)).to be true }
|
148
150
|
end
|
149
151
|
end
|
150
152
|
end
|
151
153
|
|
152
|
-
describe
|
153
|
-
context
|
154
|
-
let(:params) { Hash[page:
|
154
|
+
describe "#next_page_tag" do
|
155
|
+
context "when page is 1" do
|
156
|
+
let(:params) { Hash[page: "1"] }
|
155
157
|
it { expect(next_page_tag).to eql '<a href="/split?page=2&per=10">2</a>' }
|
156
158
|
end
|
157
159
|
|
158
|
-
context
|
159
|
-
let(:params) { Hash[page:
|
160
|
+
context "when page is 2" do
|
161
|
+
let(:params) { Hash[page: "2"] }
|
160
162
|
it { expect(next_page_tag).to eql '<a href="/split?page=3&per=10">3</a>' }
|
161
163
|
end
|
162
164
|
end
|
163
165
|
|
164
|
-
describe
|
165
|
-
context
|
166
|
+
describe "#total_pages" do
|
167
|
+
context "when collection length is 30" do
|
166
168
|
let(:collection) { (1..30).to_a }
|
167
169
|
it { expect(total_pages(collection)).to eql 3 }
|
168
170
|
end
|
169
171
|
|
170
|
-
context
|
172
|
+
context "when collection length is 35" do
|
171
173
|
let(:collection) { (1..35).to_a }
|
172
174
|
it { expect(total_pages(collection)).to eql 4 }
|
173
175
|
end
|
174
176
|
end
|
175
177
|
|
176
|
-
describe
|
178
|
+
describe "#show_last_ellipsis_tag?" do
|
177
179
|
let(:collection) { (1..30).to_a }
|
178
|
-
let(:params) { Hash[per:
|
180
|
+
let(:params) { Hash[per: "5", page: "2"] }
|
179
181
|
it { expect(show_last_ellipsis_tag?(collection)).to be true }
|
180
182
|
end
|
181
183
|
|
182
|
-
describe
|
184
|
+
describe "#show_last_page_tag?" do
|
183
185
|
let(:collection) { (1..30).to_a }
|
184
186
|
|
185
|
-
context
|
186
|
-
let(:params) { Hash[per:
|
187
|
+
context "when page is 5/6" do
|
188
|
+
let(:params) { Hash[per: "5", page: "5"] }
|
187
189
|
it { expect(show_last_page_tag?(collection)).to be false }
|
188
190
|
end
|
189
191
|
|
190
|
-
context
|
191
|
-
let(:params) { Hash[per:
|
192
|
+
context "when page is 4/6" do
|
193
|
+
let(:params) { Hash[per: "5", page: "4"] }
|
192
194
|
it { expect(show_last_page_tag?(collection)).to be true }
|
193
195
|
end
|
194
196
|
end
|
195
197
|
|
196
|
-
describe
|
198
|
+
describe "#last_page_tag" do
|
197
199
|
let(:collection) { (1..30).to_a }
|
198
200
|
it { expect(last_page_tag(collection)).to eql '<a href="/split?page=3&per=10">3</a>' }
|
199
201
|
end
|
@@ -1,34 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "split/dashboard/paginator"
|
4
5
|
|
5
6
|
describe Split::DashboardPaginator do
|
6
|
-
context
|
7
|
+
context "when collection is 1..20" do
|
7
8
|
let(:collection) { (1..20).to_a }
|
8
9
|
|
9
|
-
context
|
10
|
+
context "when per 5 for page" do
|
10
11
|
let(:per) { 5 }
|
11
12
|
|
12
|
-
it
|
13
|
+
it "when page number is 1 result is [1, 2, 3, 4, 5]" do
|
13
14
|
result = Split::DashboardPaginator.new(collection, 1, per).paginate
|
14
15
|
expect(result).to eql [1, 2, 3, 4, 5]
|
15
16
|
end
|
16
17
|
|
17
|
-
it
|
18
|
+
it "when page number is 2 result is [6, 7, 8, 9, 10]" do
|
18
19
|
result = Split::DashboardPaginator.new(collection, 2, per).paginate
|
19
20
|
expect(result).to eql [6, 7, 8, 9, 10]
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
context
|
24
|
+
context "when per 10 for page" do
|
24
25
|
let(:per) { 10 }
|
25
26
|
|
26
|
-
it
|
27
|
+
it "when page number is 1 result is [1..10]" do
|
27
28
|
result = Split::DashboardPaginator.new(collection, 1, per).paginate
|
28
29
|
expect(result).to eql [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
29
30
|
end
|
30
31
|
|
31
|
-
it
|
32
|
+
it "when page number is 2 result is [10..20]" do
|
32
33
|
result = Split::DashboardPaginator.new(collection, 2, per).paginate
|
33
34
|
expect(result).to eql [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
34
35
|
end
|
@@ -1,41 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "split/dashboard/helpers"
|
4
5
|
|
5
6
|
include Split::DashboardHelpers
|
6
7
|
|
7
8
|
describe Split::DashboardHelpers do
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
expect(confidence_level(Complex(2e-18, -0.03))).to eq(
|
9
|
+
describe "confidence_level" do
|
10
|
+
it "should handle very small numbers" do
|
11
|
+
expect(confidence_level(Complex(2e-18, -0.03))).to eq("Insufficient confidence")
|
11
12
|
end
|
12
13
|
|
13
14
|
it "should consider a z-score of 1.65 <= z < 1.96 as 90% confident" do
|
14
|
-
expect(confidence_level(1.65)).to eq(
|
15
|
-
expect(confidence_level(1.80)).to eq(
|
15
|
+
expect(confidence_level(1.65)).to eq("90% confidence")
|
16
|
+
expect(confidence_level(1.80)).to eq("90% confidence")
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should consider a z-score of 1.96 <= z < 2.58 as 95% confident" do
|
19
|
-
expect(confidence_level(1.96)).to eq(
|
20
|
-
expect(confidence_level(2.00)).to eq(
|
20
|
+
expect(confidence_level(1.96)).to eq("95% confidence")
|
21
|
+
expect(confidence_level(2.00)).to eq("95% confidence")
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should consider a z-score of z >= 2.58 as 99% confident" do
|
24
|
-
expect(confidence_level(2.58)).to eq(
|
25
|
-
expect(confidence_level(3.00)).to eq(
|
25
|
+
expect(confidence_level(2.58)).to eq("99% confidence")
|
26
|
+
expect(confidence_level(3.00)).to eq("99% confidence")
|
26
27
|
end
|
27
28
|
|
28
|
-
describe
|
29
|
-
it
|
30
|
-
expect(round(
|
29
|
+
describe "#round" do
|
30
|
+
it "can round number strings" do
|
31
|
+
expect(round("3.1415")).to eq BigDecimal("3.14")
|
31
32
|
end
|
32
33
|
|
33
|
-
it
|
34
|
-
expect(round(
|
34
|
+
it "can round number strings for precsion" do
|
35
|
+
expect(round("3.1415", 1)).to eq BigDecimal("3.1")
|
35
36
|
end
|
36
37
|
|
37
|
-
it
|
38
|
-
expect(round(
|
38
|
+
it "can handle invalid number strings" do
|
39
|
+
expect(round("N/A")).to be_zero
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|