vanity 3.1.0 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +28 -0
  3. data/.github/workflows/test.yml +3 -6
  4. data/.rubocop.yml +114 -0
  5. data/.rubocop_todo.yml +67 -0
  6. data/Appraisals +9 -31
  7. data/CHANGELOG +15 -0
  8. data/Gemfile +7 -3
  9. data/Gemfile.lock +35 -7
  10. data/README.md +4 -9
  11. data/Rakefile +25 -24
  12. data/bin/vanity +1 -1
  13. data/doc/configuring.textile +1 -0
  14. data/gemfiles/rails52.gemfile +6 -3
  15. data/gemfiles/rails52.gemfile.lock +36 -11
  16. data/gemfiles/rails60.gemfile +6 -3
  17. data/gemfiles/rails60.gemfile.lock +36 -11
  18. data/gemfiles/rails61.gemfile +6 -3
  19. data/gemfiles/rails61.gemfile.lock +36 -11
  20. data/lib/generators/vanity/migration_generator.rb +5 -7
  21. data/lib/vanity/adapters/abstract_adapter.rb +43 -45
  22. data/lib/vanity/adapters/active_record_adapter.rb +30 -30
  23. data/lib/vanity/adapters/mock_adapter.rb +14 -18
  24. data/lib/vanity/adapters/mongodb_adapter.rb +73 -69
  25. data/lib/vanity/adapters/redis_adapter.rb +26 -28
  26. data/lib/vanity/adapters.rb +1 -1
  27. data/lib/vanity/autoconnect.rb +6 -7
  28. data/lib/vanity/commands/list.rb +7 -7
  29. data/lib/vanity/commands/report.rb +18 -22
  30. data/lib/vanity/configuration.rb +19 -19
  31. data/lib/vanity/connection.rb +12 -14
  32. data/lib/vanity/experiment/ab_test.rb +82 -70
  33. data/lib/vanity/experiment/alternative.rb +3 -5
  34. data/lib/vanity/experiment/base.rb +24 -19
  35. data/lib/vanity/experiment/bayesian_bandit_score.rb +7 -13
  36. data/lib/vanity/experiment/definition.rb +6 -6
  37. data/lib/vanity/frameworks/rails.rb +39 -39
  38. data/lib/vanity/frameworks.rb +2 -2
  39. data/lib/vanity/helpers.rb +1 -1
  40. data/lib/vanity/metric/active_record.rb +21 -19
  41. data/lib/vanity/metric/base.rb +22 -23
  42. data/lib/vanity/metric/google_analytics.rb +6 -9
  43. data/lib/vanity/metric/remote.rb +3 -5
  44. data/lib/vanity/playground.rb +3 -6
  45. data/lib/vanity/vanity.rb +8 -12
  46. data/lib/vanity/version.rb +1 -1
  47. data/test/adapters/active_record_adapter_test.rb +1 -5
  48. data/test/adapters/mock_adapter_test.rb +0 -2
  49. data/test/adapters/mongodb_adapter_test.rb +1 -5
  50. data/test/adapters/redis_adapter_test.rb +3 -4
  51. data/test/adapters/shared_tests.rb +9 -12
  52. data/test/autoconnect_test.rb +3 -3
  53. data/test/cli_test.rb +0 -1
  54. data/test/configuration_test.rb +18 -34
  55. data/test/connection_test.rb +3 -3
  56. data/test/dummy/Rakefile +1 -1
  57. data/test/dummy/app/controllers/use_vanity_controller.rb +12 -8
  58. data/test/dummy/app/mailers/vanity_mailer.rb +3 -3
  59. data/test/dummy/config/application.rb +1 -1
  60. data/test/dummy/config/boot.rb +3 -3
  61. data/test/dummy/config/environment.rb +1 -1
  62. data/test/dummy/config/environments/development.rb +0 -1
  63. data/test/dummy/config/environments/test.rb +1 -1
  64. data/test/dummy/config/initializers/session_store.rb +1 -1
  65. data/test/dummy/config/initializers/vanity.rb +3 -0
  66. data/test/dummy/config/vanity.yml +7 -0
  67. data/test/dummy/config.ru +1 -1
  68. data/test/dummy/script/rails +2 -2
  69. data/test/experiment/ab_test.rb +148 -154
  70. data/test/experiment/base_test.rb +48 -32
  71. data/test/frameworks/rails/action_controller_test.rb +25 -25
  72. data/test/frameworks/rails/action_mailer_test.rb +2 -2
  73. data/test/frameworks/rails/action_view_test.rb +5 -6
  74. data/test/frameworks/rails/rails_test.rb +147 -181
  75. data/test/helper_test.rb +2 -2
  76. data/test/metric/active_record_test.rb +174 -212
  77. data/test/metric/base_test.rb +21 -46
  78. data/test/metric/google_analytics_test.rb +17 -25
  79. data/test/metric/remote_test.rb +7 -10
  80. data/test/playground_test.rb +7 -14
  81. data/test/templates_test.rb +16 -20
  82. data/test/test_helper.rb +28 -29
  83. data/test/vanity_test.rb +4 -10
  84. data/test/web/rails/dashboard_test.rb +21 -21
  85. data/vanity.gemspec +8 -7
  86. metadata +32 -30
  87. data/gemfiles/rails42.gemfile +0 -33
  88. data/gemfiles/rails42.gemfile.lock +0 -265
  89. data/gemfiles/rails42_protected_attributes.gemfile +0 -34
  90. data/gemfiles/rails42_protected_attributes.gemfile.lock +0 -264
  91. data/gemfiles/rails51.gemfile +0 -33
  92. data/gemfiles/rails51.gemfile.lock +0 -285
