verdict 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1929eb3266514c557ec595e7fa7f80065a1b600
4
- data.tar.gz: 1f34b0ad26c876f348649ad04d96a9f0c077ea48
3
+ metadata.gz: dd82ab981cc4c81f2b23f45dbfd6085ee4516a70
4
+ data.tar.gz: 02e7e6e193a70f05ade2cc207f396f7e249a49ae
5
5
  SHA512:
6
- metadata.gz: 63801e6ec63ae74dcb33c418090fec977a4598e23da4ff6bc642e2041025915f5ea8eda536ff7c5415dfd18106d1dc1c1fe339b6901b26663b70bfcad4d8803f
7
- data.tar.gz: 982e62386331ba13174d3e758a9624ba76b80e45e30ba59f788c65a239585a74abd6386f79622e0dd7314328c0e7843852a01bb6a4b4f7597f6b1d3618f99644
6
+ metadata.gz: a5c0c8723feb906c79ceb96358a5fd7d1fd2abc59358a6c430741f275cb8293f84357cda76a885925c7db071864acdb4e0f17b6639c15f60a5b3ad1e4e289f86
7
+ data.tar.gz: d7c49f872ca05140a5f7b555ea9fddc18b06f749b5b50b9f074f5f921f464b5e253a8039b2f61521334f9c01c65d5059ea2a3e2e3072c6a9b9667ce5ebf2d375
@@ -1,3 +1,23 @@
1
+ ## v0.8.0
2
+ **This version has breaking changes**
3
+
4
+ * Experiments that have `store_unqualified` set to `false` will now have previous assignments loaded on `assign` regardless of whether or not the merchant no longer qualifies
5
+ * Here's the change in logic for `assign` based on whether or not the `store_unqualified` flag is on:
6
+
7
+ Old behaviour:
8
+
9
+ | store_unqualified | true | false |
10
+ |-----------------------------------------------------------------------------|------|-------|
11
+ | assignments for subjects that don't qualify are persisted in the database | yes | no |
12
+ | existing assignments are returned (even if subject doesn't qualify anymore) | yes | no |
13
+
14
+ New behaviour:
15
+
16
+ | store_unqualified | true | false |
17
+ |-----------------------------------------------------------------------------|------|-------|
18
+ | assignments for subjects that don't qualify are persisted in the database | yes | no |
19
+ | existing assignments are returned (even if subject doesn't qualify anymore) | yes | **yes** |
20
+
1
21
  ## v0.7.0
2
22
  **This version has breaking changes**
3
23
 
@@ -26,7 +26,6 @@ class Verdict::Experiment
26
26
  instance_eval(&block) if block_given?
27
27
  end
28
28
 
29
-
30
29
  def subject_type(type = nil)
31
30
  return @subject_type if type.nil?
32
31
  @subject_type = type
@@ -120,12 +119,17 @@ class Verdict::Experiment
120
119
  end
121
120
 
122
121
  def assign(subject, context = nil)
123
- identifier = retrieve_subject_identifier(subject)
124
- assignment = if store_unqualified?
125
- assignment_with_unqualified_persistence(identifier, subject, context)
126
- else
127
- assignment_without_unqualified_persistence(identifier, subject, context)
128
- end
122
+ previous_assignment = lookup(subject)
123
+
124
+ subject_identifier = retrieve_subject_identifier(subject)
125
+ assignment = if previous_assignment
126
+ previous_assignment
127
+ elsif subject_qualifies?(subject, context)
128
+ group = segmenter.assign(subject_identifier, subject, context)
129
+ subject_assignment(subject, group, nil, group.nil?)
130
+ else
131
+ nil_assignment(subject)
132
+ end
129
133
 
130
134
  store_assignment(assignment)
131
135
  rescue Verdict::StorageError
@@ -225,28 +229,6 @@ class Verdict::Experiment
225
229
  assignment.permanent? && !assignment.returning? && (store_unqualified? || assignment.qualified?)
226
230
  end
227
231
 
228
- def assignment_with_unqualified_persistence(subject_identifier, subject, context)
229
- previous_assignment = lookup(subject)
230
- return previous_assignment unless previous_assignment.nil?
231
- if subject_qualifies?(subject, context)
232
- group = segmenter.assign(subject_identifier, subject, context)
233
- subject_assignment(subject, group, nil, group.nil?)
234
- else
235
- nil_assignment(subject)
236
- end
237
- end
238
-
239
- def assignment_without_unqualified_persistence(subject_identifier, subject, context)
240
- if subject_qualifies?(subject, context)
241
- previous_assignment = lookup(subject)
242
- return previous_assignment unless previous_assignment.nil?
243
- group = segmenter.assign(subject_identifier, subject, context)
244
- subject_assignment(subject, group, nil, group.nil?)
245
- else
246
- nil_assignment(subject)
247
- end
248
- end
249
-
250
232
  def subject_identifier(subject)
251
233
  subject.respond_to?(:id) ? subject.id : subject.to_s
252
234
  end
@@ -16,7 +16,7 @@ module Verdict
16
16
 
17
17
  def self.experiment
18
18
  experiment_handle = Verdict::Rake.require_env('experiment')
19
- Verdict[experiment_handle] or raise "Experiment `#{handle}` not found"
19
+ Verdict[experiment_handle] or raise "Experiment `#{experiment_handle}` not found"
20
20
  end
21
21
 
22
22
  def self.group
@@ -1,3 +1,3 @@
1
1
  module Verdict
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -22,7 +22,7 @@ class ExperimentTest < Minitest::Test
22
22
 
23
23
  subject_stub = Struct.new(:id, :country)
24
24
  ca_subject = subject_stub.new(1, 'CA')
25
- us_subject = subject_stub.new(1, 'US')
25
+ us_subject = subject_stub.new(2, 'US')
26
26
 
27
27
  assert e.qualifiers.all? { |q| q.call(ca_subject) }
28
28
  refute e.qualifiers.all? { |q| q.call(us_subject) }
@@ -89,7 +89,7 @@ class ExperimentTest < Minitest::Test
89
89
 
90
90
  subject_stub = Struct.new(:id, :country)
91
91
  ca_subject = subject_stub.new(1, 'CA')
92
- us_subject = subject_stub.new(1, 'US')
92
+ us_subject = subject_stub.new(2, 'US')
93
93
 
94
94
  assert e.qualifiers.all? { |q| q.call(ca_subject, nil) }
95
95
  refute e.qualifiers.all? { |q| q.call(us_subject, nil) }
@@ -153,7 +153,7 @@ class ExperimentTest < Minitest::Test
153
153
  def test_experiment_with_manual_assignment_timestamps_option
154
154
  e = Verdict::Experiment.new('test', manual_assignment_timestamps: true) do
155
155
  groups { group :all, 100 }
156
- end
156
+ end
157
157
 
158
158
  assert e.manual_assignment_timestamps?
159
159
  end
@@ -166,20 +166,22 @@ class ExperimentTest < Minitest::Test
166
166
  assert_raises(Verdict::EmptySubjectIdentifier) { e.retrieve_subject_identifier(stub(to_s: '')) }
167
167
  end
168
168
 
169
- def test_new_unqualified_assignment_without_store_unqualified
169
+ def test_assignment_without_store_unqualified_always_fetches_old_assignment_if_available
170
170
  mock_store, mock_qualifier = Verdict::Storage::MockStorage.new, mock('qualifier')
171
171
  e = Verdict::Experiment.new('test') do
172
172
  qualify { mock_qualifier.qualifies? }
173
173
  storage mock_store, store_unqualified: false
174
+ groups { group :all, 100 }
174
175
  end
175
176
 
176
- mock_qualifier.expects(:qualifies?).returns(false)
177
- mock_store.expects(:retrieve_assignment).never
177
+ qualified_assignment = e.subject_assignment(mock('identifier'), e.group(:all), Time.now)
178
+
179
+ mock_store.expects(:retrieve_assignment).returns(qualified_assignment).once
178
180
  mock_store.expects(:store_assignment).never
179
181
  e.assign(mock('subject'))
180
182
  end
181
183
 
182
- def test_returning_qualified_assignment_without_store_unqualified
184
+ def test_new_unqualified_assignment_without_store_unqualified_does_not_store_if_merchant_not_qualified
183
185
  mock_store, mock_qualifier = Verdict::Storage::MockStorage.new, mock('qualifier')
184
186
  e = Verdict::Experiment.new('test') do
185
187
  qualify { mock_qualifier.qualifies? }
@@ -187,9 +189,8 @@ class ExperimentTest < Minitest::Test
187
189
  groups { group :all, 100 }
188
190
  end
189
191
 
190
- qualified_assignment = e.subject_assignment(mock('identifier'), e.group(:all), Time.now)
191
- mock_qualifier.expects(:qualifies?).returns(true)
192
- mock_store.expects(:retrieve_assignment).returns(qualified_assignment).once
192
+ mock_qualifier.expects(:qualifies?).returns(false)
193
+ mock_store.expects(:retrieve_assignment).returns(nil).once
193
194
  mock_store.expects(:store_assignment).never
194
195
  e.assign(mock('subject'))
195
196
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest