vanity 3.1.0 → 4.0.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 +4 -4
- data/.github/workflows/linting.yml +28 -0
- data/.github/workflows/test.yml +3 -6
- data/.rubocop.yml +114 -0
- data/.rubocop_todo.yml +67 -0
- data/Appraisals +9 -31
- data/CHANGELOG +5 -0
- data/Gemfile +7 -3
- data/Gemfile.lock +31 -3
- data/README.md +4 -9
- data/Rakefile +25 -24
- data/bin/vanity +1 -1
- data/doc/configuring.textile +1 -0
- data/gemfiles/rails52.gemfile +6 -3
- data/gemfiles/rails52.gemfile.lock +34 -9
- data/gemfiles/rails60.gemfile +6 -3
- data/gemfiles/rails60.gemfile.lock +34 -9
- data/gemfiles/rails61.gemfile +6 -3
- data/gemfiles/rails61.gemfile.lock +34 -9
- data/lib/generators/vanity/migration_generator.rb +5 -7
- data/lib/vanity/adapters/abstract_adapter.rb +43 -45
- data/lib/vanity/adapters/active_record_adapter.rb +30 -30
- data/lib/vanity/adapters/mock_adapter.rb +14 -18
- data/lib/vanity/adapters/mongodb_adapter.rb +73 -69
- data/lib/vanity/adapters/redis_adapter.rb +19 -27
- data/lib/vanity/adapters.rb +1 -1
- data/lib/vanity/autoconnect.rb +6 -7
- data/lib/vanity/commands/list.rb +7 -7
- data/lib/vanity/commands/report.rb +18 -22
- data/lib/vanity/configuration.rb +19 -19
- data/lib/vanity/connection.rb +12 -14
- data/lib/vanity/experiment/ab_test.rb +82 -70
- data/lib/vanity/experiment/alternative.rb +3 -5
- data/lib/vanity/experiment/base.rb +24 -19
- data/lib/vanity/experiment/bayesian_bandit_score.rb +7 -13
- data/lib/vanity/experiment/definition.rb +6 -6
- data/lib/vanity/frameworks/rails.rb +39 -39
- data/lib/vanity/frameworks.rb +2 -2
- data/lib/vanity/helpers.rb +1 -1
- data/lib/vanity/metric/active_record.rb +21 -19
- data/lib/vanity/metric/base.rb +22 -23
- data/lib/vanity/metric/google_analytics.rb +6 -9
- data/lib/vanity/metric/remote.rb +3 -5
- data/lib/vanity/playground.rb +3 -6
- data/lib/vanity/vanity.rb +8 -12
- data/lib/vanity/version.rb +1 -1
- data/test/adapters/active_record_adapter_test.rb +1 -5
- data/test/adapters/mock_adapter_test.rb +0 -2
- data/test/adapters/mongodb_adapter_test.rb +1 -5
- data/test/adapters/redis_adapter_test.rb +2 -3
- data/test/adapters/shared_tests.rb +9 -12
- data/test/autoconnect_test.rb +3 -3
- data/test/cli_test.rb +0 -1
- data/test/configuration_test.rb +18 -34
- data/test/connection_test.rb +3 -3
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/controllers/use_vanity_controller.rb +12 -8
- data/test/dummy/app/mailers/vanity_mailer.rb +3 -3
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/config/boot.rb +3 -3
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +0 -1
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config.ru +1 -1
- data/test/dummy/script/rails +2 -2
- data/test/experiment/ab_test.rb +148 -154
- data/test/experiment/base_test.rb +48 -32
- data/test/frameworks/rails/action_controller_test.rb +25 -25
- data/test/frameworks/rails/action_mailer_test.rb +2 -2
- data/test/frameworks/rails/action_view_test.rb +5 -6
- data/test/frameworks/rails/rails_test.rb +147 -181
- data/test/helper_test.rb +2 -2
- data/test/metric/active_record_test.rb +174 -212
- data/test/metric/base_test.rb +21 -46
- data/test/metric/google_analytics_test.rb +17 -25
- data/test/metric/remote_test.rb +7 -10
- data/test/playground_test.rb +7 -14
- data/test/templates_test.rb +16 -20
- data/test/test_helper.rb +28 -29
- data/test/vanity_test.rb +4 -10
- data/test/web/rails/dashboard_test.rb +21 -21
- data/vanity.gemspec +8 -7
- metadata +28 -30
- data/gemfiles/rails42.gemfile +0 -33
- data/gemfiles/rails42.gemfile.lock +0 -265
- data/gemfiles/rails42_protected_attributes.gemfile +0 -34
- data/gemfiles/rails42_protected_attributes.gemfile.lock +0 -264
- data/gemfiles/rails51.gemfile +0 -33
- data/gemfiles/rails51.gemfile.lock +0 -285
data/lib/vanity/playground.rb
CHANGED
@@ -81,7 +81,7 @@ module Vanity
|
|
81
81
|
# @deprecated
|
82
82
|
# @see Configuration#add_participant_route=
|
83
83
|
def add_participant_path=(path)
|
84
|
-
Vanity.configuration.add_participant_route=path
|
84
|
+
Vanity.configuration.add_participant_route = path
|
85
85
|
end
|
86
86
|
|
87
87
|
# @since 1.9.0
|
@@ -183,7 +183,6 @@ module Vanity
|
|
183
183
|
experiments[id.to_sym] or raise NoExperimentError, "No experiment #{id}"
|
184
184
|
end
|
185
185
|
|
186
|
-
|
187
186
|
# -- Participant Information --
|
188
187
|
|
189
188
|
# Returns an array of all experiments this participant is involved in, with their assignment.
|
@@ -193,9 +192,7 @@ module Vanity
|
|
193
192
|
participant_array = []
|
194
193
|
experiments.values.sort_by(&:name).each do |e|
|
195
194
|
index = connection.ab_assigned(e.id, participant_id)
|
196
|
-
if index
|
197
|
-
participant_array << [e, e.alternatives[index.to_i]]
|
198
|
-
end
|
195
|
+
participant_array << [e, e.alternatives[index.to_i]] if index
|
199
196
|
end
|
200
197
|
participant_array
|
201
198
|
end
|
@@ -203,7 +200,7 @@ module Vanity
|
|
203
200
|
# @since 1.4.0
|
204
201
|
# @deprecated
|
205
202
|
# @see Vanity::Connection
|
206
|
-
def establish_connection(spec=nil)
|
203
|
+
def establish_connection(spec = nil)
|
207
204
|
disconnect!
|
208
205
|
Vanity.connect!(spec)
|
209
206
|
end
|
data/lib/vanity/vanity.rb
CHANGED
@@ -8,7 +8,7 @@ module Vanity
|
|
8
8
|
#
|
9
9
|
# @see Vanity::Configuration
|
10
10
|
# @since 2.0.0
|
11
|
-
def self.configuration(set_if_needed=true)
|
11
|
+
def self.configuration(set_if_needed = true)
|
12
12
|
if defined?(@configuration) && @configuration
|
13
13
|
@configuration
|
14
14
|
elsif set_if_needed
|
@@ -77,7 +77,7 @@ module Vanity
|
|
77
77
|
# Returns the current connection. Establishes new connection is necessary.
|
78
78
|
#
|
79
79
|
# @since 2.0.0
|
80
|
-
def self.connection(connect_if_needed=true)
|
80
|
+
def self.connection(connect_if_needed = true)
|
81
81
|
if defined?(@connection) && @connection
|
82
82
|
@connection
|
83
83
|
elsif connect_if_needed
|
@@ -91,7 +91,7 @@ module Vanity
|
|
91
91
|
#
|
92
92
|
# @since 2.0.0
|
93
93
|
# @see Vanity::Connection
|
94
|
-
def self.connect!(spec_or_nil=nil)
|
94
|
+
def self.connect!(spec_or_nil = nil)
|
95
95
|
spec_or_nil ||= configuration.connection_params
|
96
96
|
|
97
97
|
# Legacy special config variables permitted in connection spec
|
@@ -100,15 +100,11 @@ module Vanity
|
|
100
100
|
# Legacy redis.yml fallback
|
101
101
|
if spec_or_nil.nil?
|
102
102
|
redis_url = configuration.redis_url_from_file
|
103
|
-
if redis_url
|
104
|
-
spec_or_nil = redis_url
|
105
|
-
end
|
103
|
+
spec_or_nil = redis_url if redis_url
|
106
104
|
end
|
107
105
|
|
108
106
|
# Legacy connection url fallback
|
109
|
-
if configuration.connection_url
|
110
|
-
spec_or_nil = configuration.connection_url
|
111
|
-
end
|
107
|
+
spec_or_nil = configuration.connection_url if configuration.connection_url
|
112
108
|
|
113
109
|
@connection = Connection.new(spec_or_nil)
|
114
110
|
end
|
@@ -117,7 +113,7 @@ module Vanity
|
|
117
113
|
#
|
118
114
|
# @since 2.0.0
|
119
115
|
def self.disconnect!
|
120
|
-
if @connection
|
116
|
+
if @connection # rubocop:todo Style/GuardClause
|
121
117
|
@connection.disconnect!
|
122
118
|
@connection = nil
|
123
119
|
end
|
@@ -135,7 +131,7 @@ module Vanity
|
|
135
131
|
# The playground instance.
|
136
132
|
#
|
137
133
|
# @see Vanity::Playground
|
138
|
-
def self.playground(load_if_needed=true)
|
134
|
+
def self.playground(load_if_needed = true)
|
139
135
|
if @playground
|
140
136
|
@playground
|
141
137
|
elsif load_if_needed
|
@@ -184,4 +180,4 @@ module Vanity
|
|
184
180
|
configuration.collecting = spec_or_nil[:collecting] if spec_or_nil.has_key?(:collecting)
|
185
181
|
end
|
186
182
|
end
|
187
|
-
end
|
183
|
+
end
|
data/lib/vanity/version.rb
CHANGED
@@ -3,7 +3,6 @@ require 'vanity/adapters/active_record_adapter'
|
|
3
3
|
require 'adapters/shared_tests'
|
4
4
|
|
5
5
|
describe Vanity::Adapters::ActiveRecordAdapter do
|
6
|
-
|
7
6
|
def specification
|
8
7
|
Vanity::Connection::Specification.new(VanityTestHelpers::DATABASE_OPTIONS["active_record"])
|
9
8
|
end
|
@@ -12,8 +11,5 @@ describe Vanity::Adapters::ActiveRecordAdapter do
|
|
12
11
|
Vanity::Adapters::ActiveRecordAdapter.new(specification.to_h)
|
13
12
|
end
|
14
13
|
|
15
|
-
if ENV["DB"] == "active_record"
|
16
|
-
include Vanity::Adapters::SharedTests
|
17
|
-
end
|
18
|
-
|
14
|
+
include Vanity::Adapters::SharedTests if ENV["DB"] == "active_record"
|
19
15
|
end
|
@@ -2,7 +2,6 @@ require 'test_helper'
|
|
2
2
|
require 'adapters/shared_tests'
|
3
3
|
|
4
4
|
describe Vanity::Adapters::MockAdapter do
|
5
|
-
|
6
5
|
def specification
|
7
6
|
Vanity::Connection::Specification.new(VanityTestHelpers::DATABASE_OPTIONS["mock"])
|
8
7
|
end
|
@@ -12,5 +11,4 @@ describe Vanity::Adapters::MockAdapter do
|
|
12
11
|
end
|
13
12
|
|
14
13
|
include Vanity::Adapters::SharedTests
|
15
|
-
|
16
14
|
end
|
@@ -3,7 +3,6 @@ require 'vanity/adapters/mongodb_adapter'
|
|
3
3
|
require 'adapters/shared_tests'
|
4
4
|
|
5
5
|
describe Vanity::Adapters::MongodbAdapter do
|
6
|
-
|
7
6
|
def specification
|
8
7
|
Vanity::Connection::Specification.new(VanityTestHelpers::DATABASE_OPTIONS["mongodb"])
|
9
8
|
end
|
@@ -12,8 +11,5 @@ describe Vanity::Adapters::MongodbAdapter do
|
|
12
11
|
Vanity::Adapters::MongodbAdapter.new(specification.to_h)
|
13
12
|
end
|
14
13
|
|
15
|
-
if ENV["DB"] == "mongodb"
|
16
|
-
include Vanity::Adapters::SharedTests
|
17
|
-
end
|
18
|
-
|
14
|
+
include Vanity::Adapters::SharedTests if ENV["DB"] == "mongodb"
|
19
15
|
end
|
@@ -31,14 +31,14 @@ describe Vanity::Adapters::RedisAdapter do
|
|
31
31
|
def stub_redis
|
32
32
|
Vanity.playground.failover_on_datastore_error!
|
33
33
|
mocked_redis = stub("Redis")
|
34
|
-
redis_adapter = Vanity::Adapters::RedisAdapter.new(:
|
34
|
+
redis_adapter = Vanity::Adapters::RedisAdapter.new(redis: mocked_redis)
|
35
35
|
|
36
36
|
[redis_adapter, mocked_redis]
|
37
37
|
end
|
38
38
|
|
39
39
|
it "connects to existing redis" do
|
40
40
|
mocked_redis = stub("Redis")
|
41
|
-
adapter = Vanity::Adapters.redis_connection(:
|
41
|
+
adapter = Vanity::Adapters.redis_connection(redis: mocked_redis)
|
42
42
|
assert_equal mocked_redis, adapter.redis
|
43
43
|
end
|
44
44
|
|
@@ -131,5 +131,4 @@ describe Vanity::Adapters::RedisAdapter do
|
|
131
131
|
redis_adapter.ab_add_conversion("price_options", 0, "3ff62e2fb51f0b22646a342a2d357aec")
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
135
134
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'time'
|
2
2
|
|
3
3
|
module Vanity::Adapters::SharedTests
|
4
|
-
|
5
4
|
DummyAlternative = Struct.new(:id)
|
6
5
|
|
7
6
|
def identity
|
@@ -124,7 +123,7 @@ module Vanity::Adapters::SharedTests
|
|
124
123
|
|
125
124
|
refute(@subject.experiment_persisted?(experiment))
|
126
125
|
assert_equal(
|
127
|
-
{ :
|
126
|
+
{ participants: 0, converted: 0, conversions: 0 },
|
128
127
|
@subject.ab_counts(experiment, alternative)
|
129
128
|
)
|
130
129
|
end
|
@@ -132,13 +131,11 @@ module Vanity::Adapters::SharedTests
|
|
132
131
|
|
133
132
|
describe '#is_experiment_enabled?' do
|
134
133
|
def with_experiments_start_enabled(enabled)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
Vanity.configuration.experiments_start_enabled = original_value
|
141
|
-
end
|
134
|
+
original_value = Vanity.configuration.experiments_start_enabled
|
135
|
+
Vanity.configuration.experiments_start_enabled = enabled
|
136
|
+
yield
|
137
|
+
ensure
|
138
|
+
Vanity.configuration.experiments_start_enabled = original_value
|
142
139
|
end
|
143
140
|
|
144
141
|
describe 'when experiments start enabled' do
|
@@ -193,7 +190,7 @@ module Vanity::Adapters::SharedTests
|
|
193
190
|
@subject.ab_add_conversion(experiment, alternative, identity, 1, true)
|
194
191
|
|
195
192
|
assert_equal(
|
196
|
-
{:
|
193
|
+
{ participants: 1, conversions: 1, converted: 1 },
|
197
194
|
@subject.ab_counts(experiment, alternative)
|
198
195
|
)
|
199
196
|
end
|
@@ -204,7 +201,7 @@ module Vanity::Adapters::SharedTests
|
|
204
201
|
@subject.ab_add_participant(experiment, alternative, identity)
|
205
202
|
|
206
203
|
assert_equal(
|
207
|
-
{:
|
204
|
+
{ participants: 1, conversions: 0, converted: 0 },
|
208
205
|
@subject.ab_counts(experiment, alternative)
|
209
206
|
)
|
210
207
|
end
|
@@ -287,7 +284,7 @@ module Vanity::Adapters::SharedTests
|
|
287
284
|
run_experiment
|
288
285
|
|
289
286
|
assert_equal(
|
290
|
-
{:
|
287
|
+
{ participants: 2, conversions: 2, converted: 1 },
|
291
288
|
@subject.ab_counts(experiment, alternative)
|
292
289
|
)
|
293
290
|
end
|
data/test/autoconnect_test.rb
CHANGED
@@ -15,7 +15,7 @@ describe Vanity::Autoconnect do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns false if in assets:precompile rake task" do
|
18
|
-
Rake.expects(:application).returns(stub(:
|
18
|
+
Rake.expects(:application).returns(stub(top_level_tasks: ['assets:precompile']))
|
19
19
|
autoconnect = Vanity::Autoconnect.should_connect?
|
20
20
|
assert autoconnect == false
|
21
21
|
end
|
@@ -23,8 +23,8 @@ describe Vanity::Autoconnect do
|
|
23
23
|
|
24
24
|
describe ".schema_relevant?" do
|
25
25
|
it "returns true for database tasks" do
|
26
|
-
Rake.expects(:application).returns(stub(:
|
26
|
+
Rake.expects(:application).returns(stub(top_level_tasks: ['db:migrate']))
|
27
27
|
assert_equal true, Vanity::Autoconnect.schema_relevant?
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
data/test/cli_test.rb
CHANGED
data/test/configuration_test.rb
CHANGED
@@ -3,7 +3,7 @@ require "test_helper"
|
|
3
3
|
describe Vanity::Configuration do
|
4
4
|
let(:config) do
|
5
5
|
config = Vanity::Configuration.new
|
6
|
-
config.logger = $logger
|
6
|
+
config.logger = $logger # rubocop:todo Style/GlobalVars
|
7
7
|
config
|
8
8
|
end
|
9
9
|
|
@@ -31,9 +31,7 @@ describe Vanity::Configuration do
|
|
31
31
|
describe "using the default config file & path" do
|
32
32
|
it "returns the connection params" do
|
33
33
|
FileUtils.mkpath "./config"
|
34
|
-
File.
|
35
|
-
f.write VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"]
|
36
|
-
end
|
34
|
+
File.write("./config/vanity.yml", VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"])
|
37
35
|
|
38
36
|
mock_connection_hash = { adapter: "mock" }
|
39
37
|
assert_equal mock_connection_hash, config.connection_params
|
@@ -42,9 +40,7 @@ describe Vanity::Configuration do
|
|
42
40
|
|
43
41
|
it "accepts a file name" do
|
44
42
|
FileUtils.mkpath "./config"
|
45
|
-
File.
|
46
|
-
f.write VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"]
|
47
|
-
end
|
43
|
+
File.write("./config/vanity.yml", VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"])
|
48
44
|
|
49
45
|
mock_connection_hash = { adapter: "mock" }
|
50
46
|
assert_equal mock_connection_hash, config.connection_params("vanity.yml")
|
@@ -52,9 +48,7 @@ describe Vanity::Configuration do
|
|
52
48
|
|
53
49
|
it "returns connection strings" do
|
54
50
|
FileUtils.mkpath "./config"
|
55
|
-
File.
|
56
|
-
f.write VanityTestHelpers::VANITY_CONFIGS["redis.yml.url"]
|
57
|
-
end
|
51
|
+
File.write("./config/redis.yml", VanityTestHelpers::VANITY_CONFIGS["redis.yml.url"])
|
58
52
|
|
59
53
|
mock_connection_string = "localhost:6379/15"
|
60
54
|
assert_equal mock_connection_string, config.connection_params("redis.yml")
|
@@ -64,9 +58,7 @@ describe Vanity::Configuration do
|
|
64
58
|
connection_config = VanityTestHelpers::VANITY_CONFIGS["vanity.yml.redis"]
|
65
59
|
|
66
60
|
FileUtils.mkpath "./config"
|
67
|
-
File.
|
68
|
-
f.write(connection_config)
|
69
|
-
end
|
61
|
+
File.write("./config/vanity.yml", connection_config)
|
70
62
|
|
71
63
|
assert_equal "redis://:p4ssw0rd@10.0.1.1:6380/15", config.connection_url
|
72
64
|
end
|
@@ -76,9 +68,7 @@ describe Vanity::Configuration do
|
|
76
68
|
ENV["VANITY_TEST_REDIS_URL"] = "redis://:p4ssw0rd@10.0.1.1:6380/15"
|
77
69
|
|
78
70
|
FileUtils.mkpath "./config"
|
79
|
-
File.
|
80
|
-
f.write(connection_config)
|
81
|
-
end
|
71
|
+
File.write("./config/vanity.yml", connection_config)
|
82
72
|
|
83
73
|
connection_hash = { adapter: "redis", url: "redis://:p4ssw0rd@10.0.1.1:6380/15" }
|
84
74
|
assert_equal connection_hash, config.connection_params
|
@@ -91,21 +81,17 @@ describe Vanity::Configuration do
|
|
91
81
|
|
92
82
|
it "raises an error if the environment isn't configured" do
|
93
83
|
FileUtils.mkpath "./config"
|
94
|
-
File.
|
95
|
-
f.write VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"]
|
96
|
-
end
|
84
|
+
File.write("./config/vanity.yml", VanityTestHelpers::VANITY_CONFIGS["vanity.yml.mock"])
|
97
85
|
|
98
86
|
config.environment = "staging"
|
99
|
-
assert_raises(Vanity::Configuration::MissingEnvironment)
|
87
|
+
assert_raises(Vanity::Configuration::MissingEnvironment) do
|
100
88
|
config.connection_params
|
101
|
-
|
89
|
+
end
|
102
90
|
end
|
103
91
|
|
104
92
|
it "symbolizes hash keys" do
|
105
93
|
FileUtils.mkpath "./config"
|
106
|
-
File.
|
107
|
-
f.write VanityTestHelpers::VANITY_CONFIGS["vanity.yml.activerecord"]
|
108
|
-
end
|
94
|
+
File.write("./config/vanity.yml", VanityTestHelpers::VANITY_CONFIGS["vanity.yml.activerecord"])
|
109
95
|
|
110
96
|
ar_connection_values = [:adapter, :active_record_adapter]
|
111
97
|
assert_equal ar_connection_values, config.connection_params.keys
|
@@ -114,18 +100,16 @@ describe Vanity::Configuration do
|
|
114
100
|
|
115
101
|
describe "setup_locales" do
|
116
102
|
it "adds vanity locales to the I18n gem" do
|
117
|
-
|
118
|
-
original_load_path = I18n.load_path
|
103
|
+
original_load_path = I18n.load_path
|
119
104
|
|
120
|
-
|
105
|
+
config.setup_locales
|
121
106
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
107
|
+
assert_includes(
|
108
|
+
I18n.load_path,
|
109
|
+
File.expand_path(File.join(__FILE__, '..', '..', 'lib/vanity/locales/vanity.en.yml'))
|
110
|
+
)
|
111
|
+
ensure
|
112
|
+
I18n.load_path = original_load_path
|
129
113
|
end
|
130
114
|
end
|
131
115
|
end
|
data/test/connection_test.rb
CHANGED
@@ -32,9 +32,9 @@ describe Vanity::Connection do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "raises an error for invalid specification hashes" do
|
35
|
-
assert_raises(Vanity::Connection::InvalidSpecification)
|
35
|
+
assert_raises(Vanity::Connection::InvalidSpecification) do
|
36
36
|
Vanity::Connection.new("adapter" => "mock")
|
37
|
-
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
it "allows a redis connection to be specified" do
|
@@ -43,4 +43,4 @@ describe Vanity::Connection do
|
|
43
43
|
Vanity::Connection.new(redis: redis)
|
44
44
|
end
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
data/test/dummy/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('config/application', __dir__)
|
5
5
|
require 'rake'
|
6
6
|
|
7
7
|
Dummy::Application.load_tasks
|
@@ -9,30 +9,34 @@ class UseVanityController < ActionController::Base
|
|
9
9
|
|
10
10
|
def index
|
11
11
|
text = Vanity.ab_test(:pie_or_cake)
|
12
|
-
render :
|
12
|
+
render plain: text, text: text
|
13
13
|
end
|
14
14
|
|
15
15
|
def js
|
16
16
|
Vanity.ab_test(:pie_or_cake)
|
17
|
-
render :
|
17
|
+
render inline: "<%= vanity_js -%>"
|
18
18
|
end
|
19
19
|
|
20
20
|
def view_helper_ab_test_js
|
21
|
-
|
21
|
+
# rubocop:todo Naming/HeredocDelimiterNaming
|
22
|
+
render inline: <<-EOS
|
22
23
|
<% ab_test(:pie_or_cake) %>
|
23
24
|
<%= vanity_js -%>
|
24
|
-
EOS
|
25
|
+
EOS
|
26
|
+
# rubocop:enable Naming/HeredocDelimiterNaming
|
25
27
|
end
|
26
28
|
|
27
29
|
def global_ab_test_js
|
28
|
-
|
30
|
+
# rubocop:todo Naming/HeredocDelimiterNaming
|
31
|
+
render inline: <<-EOS
|
29
32
|
<% Vanity.ab_test(:pie_or_cake) %>
|
30
33
|
<%= vanity_js -%>
|
31
|
-
EOS
|
34
|
+
EOS
|
35
|
+
# rubocop:enable Naming/HeredocDelimiterNaming
|
32
36
|
end
|
33
37
|
|
34
38
|
def model_js
|
35
39
|
TestModel.new.test_method
|
36
|
-
render :
|
40
|
+
render inline: "<%= vanity_js -%>"
|
37
41
|
end
|
38
|
-
end
|
42
|
+
end
|
@@ -6,16 +6,16 @@ class VanityMailer < ActionMailer::Base
|
|
6
6
|
def ab_test_subject(user)
|
7
7
|
use_vanity_mailer user
|
8
8
|
|
9
|
-
mail :
|
9
|
+
mail subject: ab_test(:pie_or_cake).to_s, body: ""
|
10
10
|
end
|
11
11
|
|
12
12
|
def ab_test_content(user)
|
13
13
|
use_vanity_mailer user
|
14
14
|
|
15
|
-
image_html = view_context.vanity_tracking_image(Vanity.context.vanity_identity, :open, :
|
15
|
+
image_html = view_context.vanity_tracking_image(Vanity.context.vanity_identity, :open, host: "127.0.0.1:3000")
|
16
16
|
|
17
17
|
mail do |format|
|
18
|
-
format.html { render :
|
18
|
+
format.html { render html: image_html.html_safe }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
# Set up gems listed in the Gemfile.
|
4
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
5
5
|
|
6
|
-
require 'bundler/setup' if File.
|
6
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
7
7
|
|
8
|
-
$:.unshift File.expand_path('
|
8
|
+
$:.unshift File.expand_path('../../../lib', __dir__)
|
@@ -18,7 +18,7 @@ Dummy::Application.configure do
|
|
18
18
|
config.action_dispatch.show_exceptions = false
|
19
19
|
|
20
20
|
# Disable request forgery protection in test environment
|
21
|
-
config.action_controller.allow_forgery_protection
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
22
|
|
23
23
|
# Tell Action Mailer not to deliver emails to the real world.
|
24
24
|
# The :test delivery method accumulates sent emails in the
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
Dummy::Application.config.session_store :cookie_store, :
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
4
|
|
5
5
|
# Use the database for sessions instead of the cookie-based default,
|
6
6
|
# which shouldn't be used to store highly confidential information
|
data/test/dummy/config.ru
CHANGED
data/test/dummy/script/rails
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
3
|
|
4
|
-
APP_PATH = File.expand_path('
|
5
|
-
require File.expand_path('
|
4
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
5
|
+
require File.expand_path('../config/boot', __dir__)
|
6
6
|
require 'rails/commands'
|