@@ -1,7 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "Metric via playground" do
4
-
5
4
  it "knows all loaded metrics" do
6
5
  metric "Yawns/sec", "Cheers/sec"
7
6
  assert Vanity.playground.metrics.keys.include?(:yawns_sec)
@@ -9,34 +8,28 @@ describe "Metric via playground" do
9
8
  end
10
9
 
11
10
  it "loads metric definitions" do
12
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
13
- f.write <<-RUBY
11
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
14
12
  metric "Yawns/sec" do
15
13
  def xmts
16
14
  "x"
17
15
  end
18
16
  end
19
- RUBY
20
- end
17
+ RUBY
21
18
  assert_equal "x", Vanity.playground.metric(:yawns_sec).xmts
22
19
  end
23
20
 
24
21
  it "bubbles up loaded metrics" do
25
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
26
- f.write "fail 'yawn!'"
27
- end
22
+ File.write("tmp/experiments/metrics/yawns_sec.rb", "fail 'yawn!'")
28
23
  assert_raises NameError do
29
24
  Vanity.playground.metric(:yawns_sec)
30
25
  end
31
26
  end
32
27
 
33
28
  it "map identifier from file name" do
34
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
35
- f.write <<-RUBY
29
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
36
30
  metric "yawns/hour" do
37
31
  end
38
- RUBY
39
- end
32
+ RUBY
40
33
  assert Vanity.playground.metric(:yawns_sec)
41
34
  end
42
35
 
@@ -64,19 +57,16 @@ describe "Metric via playground" do
64
57
  end
65
58
 
66
59
  it "bootstraps the metric" do
67
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
68
- f.write <<-RUBY
60
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
69
61
  metric "yawns/hour" do
70
62
  end
71
- RUBY
72
- end
63
+ RUBY
73
64
  Vanity.playground.track!(:yawns_sec)
74
65
  Vanity.playground.track!(:yawns_sec)
75
66
  assert Vanity.playground.connection.get_metric_last_update_at(:yawns_sec)
76
67
  end
77
68
  end
78
69
 
79
-
80
70
  describe "Metric tracking" do
81
71
  it "disabled when metrics are disabled" do
82
72
  not_collecting!
@@ -100,7 +90,7 @@ describe "Metric tracking" do
100
90
  Timecop.freeze((today - 2).to_time) { 2.times { Vanity.playground.track! :yawns_sec } }
101
91
  1.times { Vanity.playground.track! :yawns_sec }
102
92
  boredom = Vanity.playground.metric(:yawns_sec).values(today - 5, today)
