vanity 2.0.0.beta4 → 2.0.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +4 -0
- data/Appraisals +14 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +5 -3
- data/README.rdoc +5 -1
- data/config/locales/vanity.en.yml +39 -0
- data/config/locales/vanity.pt-BR.yml +41 -0
- data/doc/ab_testing.textile +1 -1
- data/doc/rails.textile +13 -0
- data/gemfiles/rails32.gemfile +2 -2
- data/gemfiles/rails32.gemfile.lock +4 -3
- data/gemfiles/rails4.gemfile +2 -2
- data/gemfiles/rails4.gemfile.lock +4 -3
- data/gemfiles/rails41.gemfile +29 -0
- data/gemfiles/rails41.gemfile.lock +196 -0
- data/gemfiles/rails42.gemfile +29 -0
- data/gemfiles/rails42.gemfile.lock +235 -0
- data/lib/generators/templates/vanity_migration.rb +1 -1
- data/lib/generators/vanity/views_generator.rb +16 -0
- data/lib/vanity.rb +1 -0
- data/lib/vanity/experiment/ab_test.rb +15 -15
- data/lib/vanity/experiment/alternative.rb +2 -2
- data/lib/vanity/frameworks/rails.rb +16 -3
- data/lib/vanity/metric/active_record.rb +1 -1
- data/lib/vanity/playground.rb +19 -25
- data/lib/vanity/templates.rb +29 -0
- data/lib/vanity/templates/_ab_test.erb +12 -12
- data/lib/vanity/templates/_experiment.erb +4 -2
- data/lib/vanity/templates/_participant.erb +2 -2
- data/lib/vanity/templates/_report.erb +6 -6
- data/lib/vanity/templates/_vanity.js.erb +13 -15
- data/lib/vanity/templates/vanity.css +4 -4
- data/lib/vanity/version.rb +1 -1
- data/test/frameworks/rails/action_controller_test.rb +1 -1
- data/test/frameworks/rails/rails_test.rb +118 -102
- data/test/playground_test.rb +13 -0
- data/test/templates_test.rb +28 -0
- data/test/test_helper.rb +15 -17
- data/test/web/rails/dashboard_test.rb +25 -4
- data/vanity.gemspec +2 -0
- metadata +36 -18
@@ -0,0 +1,29 @@
|
|
1
|
+
module Vanity
|
2
|
+
class Templates
|
3
|
+
def initialize
|
4
|
+
@template_directory = load_paths.find { |dir| File.exists?(dir) }
|
5
|
+
end
|
6
|
+
|
7
|
+
# Path to template.
|
8
|
+
def path(name)
|
9
|
+
File.join(@template_directory, name)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def load_paths
|
15
|
+
[Vanity.playground.custom_templates_path, gem_templates_path].compact
|
16
|
+
end
|
17
|
+
|
18
|
+
def gem_templates_path
|
19
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def template(name)
|
25
|
+
@templates ||= Templates.new
|
26
|
+
@templates.path(name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -7,33 +7,33 @@
|
|
7
7
|
<tr class="<%= "choice" if score.choice == alt %>">
|
8
8
|
<td class="option"><%= alt.name.gsub(/^o/, "O") %>:</td>
|
9
9
|
<td class="value"><code><%=vanity_h alt.value.to_s %></code></td>
|
10
|
-
<td class="value"><%= alt.participants
|
11
|
-
<td class="value"><%= alt.converted
|
10
|
+
<td class="value"><%= I18n.t 'vanity.participants', :count=>alt.participants %></td>
|
11
|
+
<td class="value"><%= I18n.t 'vanity.converted', :count=>alt.converted %></td>
|
12
12
|
<td>
|
13
13
|
<%= "%.1f%%" % [alt.conversion_rate * 100] %>
|
14
|
-
<%=
|
15
|
-
<%=
|
14
|
+
<%= I18n.t('vanity.best_alternative', :probabilty=>alt.probability.to_i) if score.method == :bayes_score %>
|
15
|
+
<%= I18n.t('vanity.better_alternative_than', :probability=>alt.difference.to_i, :alternative=>score.least.name) if alt.difference && alt.difference >= 1 %>
|
16
16
|
</td>
|
17
17
|
<% if experiment.active? && respond_to?(:url_for) %>
|
18
18
|
<td class="action">
|
19
19
|
<small>
|
20
20
|
<% if experiment.showing?(alt) %>
|
21
|
-
|
21
|
+
<%= I18n.t 'vanity.currently_shown' %>
|
22
22
|
<% else %>
|
23
|
-
<a class="button chooses" title="
|
24
|
-
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:chooses, :e=>experiment.id, :a=>alt.id) %>"
|
23
|
+
<a class="button chooses" title="<%= I18n.t 'vanity.choose_experiment' %>" href="#"
|
24
|
+
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:chooses, :e=>experiment.id, :a=>alt.id) %>"><%= I18n.t 'vanity.show_me' %></a>
|
25
25
|
<% end %>
|
26
26
|
</small>
|
27
27
|
</td>
|
28
28
|
<td class="action">
|
29
29
|
<small>
|
30
30
|
<% if @to_confirm == alt.id %>
|
31
|
-
|
32
|
-
|
33
|
-
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id, :confirmed=>alt.id) %>"
|
31
|
+
<%= I18n.t 'vanity.complete_and_confirm_experiment_label', :name=>alt.name %>
|
32
|
+
<a class="button chooses" title="<%= I18n.t 'vanity.complete_and_confirm_experiment', name: alt.name %>" href="#"
|
33
|
+
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id, :confirmed=>alt.id) %>"><%= I18n.t 'vanity.confirm' %></a>
|
34
34
|
<% else %>
|
35
|
-
|
36
|
-
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id) %>"
|
35
|
+
<a class="button chooses" title="<%= I18n.t 'vanity.complete_experiment', :name=>alt.name %>" href="#"
|
36
|
+
data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id) %>"><%= I18n.t 'vanity.make_permanent' %></a>
|
37
37
|
<% end %>
|
38
38
|
</small>
|
39
39
|
</td>
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<h3><%=vanity_h experiment.name %> <span class="type">(<%= experiment.class.friendly_name %>)</span></h3>
|
2
2
|
<%= experiment.description.to_s.split(/\n\s*\n/).map { |para| vanity_html_safe(%{<p class="description">#{vanity_h para}</p>}) }.join.html_safe %>
|
3
3
|
<%= render :file => Vanity.template("_" + experiment.type), :locals => {:experiment => experiment} %>
|
4
|
-
<p class="meta">
|
5
|
-
<%=
|
4
|
+
<p class="meta">
|
5
|
+
<%= I18n.t('vanity.started_at', :timestamp=>I18n.l(experiment.created_at, :format=>'%a, %b %d')) %>
|
6
|
+
<%= ' | '+I18n.t('vanity.completed_at', :timestamp=>I18n.l(experiment.completed_at, :format=>'%a, %b %d')) unless experiment.active? %>
|
7
|
+
</p>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<p
|
1
|
+
<p><%= I18n.t 'vanity.participant_taking_part_on', :participant_id=>participant_id %>
|
2
2
|
<ul class="experiments">
|
3
3
|
<% participant_info.each do |experiment, alt| %>
|
4
4
|
<li class="experiment <%= experiment.type %>" id="experiment_<%=vanity_h experiment.id.to_s %>">
|
@@ -9,4 +9,4 @@
|
|
9
9
|
</li>
|
10
10
|
<% end %>
|
11
11
|
</ul>
|
12
|
-
</p>
|
12
|
+
</p>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
|
-
<title
|
3
|
+
<title><%= I18n.t('vanity.report', :timestamp=>I18n.l(Time.now, :format=>'%b %d %Y, %I:%M:%P')) %></title>
|
4
4
|
<style>
|
5
5
|
.vanity { margin: 2em auto; width: 40em; font-family: "Helvetica Neue", "Helvetica", "Verdana", sans-serif }
|
6
6
|
.vanity h1 { margin: 1em 0; border-bottom: 3px solid #ccc }
|
@@ -15,27 +15,27 @@
|
|
15
15
|
<div class="vanity">
|
16
16
|
<% unless Vanity.playground.collecting? %>
|
17
17
|
<div class="alert collecting">
|
18
|
-
|
18
|
+
<%= I18n.t('vanity.not_collecting_data', :setting=>"<span style='font-family: courier'>Vanity.playground.collecting = true;</span>", :file=>"<span style='font-family: courier'>config/environments/[environment].rb</span>").html_safe %>
|
19
19
|
</div>
|
20
20
|
<% end %>
|
21
21
|
|
22
22
|
<% if experiments_persisted %>
|
23
23
|
<% if experiments.present? %>
|
24
|
-
<h2
|
24
|
+
<h2><%= I18n.t 'vanity.experiments' %></h2>
|
25
25
|
<%= render :file=>Vanity.template("_experiments"), :locals=>{:experiments=>experiments} %>
|
26
26
|
<% end %>
|
27
27
|
|
28
28
|
<% unless metrics.empty? %>
|
29
|
-
<h2
|
29
|
+
<h2><%= I18n.t 'vanity.metrics' %></h2>
|
30
30
|
<%= render :file=>Vanity.template("_metrics"), :locals=>{:metrics=>metrics, :experiments=>experiments} %>
|
31
31
|
<% end %>
|
32
32
|
<% else %>
|
33
33
|
<div class="alert persistance">
|
34
|
-
|
34
|
+
<%= I18n.t 'vanity.experiments_out_of_sync' %>
|
35
35
|
</div>
|
36
36
|
<% end %>
|
37
37
|
|
38
|
-
<p class="footer"
|
38
|
+
<p class="footer"><%= I18n.t('vanity.generated_by', :link=>'<a href="http://vanity.labnotes.org">Vanity</a>').html_safe %></p>
|
39
39
|
</div>
|
40
40
|
</body>
|
41
41
|
</html>
|
@@ -1,16 +1,14 @@
|
|
1
1
|
var httpRequest;
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
<% end %>
|
2
|
+
var params = "v=<%= @_vanity_experiments.map{|name, alternative| "#{name}=#{alternative.id}" }.join(',') %>&authenticity_token=<%= CGI.escape(form_authenticity_token) %>";
|
3
|
+
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
|
4
|
+
httpRequest = new XMLHttpRequest();
|
5
|
+
} else if (window.ActiveXObject) { // IE
|
6
|
+
try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
|
7
|
+
catch (e) { }
|
8
|
+
}
|
9
|
+
if (httpRequest) {
|
10
|
+
httpRequest.open('POST', "<%= Vanity.playground.add_participant_path %>", true);
|
11
|
+
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
12
|
+
httpRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
13
|
+
httpRequest.send(params);
|
14
|
+
}
|
@@ -9,12 +9,12 @@
|
|
9
9
|
.vanity .experiment .type { margin-left: .3em; color: #bbb; font-size: .8em; font-weight: normal }
|
10
10
|
|
11
11
|
.vanity .ab_test table { border-collapse: collapse; table-layout: fixed; width: 100%; border-bottom: 1px solid #ccc; margin: 1em 0 0 0 }
|
12
|
-
.vanity .ab_test td { padding: .5em; border-top: 1px solid #ccc }
|
12
|
+
.vanity .ab_test td { padding: .5em; border-top: 1px solid #ccc; width: 2em; overflow: hidden }
|
13
13
|
.vanity .ab_test .choice td { font-weight: bold; background: #f0f0f8 }
|
14
14
|
.vanity .ab_test caption { caption-side: bottom; padding: .5em; background: transparent; text-align: left }
|
15
|
-
.vanity .ab_test td.option { width: 5em; white-space: nowrap;
|
16
|
-
.vanity .ab_test td.value { width: 8em;
|
17
|
-
.vanity .ab_test td.action { width: 6em;
|
15
|
+
.vanity .ab_test td.option { width: 5em; white-space: nowrap; }
|
16
|
+
.vanity .ab_test td.value { width: 8em; }
|
17
|
+
.vanity .ab_test td.action { width: 6em; text-align: right }
|
18
18
|
|
19
19
|
.vanity .metrics { list-style: none; margin: 0; padding: 0; border-bottom: 1px solid #ddd }
|
20
20
|
.vanity .metric { margin: 2em 0 }
|
data/lib/vanity/version.rb
CHANGED
@@ -34,7 +34,7 @@ class UseVanityControllerTest < ActionController::TestCase
|
|
34
34
|
def test_render_js_for_tests
|
35
35
|
Vanity.playground.use_js!
|
36
36
|
get :js
|
37
|
-
assert_match /script.*
|
37
|
+
assert_match /script.*v=pie_or_cake=.*script/m, @response.body
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_chooses_sets_alternatives_for_rails_tests
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
3
|
+
describe "Rails load path and connection configuration" do
|
4
4
|
|
5
|
-
|
5
|
+
it "load_path" do
|
6
6
|
assert_equal File.expand_path("tmp/experiments"), load_rails("", <<-RB)
|
7
7
|
$stdout << Vanity.playground.load_path
|
8
8
|
RB
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
it "settable_load_path" do
|
12
12
|
assert_equal File.expand_path("tmp/predictions"), load_rails(%Q{\nVanity.playground.load_path = "predictions"\n}, <<-RB)
|
13
13
|
$stdout << Vanity.playground.load_path
|
14
14
|
RB
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
it "absolute_load_path" do
|
18
18
|
Dir.mktmpdir do |dir|
|
19
19
|
assert_equal dir, load_rails(%Q{\nVanity.playground.load_path = "#{dir}"\n}, <<-RB)
|
20
20
|
$stdout << Vanity.playground.load_path
|
@@ -23,201 +23,217 @@ $stdout << Vanity.playground.load_path
|
|
23
23
|
end
|
24
24
|
|
25
25
|
if ENV['DB'] == 'redis'
|
26
|
-
|
26
|
+
it "default_connection" do
|
27
27
|
assert_equal "redis://127.0.0.1:6379/0", load_rails("", <<-RB)
|
28
28
|
$stdout << Vanity.playground.connection
|
29
29
|
RB
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "connection_from_string" do
|
33
33
|
assert_equal "redis://192.168.1.1:6379/5", load_rails(%Q{\nVanity.playground.establish_connection "redis://192.168.1.1:6379/5"\n}, <<-RB)
|
34
34
|
$stdout << Vanity.playground.connection
|
35
35
|
RB
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
it "connection_from_yaml" do
|
39
|
+
begin
|
40
|
+
FileUtils.mkpath "tmp/config"
|
41
|
+
@original_env = ENV["RAILS_ENV"]
|
42
|
+
ENV["RAILS_ENV"] = "production"
|
43
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
44
|
+
io.write <<-YML
|
44
45
|
production:
|
45
46
|
adapter: redis
|
46
47
|
host: somehost
|
47
48
|
database: 15
|
48
49
|
YML
|
49
|
-
|
50
|
-
|
50
|
+
end
|
51
|
+
assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
|
51
52
|
$stdout << Vanity.playground.connection
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
RB
|
54
|
+
ensure
|
55
|
+
ENV["RAILS_ENV"] = @original_env
|
56
|
+
File.unlink "tmp/config/vanity.yml"
|
57
|
+
end
|
56
58
|
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
it "connection_from_yaml_url" do
|
61
|
+
begin
|
62
|
+
FileUtils.mkpath "tmp/config"
|
63
|
+
@original_env = ENV["RAILS_ENV"]
|
64
|
+
ENV["RAILS_ENV"] = "production"
|
65
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
66
|
+
io.write <<-YML
|
64
67
|
production: redis://somehost/15
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
YML
|
69
|
+
end
|
70
|
+
assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
|
68
71
|
$stdout << Vanity.playground.connection
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
RB
|
73
|
+
ensure
|
74
|
+
ENV["RAILS_ENV"] = @original_env
|
75
|
+
File.unlink "tmp/config/vanity.yml"
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
it "connection_from_yaml_with_erb" do
|
80
|
+
begin
|
81
|
+
FileUtils.mkpath "tmp/config"
|
82
|
+
@original_env = ENV["RAILS_ENV"]
|
83
|
+
ENV["RAILS_ENV"] = "production"
|
84
|
+
# Pass storage URL through environment like heroku does
|
85
|
+
@original_redis_url = ENV["REDIS_URL"]
|
86
|
+
ENV["REDIS_URL"] = "redis://somehost:6379/15"
|
87
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
88
|
+
io.write <<-YML
|
84
89
|
production: <%= ENV['REDIS_URL'] %>
|
85
90
|
YML
|
86
|
-
|
87
|
-
|
91
|
+
end
|
92
|
+
assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
|
88
93
|
$stdout << Vanity.playground.connection
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
RB
|
95
|
+
ensure
|
96
|
+
ENV["RAILS_ENV"] = @original_env
|
97
|
+
ENV["REDIS_URL"] = @original_redis_url
|
98
|
+
File.unlink "tmp/config/vanity.yml"
|
99
|
+
end
|
94
100
|
end
|
95
101
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
+
it "connection_from_redis_yml" do
|
103
|
+
begin
|
104
|
+
FileUtils.mkpath "tmp/config"
|
105
|
+
yml = File.open("tmp/config/redis.yml", "w")
|
106
|
+
yml << "production: internal.local:6379\n"
|
107
|
+
yml.flush
|
108
|
+
assert_equal "redis://internal.local:6379/0", load_rails("", <<-RB)
|
102
109
|
$stdout << Vanity.playground.connection
|
103
|
-
|
104
|
-
|
105
|
-
|
110
|
+
RB
|
111
|
+
ensure
|
112
|
+
File.unlink yml.path
|
113
|
+
end
|
106
114
|
end
|
107
115
|
end
|
108
116
|
|
109
117
|
if ENV['DB'] == 'mongo'
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
118
|
+
it "mongo_connection_from_yaml" do
|
119
|
+
begin
|
120
|
+
FileUtils.mkpath "tmp/config"
|
121
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
122
|
+
io.write <<-YML
|
114
123
|
mongodb:
|
115
124
|
adapter: mongodb
|
116
125
|
host: localhost
|
117
126
|
port: 27017
|
118
127
|
database: vanity_test
|
119
|
-
|
120
|
-
|
128
|
+
YML
|
129
|
+
end
|
121
130
|
|
122
|
-
|
131
|
+
assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
|
123
132
|
$stdout << Vanity.playground.connection
|
124
|
-
|
125
|
-
|
126
|
-
|
133
|
+
RB
|
134
|
+
ensure
|
135
|
+
File.unlink "tmp/config/vanity.yml"
|
136
|
+
end
|
127
137
|
end
|
128
138
|
|
129
139
|
unless ENV['CI'] == 'true' #TODO this doesn't get tested on CI
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
140
|
+
it "mongodb_replica_set_connection" do
|
141
|
+
begin
|
142
|
+
FileUtils.mkpath "tmp/config"
|
143
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
144
|
+
io.write <<-YML
|
134
145
|
mongodb:
|
135
146
|
adapter: mongodb
|
136
147
|
hosts:
|
137
148
|
- localhost
|
138
149
|
port: 27017
|
139
150
|
database: vanity_test
|
140
|
-
|
141
|
-
|
151
|
+
YML
|
152
|
+
end
|
142
153
|
|
143
|
-
|
154
|
+
assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
|
144
155
|
$stdout << Vanity.playground.connection
|
145
|
-
|
156
|
+
RB
|
146
157
|
|
147
|
-
|
158
|
+
assert_equal "Mongo::ReplSetConnection", load_rails("", <<-RB, "mongodb")
|
148
159
|
$stdout << Vanity.playground.connection.mongo.class
|
149
|
-
|
150
|
-
|
151
|
-
|
160
|
+
RB
|
161
|
+
ensure
|
162
|
+
File.unlink "tmp/config/vanity.yml"
|
163
|
+
end
|
152
164
|
end
|
153
165
|
end
|
154
166
|
end
|
155
167
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
168
|
+
it "connection_from_yaml_missing" do
|
169
|
+
begin
|
170
|
+
FileUtils.mkpath "tmp/config"
|
171
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
172
|
+
io.write <<-YML
|
160
173
|
production:
|
161
174
|
adapter: redis
|
162
175
|
YML
|
163
|
-
|
176
|
+
end
|
164
177
|
|
165
|
-
|
178
|
+
assert_equal "No configuration for development", load_rails("\nbegin\n", <<-RB, "development")
|
166
179
|
rescue RuntimeError => e
|
167
180
|
$stdout << e.message
|
168
181
|
end
|
169
182
|
RB
|
170
|
-
|
171
|
-
|
183
|
+
ensure
|
184
|
+
File.unlink "tmp/config/vanity.yml"
|
185
|
+
end
|
172
186
|
end
|
173
187
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
188
|
+
it "collection_from_vanity_yaml" do
|
189
|
+
begin
|
190
|
+
FileUtils.mkpath "tmp/config"
|
191
|
+
File.open("tmp/config/vanity.yml", "w") do |io|
|
192
|
+
io.write <<-YML
|
178
193
|
production:
|
179
194
|
collecting: false
|
180
195
|
adapter: mock
|
181
|
-
|
182
|
-
|
183
|
-
|
196
|
+
YML
|
197
|
+
end
|
198
|
+
assert_equal "false", load_rails("", <<-RB)
|
184
199
|
$stdout << Vanity.playground.collecting?
|
185
|
-
|
186
|
-
|
187
|
-
|
200
|
+
RB
|
201
|
+
ensure
|
202
|
+
File.unlink "tmp/config/vanity.yml"
|
203
|
+
end
|
188
204
|
end
|
189
205
|
|
190
|
-
|
206
|
+
it "collection_true_in_production_by_default" do
|
191
207
|
assert_equal "true", load_rails("", <<-RB)
|
192
208
|
$stdout << Vanity.playground.collecting?
|
193
209
|
RB
|
194
210
|
end
|
195
211
|
|
196
|
-
|
212
|
+
it "collection_false_in_production_when_configured" do
|
197
213
|
assert_equal "false", load_rails("\nVanity.playground.collecting = false\n", <<-RB)
|
198
214
|
$stdout << Vanity.playground.collecting?
|
199
215
|
RB
|
200
216
|
end
|
201
217
|
|
202
|
-
|
218
|
+
it "collection_true_in_development_by_default" do
|
203
219
|
assert_equal "true", load_rails("", <<-RB, "development")
|
204
220
|
$stdout << Vanity.playground.collecting?
|
205
221
|
RB
|
206
222
|
end
|
207
223
|
|
208
|
-
|
224
|
+
it "collection_true_in_development_when_configured" do
|
209
225
|
assert_equal "true", load_rails("\nVanity.playground.collecting = true\n", <<-RB, "development")
|
210
226
|
$stdout << Vanity.playground.collecting?
|
211
227
|
RB
|
212
228
|
end
|
213
229
|
|
214
|
-
|
230
|
+
it "playground_loads_if_connected" do
|
215
231
|
assert_equal "{}", load_rails("", <<-RB)
|
216
232
|
$stdout << Vanity.playground.instance_variable_get(:@experiments).inspect
|
217
233
|
RB
|
218
234
|
end
|
219
235
|
|
220
|
-
|
236
|
+
it "playground_does_not_load_if_not_connected" do
|
221
237
|
ENV['VANITY_DISABLED'] = '1'
|
222
238
|
assert_equal "nil", load_rails("", <<-RB)
|
223
239
|
$stdout << Vanity.playground.instance_variable_get(:@experiments).inspect
|