test_track_rails_client 0.9.13 → 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +70 -0
- data/lib/generators/test_track/migration_generator.rb +55 -13
- data/lib/test_track_rails_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODhlNWMwYmU2ZWE5YmMwYTNlYTM0YTkyNDAyM2E0ODgyZjI1YjAyZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDc3MzQwNDcwNGM2MTY1MmY1ZjYwZmIxNDJlMGE5MWUwMjRiNzI4ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODc1YTE3ZjMxYzMwZTlkOTA2YjU1OTk2NDIyMGI2YjhlNWY0ZjRkZGQ2MzQy
|
10
|
+
Y2VhNmM4ZDRiY2JiMGI3ODBmM2M2NWRmMTI5MDNjNDVmMTQxZDRiZDNmZTQ0
|
11
|
+
ZWE5MjRiNmM4YmMzMzE4NjZmMzMxMDg5NzQwZGU4MDAxYjA5ODA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODI2MTViNTM5YjE0YzdkN2NmZjc5NWE5ZmJkODQ5ODIzYTAxZWVmNDI5ODhk
|
14
|
+
ZWY0ZTBmMzM2Y2FiNzUwMTFlMTdhZTNjZGYxNjE2MmVjY2QwMjllOWY0MjU0
|
15
|
+
ODg4ZTVmYzMyOTE0NTFjM2Y4OGE2MjhkM2YxZmY4Yjc2YjQzMDE=
|
data/README.md
CHANGED
@@ -107,6 +107,76 @@ end
|
|
107
107
|
|
108
108
|
_Note: `drop_split` (a.k.a. `finish_split`) does not physically delete split data from mixpanel or Test Track's database._
|
109
109
|
|
110
|
+
### Generating Split Migrations
|
111
|
+
|
112
|
+
Split configuration changes can be generated using Rails generators that are included with the TestTrack Rails client.
|
113
|
+
|
114
|
+
```
|
115
|
+
rails generate test_track:migration add_name_of_split
|
116
|
+
```
|
117
|
+
|
118
|
+
will generate a timestamped migration file with the content
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class AddNameOfSplit < ActiveRecord::Migration
|
122
|
+
def change
|
123
|
+
TestTrack.update_config do |c|
|
124
|
+
c.split :name_of_split, control: 50, treatment: 50
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
The generator infers the type of split from the migration name.
|
131
|
+
|
132
|
+
Adding `Drop` to the migration name will create a migration to drop a split.
|
133
|
+
|
134
|
+
```
|
135
|
+
rails generate test_track:migration drop_name_of_split
|
136
|
+
```
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
class DropNameOfSplit < ActiveRecord::Migration
|
140
|
+
def change
|
141
|
+
TestTrack.update_config do |c|
|
142
|
+
c.drop_split :name_of_split
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
Adding `Enabled` or `FeatureFlag` to the end of the migration name will create sensible defaults for a feature flag split.
|
149
|
+
|
150
|
+
```
|
151
|
+
rails generate test_track:migration add_name_of_split_enabled
|
152
|
+
```
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
class AddNameOfSplitEnabled < ActiveRecord::Migration
|
156
|
+
def change
|
157
|
+
TestTrack.update_config do |c|
|
158
|
+
c.split :name_of_split_enabled, true: 0, false: 100
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
Adding `Experiment` to the end of the migration name will create sensible defaults for an experiment.
|
165
|
+
|
166
|
+
```
|
167
|
+
rails generate test_track:migration add_name_of_split_experiment
|
168
|
+
```
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
class AddNameOfSplitExperiment < ActiveRecord::Migration
|
172
|
+
def change
|
173
|
+
TestTrack.update_config do |c|
|
174
|
+
c.split :name_of_split_experiment, control: 50, treatment: 50
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
110
180
|
## Varying app behavior based on assigned variant
|
111
181
|
|
112
182
|
### Varying app behavior in a web context
|
@@ -1,38 +1,80 @@
|
|
1
|
-
require 'rails/generators/
|
1
|
+
require 'rails/generators/base'
|
2
2
|
|
3
3
|
module TestTrack
|
4
4
|
module Generators
|
5
|
-
class MigrationGenerator < Rails::Generators::
|
6
|
-
desc "Creates a test track migration file.
|
5
|
+
class MigrationGenerator < Rails::Generators::Base
|
6
|
+
desc "Creates a test track migration file."
|
7
|
+
|
8
|
+
argument :raw_split_name, required: true
|
7
9
|
|
8
10
|
def create_test_track_migration_file
|
9
|
-
|
10
|
-
|
11
|
+
create_migration_file
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def create_migration_file
|
17
|
+
create_file full_file_path, <<-FILE.strip_heredoc
|
18
|
+
class #{split_class_name} < ActiveRecord::Migration
|
11
19
|
def change
|
12
20
|
TestTrack.update_config do |c|
|
13
|
-
#{
|
21
|
+
#{split_command_line}
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
17
25
|
FILE
|
18
26
|
end
|
19
27
|
|
20
|
-
|
28
|
+
def split_command_line
|
29
|
+
"#{split_command} :#{split_name}#{split_variants}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def split_command
|
33
|
+
@split_command ||= split_type == :drop ? 'c.drop_split' : 'c.split'
|
34
|
+
end
|
35
|
+
|
36
|
+
def split_variants
|
37
|
+
case split_type
|
38
|
+
when :drop
|
39
|
+
''
|
40
|
+
when :gate
|
41
|
+
', true: 0, false: 100'
|
42
|
+
else
|
43
|
+
', control: 50, treatment: 50'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def split_type
|
48
|
+
if split_file_name.start_with? 'drop'
|
49
|
+
:drop
|
50
|
+
elsif split_file_name.end_with? 'enabled', 'feature_flag'
|
51
|
+
:gate
|
52
|
+
elsif split_file_name.end_with? 'experiment'
|
53
|
+
:experiment
|
54
|
+
else
|
55
|
+
:default
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def full_file_path
|
60
|
+
"db/migrate/#{formatted_time_stamp}_#{split_file_name}.rb"
|
61
|
+
end
|
21
62
|
|
22
63
|
def formatted_time_stamp
|
23
64
|
Time.zone.now.strftime('%Y%m%d%H%M%S')
|
24
65
|
end
|
25
66
|
|
26
|
-
def
|
27
|
-
|
67
|
+
def split_class_name
|
68
|
+
split_file_name.camelize
|
28
69
|
end
|
29
70
|
|
30
|
-
def
|
31
|
-
|
71
|
+
def split_name
|
72
|
+
noise_words = /^create_|^update_|^drop_|^add_/
|
73
|
+
split_file_name.gsub(noise_words, '')
|
32
74
|
end
|
33
75
|
|
34
|
-
def
|
35
|
-
|
76
|
+
def split_file_name
|
77
|
+
raw_split_name.underscore
|
36
78
|
end
|
37
79
|
end
|
38
80
|
end
|