103
- assert_equal [0,4,0,2,0,1], boredom
93
+ assert_equal [0, 4, 0, 2, 0, 1], boredom
104
94
  end
105
95
 
106
96
  it "with no value" do
@@ -117,7 +107,7 @@ describe "Metric tracking" do
117
107
  Timecop.freeze((today - 2).to_time) { Vanity.playground.track! :yawns_sec, 2 }
118
108
  Vanity.playground.track! :yawns_sec
119
109
  boredom = Vanity.playground.metric(:yawns_sec).values(today - 5, today)
120
- assert_equal [0,4,0,2,0,1], boredom
110
+ assert_equal [0, 4, 0, 2, 0, 1], boredom
121
111
  end
122
112
 
123
113
  it "runs hook" do
@@ -136,7 +126,7 @@ describe "Metric tracking" do
136
126
  not_collecting!
137
127
  metric "Many Happy Returns"
138
128
  total = 0
139
- Vanity.playground.metric(:many_happy_returns).hook do |metric_id, timestamp, count|
129
+ Vanity.playground.metric(:many_happy_returns).hook do |_metric_id, _timestamp, count|
140
130
  total += count
141
131
  end
142
132
  Vanity.playground.track! :many_happy_returns, 6
@@ -162,39 +152,31 @@ describe "Metric tracking" do
162
152
  end
163
153
  end
164
154
 
165
-
166
155
  describe "Metric name" do
167
156
  it "can be whatever" do
168
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
169
- f.write <<-RUBY
157
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
170
158
  metric "Yawns per second" do
171
159
  end
172
- RUBY
173
- end
160
+ RUBY
174
161
  assert_equal "Yawns per second", Vanity.playground.metric(:yawns_sec).name
175
162
  end
176
163
  end
177
164
 
178
-
179
165
  describe "Metric description" do
180
166
  it "metric with description" do
181
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
182
- f.write <<-RUBY
167
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
183
168
  metric "Yawns/sec" do
184
169
  description "Am I that boring?"
185
170
  end
186
- RUBY
187
- end
171
+ RUBY
188
172
  assert_equal "Am I that boring?", Vanity::Metric.description(Vanity.playground.metric(:yawns_sec))
189
173
  end
190
174
 
191
175
  it "metric without description" do
192
- File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
193
- f.write <<-RUBY
176
+ File.write("tmp/experiments/metrics/yawns_sec.rb", <<-RUBY)
194
177
  metric "Yawns/sec" do
195
178
  end
196
- RUBY
197
- end
179
+ RUBY
198
180
  assert_nil Vanity::Metric.description(Vanity.playground.metric(:yawns_sec))
199
181
  end
200
182
 
@@ -204,19 +186,16 @@ describe "Metric description" do
204
186
  end
205
187
  end
206
188
 
207
-
208
189
  describe "Metric bounds" do
209
190
  it "metric with bounds" do
210
- File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
211
- f.write <<-RUBY
191
+ File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
212
192
  metric "Sky is limit" do
213
193
  def bounds
214
194
  [6,12]
215
195
  end
216
196
  end
217
- RUBY
218
- end
219
- assert_equal [6,12], Vanity::Metric.bounds(Vanity.playground.metric(:sky_is_limit))
197
+ RUBY
198
+ assert_equal [6, 12], Vanity::Metric.bounds(Vanity.playground.metric(:sky_is_limit))
220
199
  end
221
200
 
222
201
  it "metric without bounds" do
@@ -230,7 +209,6 @@ describe "Metric bounds" do
230
209
  end
231
210
  end
232
211
 
233
-
234
212
  describe "Metric last_update_at" do
235
213
  it "for new metric" do
236
214
  metric "Coolness"
@@ -249,7 +227,6 @@ describe "Metric last_update_at" do
249
227
  end
250
228
  end
251
229
 
252
-
253
230
  describe "Metric data" do
254
231
  it "explicit dates" do
255
232
  metric "Yawns/sec"
@@ -287,15 +264,13 @@ describe "Metric data" do
287
264
  end
288
265
 
289
266
  it "using custom values method" do
