vanity 3.0.2 → 4.0.1

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.
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 +13 -0
  8. data/Gemfile +7 -3
  9. data/Gemfile.lock +32 -4
  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 +34 -9
  16. data/gemfiles/rails60.gemfile +6 -3
  17. data/gemfiles/rails60.gemfile.lock +34 -9
  18. data/gemfiles/rails61.gemfile +6 -3
  19. data/gemfiles/rails61.gemfile.lock +34 -9
  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 +19 -27
  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 +23 -19
  31. data/lib/vanity/connection.rb +12 -14
  32. data/lib/vanity/experiment/ab_test.rb +95 -79
  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 +2 -3
  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 +188 -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 -15
  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,6 +1,5 @@
1
1
  module Vanity
2
2
  class Metric
3
-
4
3
  # Use Google Analytics metric. Note: you must +require "garb"+ before
5
4
  # vanity.
6
5
  #
@@ -17,13 +16,13 @@ module Vanity
17
16
  # @see Vanity::Metric::GoogleAnalytics
18
17
  def google_analytics(web_property_id, *args)
19
18
  require "garb"
20
- options = Hash === args.last ? args.pop : {}
19
+ options = args.last.is_a?(Hash) ? args.pop : {}
21
20
  metric = args.shift || :pageviews
22
21
  @ga_resource = Vanity::Metric::GoogleAnalytics::Resource.new(web_property_id, metric)
23
- @ga_mapper = options[:mapper] ||= lambda { |entry| entry.send(@ga_resource.metrics.elements.first).to_i }
22
+ @ga_mapper = options[:mapper] ||= ->(entry) { entry.send(@ga_resource.metrics.elements.first).to_i }
24
23
  extend GoogleAnalytics
25
24
  rescue LoadError
26
- fail LoadError, "Google Analytics metrics require Garb, please gem install garb first"
25
+ raise LoadError, "Google Analytics metrics require Garb, please gem install garb first"
27
26
  end
28
27
 
29
28
  # Calling google_analytics method on a metric extends it with these modules,
@@ -31,19 +30,18 @@ module Vanity
31
30
  #
32
31
  # @since 1.3.0
33
32
  module GoogleAnalytics
34
-
35
33
  # Returns values from GA using parameters specified by prior call to
36
34
  # google_analytics.
37
35
  def values(from, to)
38
- data = @ga_resource.results(from, to).inject({}) do |hash,entry|
39
- hash.merge(entry.date=>@ga_mapper.call(entry))
36
+ data = @ga_resource.results(from, to).inject({}) do |hash, entry|
37
+ hash.merge(entry.date => @ga_mapper.call(entry))
40
38
  end
41
39
  (from..to).map { |day| data[day.strftime('%Y%m%d')] || 0 }
42
40
  end
43
41
 
44
42
  # Hooks not supported for GA metrics.
45
43
  def hook
46
- fail "Cannot use hooks with Google Analytics methods"
44
+ raise "Cannot use hooks with Google Analytics methods"
47
45
  end
48
46
 
49
47
  # Garb report.
@@ -77,7 +75,6 @@ module Vanity
77
75
  Garb::ReportResponse.new(send_request_for_body).results
78
76
  end
79
77
  end
80
-
81
78
  end
82
79
  end
83
80
  end
@@ -3,7 +3,6 @@ require "cgi"
3
3
 
4
4
  module Vanity
5
5
  class Metric
6
-
7
6
  # Specifies the base URL to use for a remote metric. For example:
8
7
  # metric :sandbox do
9
8
  # remote "http://api.vanitydash.com/metrics/sandbox"
@@ -26,9 +25,9 @@ module Vanity
26
25
  # - Set values by their index using +values[0]+, +values[1]+, etc or
27
26
  # - Set values by series name using +values[foo]+, +values[bar]+, etc.
28
27
  module Remote
29
-
30
28
  def track!(args = nil)
31
29
  return unless @playground.collecting?
30
+
32
31
  timestamp, identity, values = track_args(args)
33
32
  params = ["metric=#{CGI.escape @id.to_s}", "timestamp=#{CGI.escape timestamp.httpdate}"]
34
33
  params << "identity=#{CGI.escape identity.to_s}" if identity
@@ -36,9 +35,9 @@ module Vanity
36
35
  params << @remote_url.query if @remote_url.query
37
36
  @mutex.synchronize do
38
37
  @http ||= Net::HTTP.start(@remote_url.host, @remote_url.port)