290
- File.open "tmp/experiments/metrics/hours_in_day.rb", "w" do |f|
291
- f.write <<-RUBY
267
+ File.write("tmp/experiments/metrics/hours_in_day.rb", <<-RUBY)
292
268
  metric "Hours in day" do
293
269
  def values(from, to)
294
270
  (from..to).map { |d| 24 }
295
271
  end
296
272
  end
297
- RUBY
298
- end
273
+ RUBY
299
274
  data = Vanity::Metric.data(Vanity.playground.metric(:hours_in_day))
300
275
  assert_equal [24] * 90, data.map(&:last)
301
276
  end
@@ -2,27 +2,23 @@ require "test_helper"
2
2
 
3
3
  describe "Google Analytics" do
4
4
  before do
5
- File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
6
- f.write <<-RUBY
5
+ File.write("tmp/experiments/metrics/ga.rb", <<-RUBY)
7
6
  metric "GA" do
8
7
  google_analytics "UA2"
9
8
  end
10
- RUBY
11
- end
9
+ RUBY
12
10
  end
13
11
 
14
- GA_RESULT = Struct.new(:date, :pageviews, :visits)
15
- GA_PROFILE = Struct.new(:web_property_id)
12
+ GA_RESULT = Struct.new(:date, :pageviews, :visits) # rubocop:todo Lint/ConstantDefinitionInBlock
13
+ GA_PROFILE = Struct.new(:web_property_id) # rubocop:todo Lint/ConstantDefinitionInBlock
16
14
 
17
15
  it "fail if Garb not available" do
18
- File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
19
- f.write <<-RUBY
16
+ File.write("tmp/experiments/metrics/ga.rb", <<-RUBY)
20
17
  metric "GA" do
21
18
  expects(:require).raises LoadError
22
19
  google_analytics "UA2"
23
20
  end
24
- RUBY
25
- end
21
+ RUBY
26
22
  assert_raises LoadError do
27
23
  Vanity.playground.metrics
28
24
  end
@@ -45,13 +41,11 @@ describe "Google Analytics" do
45
41
  end
46
42
 
47
43
  it "accept other metrics" do
48
- File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
49
- f.write <<-RUBY
44
+ File.write("tmp/experiments/metrics/ga.rb", <<-RUBY)
50
45
  metric "GA" do
51
46
  google_analytics "UA2", :visitors
52
47
  end
53
- RUBY
54
- end
48
+ RUBY
55
49
  Vanity.playground.metrics
56
50
  assert_equal [:visitors], metric(:ga).report.metrics.elements
57
51
  end
@@ -67,35 +61,33 @@ describe "Google Analytics" do
67
61
  Vanity.playground.metrics
68
62
  Garb::Profile.expects(:all).returns(Array.new(3) { |i| GA_PROFILE.new("UA#{i + 1}") })
69
63
  metric(:ga).report.stubs(:send_request_for_body).returns(nil)
70
- Garb::ReportResponse.stubs(:new).returns(mock(:results=>[]))
64
+ Garb::ReportResponse.stubs(:new).returns(mock(results: []))
71
65
  metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
72
66
  assert_equal "UA2", metric(:ga).report.profile.web_property_id
73
67
  end
74
68
 
75
69
  it "should map results from report" do
76
70
  Vanity.playground.metrics
77
- today = Date.today
78
- response = mock(:results=>Array.new(3) { |i| GA_RESULT.new("2010021#{i}", i + 1) })
71
+ today = Date.today # rubocop:todo Lint/UselessAssignment
72
+ response = mock(results: Array.new(3) { |i| GA_RESULT.new("2010021#{i}", i + 1) })
79
73
  Garb::Profile.stubs(:all).returns([])
80
74
  Garb::ReportResponse.expects(:new).returns(response)
81
75
  metric(:ga).report.stubs(:send_request_for_body).returns(nil)
82
- assert_equal [1,2,3], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
76
+ assert_equal [1, 2, 3], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
83
77
  end
84
78
 
85
79
  it "mapping GA metrics to single value" do
86
- File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
87
- f.write <<-RUBY
80
+ File.write("tmp/experiments/metrics/ga.rb", <<-RUBY)
88
81
  metric "GA" do
89
82
  google_analytics "UA2", :mapper=>lambda { |e| e.pageviews * e.visits }
90
83
  end
91
- RUBY
92
- end
84
+ RUBY
93
85
  Vanity.playground.metrics
94
- today = Date.today
95
- response = mock(:results=>Array.new(3) { |i| GA_RESULT.new("2010021#{i}", i + 1, i + 1) })
86
+ today = Date.today # rubocop:todo Lint/UselessAssignment
87
+ response = mock(results: Array.new(3) { |i| GA_RESULT.new("2010021#{i}", i + 1, i + 1) })
96
88
  Garb::Profile.stubs(:all).returns([])
97
89
  Garb::ReportResponse.expects(:new).returns(response)
98
90
  metric(:ga).report.stubs(:send_request_for_body).returns(nil)
99
- assert_equal [1,4,9], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
91
+ assert_equal [1, 4, 9], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
100
92
  end
101
93
  end
@@ -2,13 +2,11 @@ require "test_helper"
2
2
 
3
3
  describe "Remote metrics" do
4
4
  before do
5
- File.open "tmp/experiments/metrics/sandbox.rb", "w" do |f|
6
- f.write <<-RUBY
5
+ File.write("tmp/experiments/metrics/sandbox.rb", <<-RUBY)
7
6
  metric "Sandbox" do
8
7
  remote "http://api.vanitydash.com/metrics/sandbox"
9
8
  end
10
- RUBY
11
- end
9
+ RUBY
12
10
 
13
11
  Dir.chdir "tmp" do
14
12
  Vanity.playground.load!
@@ -28,7 +26,6 @@ describe "Remote metrics" do
28
26
  end
29
27
  end
30
28
 
31
-
32
29
  describe "Remote send" do
33
30
  before do
34
31
  @metric = Vanity::Metric.new(Vanity.playground, :sandbox)
@@ -40,7 +37,7 @@ describe "Remote send" do
40
37
  it "remote send in sequence" do
41
38
  Vanity.playground.track! :sandbox
42
39
  Vanity.playground.track! :sandbox
43
- assert_requested(:post, "http://api.vanitydash.com/metrics/sandbox", :times=>2)
40
+ assert_requested(:post, "http://api.vanitydash.com/metrics/sandbox", times: 2)
44
41
  end
45
42
 
46
43
  it "remote sends url-encoded data" do
@@ -59,7 +56,7 @@ describe "Remote send" do
59
56
  end
60
57
 
61
58
  it "remote sends array of values" do
62
- Vanity.playground.track! :sandbox, [1,2,3]
59
+ Vanity.playground.track! :sandbox, [1, 2, 3]
63
60
  assert_requested(:post, /api/) { |request| Rack::Utils.parse_query(request.body)["values[]"] == %w{1 2 3} }
64
61
  end
65
62
 
@@ -90,7 +87,7 @@ describe "Remote send" do
90
87
  Vanity.playground.track! :sandbox
91
88
  stub_request(:post, /api/)
92
89
  Vanity.playground.track! :sandbox
93
- assert_requested(:post, /api/, :times=>2)
90
+ assert_requested(:post, /api/, times: 2)
94
91
  end
95
92
 
96
93
  it "remote send handles timeout error" do
@@ -98,13 +95,13 @@ describe "Remote send" do
98
95
  Vanity.playground.track! :sandbox
99
96
  stub_request(:post, /api/)
100
97
  Vanity.playground.track! :sandbox
101
- assert_requested(:post, /api/, :times=>2)
98
+ assert_requested(:post, /api/, times: 2)
102
99
  end
103
100
 
104
101
  it "remote does not send when metrics disabled" do
105
102
  not_collecting!
106
103
  Vanity.playground.track! :sandbox
107
104
  Vanity.playground.track! :sandbox
108
- assert_requested(:post, /api/, :times=>0)
105
+ assert_requested(:post, /api/, times: 0)
109
106
  end
110
107
  end