39
- @http.request Net::HTTP::Post.new(@remote_url.path, "Content-Type"=>"application/x-www-form-urlencoded"), params.join("&")
38
+ @http.request Net::HTTP::Post.new(@remote_url.path, "Content-Type" => "application/x-www-form-urlencoded"), params.join("&")
40
39
  end
41
- rescue Timeout::Error, StandardError
40
+ rescue Timeout::Error, StandardError # rubocop:todo Lint/ShadowedException
42
41
  @playground.logger.error "Error sending data for metric #{name}: #{$!}"
43
42
  @http = nil
44
43
  ensure
@@ -47,7 +46,6 @@ module Vanity
47
46
 
48
47
  # "Don't worry, be crappy. Revolutionary means you ship and then test."
49
48
  # -- Guy Kawazaki
50
-
51
49
  end
52
50
  end
53
51
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Vanity
2
- VERSION = "3.0.2"
2
+ VERSION = "4.0.1"
3
3
 
4
4
  module Version
5
5
  version = VERSION.to_s.split(".").map { |i| i.to_i }
@@ -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(:redis => mocked_redis)
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(:redis => mocked_redis)
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
- { :participants => 0, :converted => 0, :conversions => 0 },
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
- begin
136
- original_value = Vanity.configuration.experiments_start_enabled
137
- Vanity.configuration.experiments_start_enabled = enabled
138
- yield
139
- ensure
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
- {:participants => 1, :conversions => 1, :converted => 1},
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
- {:participants => 1, :conversions => 0, :converted => 0},
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
- {:participants => 2, :conversions => 2, :converted => 1},
287
+ { participants: 2, conversions: 2, converted: 1 },
291
288
  @subject.ab_counts(experiment, alternative)
292
289
  )
293
290
  end
@@ -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(:top_level_tasks => ['assets:precompile']))
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(:top_level_tasks => ['db:migrate']))
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
@@ -1,7 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "bin/vanity" do
4
-
5
4
  before do
6
5
  not_collecting!
7
6
  end
@@ -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.open("./config/vanity.yml", "w") do |f|
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.open("./config/vanity.yml", "w") do |f|
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.open("./config/redis.yml", "w") do |f|
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.open("./config/vanity.yml", "w") do |f|
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.open("./config/vanity.yml", "w") do |f|
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.open("./config/vanity.yml", "w") do |f|
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.open("./config/vanity.yml", "w") do |f|
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
- begin
118
- original_load_path = I18n.load_path
103
+ original_load_path = I18n.load_path
119
104
 
120
- config.setup_locales
105
+ config.setup_locales
121
106
 
122
- assert_includes(
123
- I18n.load_path,
124
- File.expand_path(File.join(__FILE__, '..', '..', 'lib/vanity/locales/vanity.en.yml'))
125
- )
126
- ensure
127
- I18n.load_path = original_load_path
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
@@ -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('../config/application', __FILE__)
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 :plain=>text, :text=>text
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 :inline => "<%= vanity_js -%>"
17
+ render inline: "<%= vanity_js -%>"
18
18
  end
19
19
 
20
20
  def view_helper_ab_test_js
21
- render :inline => <<-EOS
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
- render :inline => <<-EOS
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 :inline => "<%= vanity_js -%>"
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 :subject =>ab_test(:pie_or_cake).to_s, :body => ""
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, :host => "127.0.0.1:3000")
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 :html=>image_html.html_safe }
18
+ format.html { render html: image_html.html_safe }
19
19
  end
20
20
  end
21
21
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require "active_model/railtie"
4
4
  require "active_record/railtie"
@@ -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('../../Gemfile', __FILE__)
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
5
 
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
7
7
 
8
- $:.unshift File.expand_path('../../../../lib', __FILE__)
8
+ $:.unshift File.expand_path('../../../lib', __dir__)
@@ -1,5 +1,5 @@
1
1
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the rails application
5
5
  Dummy::Application.initialize!
@@ -23,4 +23,3 @@ Dummy::Application.configure do
23
23
  # Only use best-standards-support built into browsers
24
24
  config.action_dispatch.best_standards_support = :builtin
25
25
  end
26
-
@@ -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 = false
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, :key => '_dummy_session'
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
@@ -0,0 +1,3 @@
1
+ Vanity.configure do |config|
2
+ config.config_path = Rails.root.join('config')
3
+ end
@@ -0,0 +1,7 @@
1
+ default: &default
2
+ some_key: true
3
+
4
+ test:
5
+ <<: *default
6
+ adapter: mock
7
+ collecting: false
data/test/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('config/environment', __dir__)
4
4
  run Dummy::Application