@@ -1,28 +1,23 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe Vanity::Playground do
4
-
5
4
  it "has one global instance" do
6
5
  assert instance = Vanity.playground
7
6
  assert_equal instance, Vanity.playground
8
7
  end
9
8
 
10
9
  it "creates metrics hooks on initialization for tracking" do
11
- File.open "tmp/experiments/metrics/coolness.rb", "w" do |f|
12
- f.write <<-RUBY
10
+ File.write("tmp/experiments/metrics/coolness.rb", <<-RUBY)
13
11
  metric "coolness" do
14
12
  end
15
- RUBY
16
- end
13
+ RUBY
17
14
 
18
- File.open "tmp/experiments/foobar.rb", "w" do |f|
19
- f.write <<-RUBY
15
+ File.write("tmp/experiments/foobar.rb", <<-RUBY)
20
16
  ab_test :foobar do
21
17
  metrics :coolness
22
18
  default false
23
19
  end
24
- RUBY
25
- end
20
+ RUBY
26
21
 
27
22
  # new_ab_test :foobar do
28
23
  # alternatives "foo", "bar"
@@ -56,7 +51,7 @@ describe Vanity::Playground do
56
51
  proc = Vanity.playground.on_datastore_error
57
52
  assert proc.respond_to?(:call)
58
53
  assert_silent do
59
- proc.call(Exception.new("datastore error"), self.class, caller[0][/`.*'/][1..-2], [1, 2, 3])
54
+ proc.call(Exception.new("datastore error"), self.class, caller(1..1).first[/`.*'/][1..-2], [1, 2, 3])
60
55
  end
61
56
  end
62
57
  end
@@ -105,12 +100,10 @@ describe Vanity::Playground do
105
100
 
106
101
  describe "#experiments" do
107
102
  it "saves experiments exactly once" do
108
- File.open "tmp/experiments/foobar.rb", "w" do |f|
109
- f.write <<-RUBY
103
+ File.write("tmp/experiments/foobar.rb", <<-RUBY)
110
104
  ab_test :foobar do
111
105
  end
112
- RUBY
113
- end
106
+ RUBY
114
107
  Vanity::Experiment::AbTest.any_instance.expects(:save).once
115
108
  Vanity.playground.experiments
116
109
  end
@@ -7,7 +7,7 @@ describe Vanity::Templates do
7
7
 
8
8
  describe "template" do
9
9
  it "resolves templates from the configured path" do
10
- custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
10
+ custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity')) # rubocop:todo Lint/UselessAssignment
11
11
  gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
12
12
  expected = File.join(gem_view_path, 'foo.html')
13
13
 
@@ -15,33 +15,29 @@ describe Vanity::Templates do
15
15
  end
16
16
 
17
17
  it "resolves templates from a Rails view directory when configured" do
18
- begin
19
- custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
20
- Vanity.configuration.templates_path = custom_view_path
18
+ custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
19
+ Vanity.configuration.templates_path = custom_view_path
21
20
 
22
- expected = File.expand_path(File.join(custom_view_path, 'foo.html'))
21
+ expected = File.expand_path(File.join(custom_view_path, 'foo.html'))
23
22
 
24
- FileUtils.mkpath(custom_view_path)
25
- File.open(expected, "w")
23
+ FileUtils.mkpath(custom_view_path)
24
+ File.open(expected, "w")
26
25
 
27
- assert_equal expected, Vanity::Templates.new.path('foo.html')
28
- ensure
29
- FileUtils.rm_rf(custom_view_path)
30
- end
26
+ assert_equal expected, Vanity::Templates.new.path('foo.html')
27
+ ensure
28
+ FileUtils.rm_rf(custom_view_path)
31
29
  end
32
30
 
33
31
  it "ignores an empty view directory" do
34
- begin
35
- custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
36
- FileUtils.mkpath(custom_view_path)
32
+ custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
33
+ FileUtils.mkpath(custom_view_path)
37
34
 
38
- gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
39
- expected = File.join(gem_view_path, 'foo.html')
35
+ gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
36
+ expected = File.join(gem_view_path, 'foo.html')
40
37
 
41
- assert_equal expected, Vanity::Templates.new.path('foo.html')
42
- ensure
43
- FileUtils.rm_rf(custom_view_path)
44
- end
38
+ assert_equal expected, Vanity::Templates.new.path('foo.html')
39
+ ensure
40
+ FileUtils.rm_rf(custom_view_path)
45
41
  end
46
42
  end
47
43
  end
data/test/test_helper.rb CHANGED
@@ -12,10 +12,10 @@ require "active_record"
12
12
 
13
13
  begin
14
14
  require "rails"
15
- rescue LoadError
15
+ rescue LoadError # rubocop:todo Lint/SuppressedException
16
16
  end
17
17
 
18
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
18
+ require File.expand_path('dummy/config/environment.rb', __dir__)
19
19
  require "rails/test_help"
20
20
 
21
21
  require "vanity"
@@ -27,16 +27,16 @@ require "webmock/minitest"
27
27
  # Due to load order differences in Rails boot and test requires we have to
28
28
  # manually require these
29
29
 
30
- # TODO wonder if we can load rails only for the rails tests...
30
+ # TODO: wonder if we can load rails only for the rails tests...
31
31
  require 'vanity/frameworks/rails'
32
32
  Vanity::Rails.load!
33
33
 
34
34
  if $DEBUG
35
- $logger = Logger.new(STDOUT)
36
- $logger.level = Logger::DEBUG
35
+ $logger = Logger.new(STDOUT) # rubocop:todo Style/GlobalVars
36
+ $logger.level = Logger::DEBUG # rubocop:todo Style/GlobalVars
37
37
  else
38
- $logger = Logger.new(STDOUT)
39
- $logger.level = Logger::FATAL
38
+ $logger = Logger.new(STDOUT) # rubocop:todo Style/GlobalVars
39
+ $logger.level = Logger::FATAL # rubocop:todo Style/GlobalVars
40
40
  end
41
41
 
42
42
  module VanityTestHelpers
@@ -46,13 +46,13 @@ module VanityTestHelpers
46
46
  DATABASE_OPTIONS = {
47
47
  "redis" => "redis://localhost/15",
48
48
  "mongodb" => "mongodb://localhost/vanity",
49
- "active_record" => { :adapter => "active_record", :active_record_adapter =>"default" },
50
- "mock" => "mock:/"
49
+ "active_record" => { adapter: "active_record", active_record_adapter: "default" },
50
+ "mock" => "mock:/",
51
51
  }
52
52
 
53
- DATABASE = DATABASE_OPTIONS[ENV["DB"]] or raise "No support yet for #{ENV["DB"]}"
53
+ DATABASE = DATABASE_OPTIONS[ENV["DB"]] or raise "No support yet for #{ENV['DB']}"
54
54
 
55
- TEST_DATA_FILES = Dir[File.expand_path("../data/*", __FILE__)]
55
+ TEST_DATA_FILES = Dir[File.expand_path('data/*', __dir__)]
56
56
  VANITY_CONFIGS = TEST_DATA_FILES.each.with_object({}) do |path, hash|
57
57
  hash[File.basename(path)] = File.read(path)
58
58
  end
@@ -73,7 +73,7 @@ module VanityTestHelpers
73
73
  # or reload an experiment (saved by the previous playground).
74
74
  def vanity_reset
75
75
  Vanity.reset!
76
- Vanity.configuration.logger = $logger
76
+ Vanity.configuration.logger = $logger # rubocop:todo Style/GlobalVars
77
77
  Vanity.configuration.experiments_path = "tmp/experiments"
78
78
 
79
79
  Vanity.disconnect!
@@ -99,7 +99,6 @@ module VanityTestHelpers
99
99
  Vanity.connect!(DATABASE)
100
100
  end
101
101
 
102
-
103
102
  # Defines the specified metrics (one or more names). Returns metric, or array
104
103
  # of metric (if more than one argument).
105
104
  def metric(*names)
@@ -144,9 +143,9 @@ module VanityTestHelpers
144
143
  def dummy_request
145
144
  # Rails 5 compatibility
146
145
  if ActionDispatch::TestRequest.respond_to?(:create)
147
- ActionDispatch::TestRequest.create()
146
+ ActionDispatch::TestRequest.create
148
147
  else
149
- ActionDispatch::TestRequest.new()
148
+ ActionDispatch::TestRequest.new
150
149
  end
151
150
  end
152
151
 
@@ -154,13 +153,13 @@ module VanityTestHelpers
154
153
  # override the built-in setup/teardown methods, so we alias_method_chain
155
154
  # them to run.
156
155
  def self.included(klass)
157
- klass.class_eval {
158
- alias :teardown_before :teardown
159
- alias :teardown :teardown_after
156
+ klass.class_eval do
157
+ alias_method :teardown_before, :teardown
158
+ alias_method :teardown, :teardown_after
160
159
 
161
- alias :setup_before :setup
162
- alias :setup :setup_after
163
- }
160
+ alias_method :setup_before, :setup
161
+ alias_method :setup, :setup_after
162
+ end
164
163
  end
165
164
  end
166
165
 
@@ -196,7 +195,7 @@ module LegacyTestRequests
196
195
  ActiveRecord::VERSION::MAJOR <= 4
197
196
  end
198
197
 
199
- def get(path, params={}, headers={})
198
+ def get(path, params = {}, headers = {})
200
199
  if rails4?
201
200
  process(path, 'GET', params, headers)
202
201
  else
@@ -204,7 +203,7 @@ module LegacyTestRequests
204
203
  end
205
204
  end
206
205
 
207
- def post(path, params={}, headers={})
206
+ def post(path, params = {}, headers = {})
208
207
  if rails4?
209
208
  process(path, 'POST', params, headers)
210
209
  else
@@ -212,7 +211,7 @@ module LegacyTestRequests
212
211
  end
213
212
  end
214
213
 
215
- def put(path, params={}, headers={})
214
+ def put(path, params = {}, headers = {})
216
215
  if rails4?
217
216
  process(path, 'PUT', params, headers)
218
217
  else
@@ -220,7 +219,7 @@ module LegacyTestRequests
220
219
  end
221
220
  end
222
221
 
223
- def delete(path, params={}, headers={})
222
+ def delete(path, params = {}, headers = {})
224
223
  if rails4?
225
224
  process(path, 'DELETE', params, headers)
226
225
  else
@@ -233,7 +232,7 @@ if defined?(ActionController::TestCase)
233
232
  class ActionController::TestCase
234
233
  include LegacyTestRequests
235
234
 
236
- alias :setup_controller_request_and_response_without_vanity :setup_controller_request_and_response
235
+ alias setup_controller_request_and_response_without_vanity setup_controller_request_and_response
237
236
  # Sets Vanity.context to the current controller, so you can do things like:
238
237
  # experiment(:simple).chooses(:green)
239
238
  def setup_controller_request_and_response
@@ -244,13 +243,13 @@ if defined?(ActionController::TestCase)
244
243
  end
245
244
 
246
245
  if defined?(ActionDispatch::IntegrationTest)
247
- class ActionDispatch::IntegrationTest
246
+ class ActionDispatch::IntegrationTest # rubocop:todo Lint/EmptyClass
248
247
  end
249
248
  end
250
249
 
251
250
  if ENV["DB"] == "active_record"
252
251
  ActiveRecord::Base.establish_connection
253
- ActiveRecord::Base.logger = $logger
252
+ ActiveRecord::Base.logger = $logger # rubocop:todo Style/GlobalVars
254
253
 
255
254
  Vanity.connect!(VanityTestHelpers::DATABASE)
256
255
 
@@ -262,7 +261,7 @@ if ENV["DB"] == "active_record"
262
261
  require "generators/vanity/migration_generator"
263
262
  Rails::Generators.invoke "vanity"
264
263
 
265
- migrate_path = File.expand_path("../dummy/db/migrate/", __FILE__)
264
+ migrate_path = File.expand_path('dummy/db/migrate', __dir__)
266
265
  if defined?(ActiveRecord::MigrationContext)
267
266
  ActiveRecord::MigrationContext.new(migrate_path).migrate
268
267
  else