vanity 2.0.0.beta8 → 2.0.0.beta9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.travis.yml +4 -2
  2. data/Appraisals +1 -1
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +4 -1
  5. data/gemfiles/rails32.gemfile +3 -2
  6. data/gemfiles/rails32.gemfile.lock +4 -5
  7. data/gemfiles/rails4.gemfile +2 -1
  8. data/gemfiles/rails4.gemfile.lock +3 -1
  9. data/gemfiles/rails41.gemfile +2 -1
  10. data/gemfiles/rails41.gemfile.lock +3 -1
  11. data/gemfiles/rails42.gemfile +2 -1
  12. data/gemfiles/rails42.gemfile.lock +3 -1
  13. data/lib/vanity.rb +11 -5
  14. data/lib/vanity/adapters.rb +20 -0
  15. data/lib/vanity/adapters/abstract_adapter.rb +0 -18
  16. data/lib/vanity/autoconnect.rb +1 -0
  17. data/lib/vanity/configuration.rb +211 -0
  18. data/lib/vanity/connection.rb +100 -0
  19. data/lib/vanity/frameworks.rb +2 -0
  20. data/lib/vanity/frameworks/rails.rb +7 -5
  21. data/lib/vanity/helpers.rb +1 -0
  22. data/{config → lib/vanity}/locales/vanity.en.yml +0 -0
  23. data/{config → lib/vanity}/locales/vanity.pt-BR.yml +0 -0
  24. data/lib/vanity/playground.rb +138 -338
  25. data/lib/vanity/vanity.rb +166 -0
  26. data/lib/vanity/version.rb +1 -1
  27. data/test/configuration_test.rb +90 -0
  28. data/test/connection_test.rb +46 -0
  29. data/test/data/redis.yml.url +2 -0
  30. data/test/data/vanity.yml.activerecord +6 -0
  31. data/test/data/vanity.yml.mock +4 -0
  32. data/test/data/vanity.yml.redis +5 -0
  33. data/test/data/vanity.yml.redis-erb +3 -0
  34. data/test/experiment/ab_test.rb +1 -1
  35. data/test/experiment/base_test.rb +1 -1
  36. data/test/frameworks/rails/rails_test.rb +34 -30
  37. data/test/metric/remote_test.rb +8 -8
  38. data/test/playground_test.rb +1 -27
  39. data/test/templates_test.rb +3 -2
  40. data/test/test_helper.rb +24 -12
  41. data/test/vanity_test.rb +130 -0
  42. metadata +25 -5
@@ -2,24 +2,24 @@ require "test_helper"
2
2
 
3
3
  describe "Remote metrics" do
4
4
  before do
5
- FileUtils.mkpath "tmp/config"
6
- File.open "tmp/config/vanity.yml", "w" do |f|
5
+ File.open "tmp/experiments/metrics/sandbox.rb", "w" do |f|
7
6
  f.write <<-RUBY
8
- metrics:
9
- sandbox: http://api.vanitydash.com/metrics/sandbox
7
+ metric "Sandbox" do
8
+ remote "http://api.vanitydash.com/metrics/sandbox"
9
+ end
10
10
  RUBY
11
11
  end
12
- ::Rails.stubs(:root).returns(Pathname.new(File.expand_path("tmp")))
12
+
13
13
  Dir.chdir "tmp" do
14
14
  Vanity.playground.load!
15
15
  end
16
16
  end
17
17
 
18
- it "loads from configuration file" do
19
- assert Vanity.playground.metrics[:sandbox]
18
+ it "loads from metrics files" do
19
+ assert Vanity.playground.metric(:sandbox)
20
20
  end
21
21
 
22
- it "creates remote metric from configuration file" do
22
+ it "creates remote metric from metric file" do
23
23
  stub_request :post, /vanitydash/
24
24
  metric(:sandbox).track!
25
25
  assert_requested :post, /api\.vanitydash\.com/
@@ -45,33 +45,7 @@ describe Vanity::Playground do
45
45
 
46
46
  describe "#add_participant_path" do
47
47
  it "sets a default add participant path" do
48
- assert_equal Vanity.playground.add_participant_path, Vanity::Playground::DEFAULT_ADD_PARTICIPANT_PATH
49
- end
50
- end
51
-
52
- describe "reconnect!" do
53
- it "reconnects with the same configuration" do
54
- Vanity.playground.establish_connection "mock:/"
55
- Vanity.playground.reconnect!
56
- assert_equal Vanity.playground.connection.to_s, "mock:/"
57
- end
58
- end
59
-
60
- describe "autoconnect" do
61
- it "establishes connection by default with connection" do
62
- instance = Vanity::Playground.new(:connection=>"mock:/")
63
- assert instance.connected?
64
- end
65
-
66
- it "establishes connection by default" do
67
- Vanity::Playground.any_instance.expects(:establish_connection)
68
- Vanity::Playground.new
69
- end
70
-
71
- it "can skip connection" do
72
- Vanity::Autoconnect.stubs(:playground_should_autoconnect?).returns(false)
73
- instance = Vanity::Playground.new(:connection=>"mock:/")
74
- assert !instance.connected?
48
+ assert_equal Vanity.playground.add_participant_path, Vanity::Configuration::DEFAULTS[:add_participant_route]
75
49
  end
76
50
  end
77
51
 
@@ -6,7 +6,7 @@ describe Vanity::Templates do
6
6
  end
7
7
 
8
8
  describe "template" do
9
- it "resolves templates from the gem by default" do
9
+ it "resolves templates from the configured path" do
10
10
  custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
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')
@@ -14,9 +14,10 @@ describe Vanity::Templates do
14
14
  assert_equal expected, Vanity::Templates.new.path('foo.html')
15
15
  end
16
16
 
17
- it "resolves templates from the Rails view directory if it exists" do
17
+ it "resolves templates from a Rails view directory when configured" do
18
18
  begin
19
19
  custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
20
+ Vanity.configuration.templates_path = custom_view_path
20
21
 
21
22
  expected = File.expand_path(File.join(custom_view_path, 'foo.html'))
22
23
 
data/test/test_helper.rb CHANGED
@@ -21,11 +21,13 @@ require "rails/test_help"
21
21
  require "vanity"
22
22
  require "timecop"
23
23
  require "mocha/mini_test"
24
+ require "fakefs/safe"
24
25
  require "webmock/minitest"
25
26
 
26
27
  # Due to load order differences in Rails boot and test requires we have to
27
28
  # manually require these
28
29
 
30
+ # TODO wonder if we can load rails only for the rails tests...
29
31
  require 'vanity/frameworks/rails'
30
32
  Vanity::Rails.load!
31
33
 
@@ -42,30 +44,41 @@ module VanityTestHelpers
42
44
  # don't use databases you care about. For Redis, we pick database 15
43
45
  # (default is 0).
44
46
  DATABASE = {
45
- "redis"=>"redis://localhost/15",
46
- "mongodb"=>"mongodb://localhost/vanity",
47
- "active_record"=> { "adapter"=>"active_record", "active_record_adapter"=>"default" },
48
- "mock"=>"mock:/"
47
+ "redis" => "redis://localhost/15",
48
+ "mongodb" => "mongodb://localhost/vanity",
49
+ "active_record" => { :adapter => "active_record", :active_record_adapter =>"default" },
50
+ "mock" => "mock:/"
49
51
  }[ENV["DB"]] or raise "No support yet for #{ENV["DB"]}"
50
52
 
53
+ TEST_DATA_FILES = Dir[File.expand_path("../data/*", __FILE__)]
54
+ VANITY_CONFIGS = TEST_DATA_FILES.each.with_object({}) do |path, hash|
55
+ hash[File.basename(path)] = File.read(path)
56
+ end
57
+
51
58
  def setup_after
52
59
  FileUtils.mkpath "tmp/experiments/metrics"
53
- new_playground
60
+ vanity_reset
54
61
  end
55
62
 
56
63
  def teardown_after
57
64
  Vanity.context = nil
58
65
  FileUtils.rm_rf "tmp"
59
- Vanity.playground.connection.flushdb if Vanity.playground.connected?
66
+ Vanity.connection.adapter.flushdb if Vanity.connection.connected?
60
67
  WebMock.reset!
61
68
  end
62
69
 
63
70
  # Call this if you need a new playground, e.g. to re-define the same experiment,
64
71
  # or reload an experiment (saved by the previous playground).
65
- def new_playground
66
- Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments")
72
+ def vanity_reset
73
+ Vanity.reset!
74
+ Vanity.configuration.logger = $logger
75
+ Vanity.configuration.experiments_path = "tmp/experiments"
76
+
77
+ Vanity.disconnect!
67
78
  ActiveRecord::Base.establish_connection
68
- Vanity.playground.establish_connection(DATABASE)
79
+ Vanity.connect!(DATABASE)
80
+
81
+ Vanity.unload!
69
82
  end
70
83
 
71
84
  # Defines the specified metrics (one or more names). Returns metric, or array
@@ -82,7 +95,7 @@ module VanityTestHelpers
82
95
  def new_ab_test(name, &block)
83
96
  id = name.to_s.downcase.gsub(/\W/, "_").to_sym
84
97
  experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, name)
85
- experiment.instance_eval &block
98
+ experiment.instance_eval(&block)
86
99
  experiment.save
87
100
  Vanity.playground.experiments[id] = experiment
88
101
  end
@@ -97,8 +110,7 @@ module VanityTestHelpers
97
110
  end
98
111
 
99
112
  def not_collecting!
100
- Vanity.playground.collecting = false
101
- Vanity.playground.stubs(:connection).returns(stub(:flushdb=>nil))
113
+ Vanity.configuration.collecting = false
102
114
  end
103
115
 
104
116
  def dummy_request
@@ -0,0 +1,130 @@
1
+ require "test_helper"
2
+
3
+ describe Vanity do
4
+ describe "#configuration" do
5
+ it "returns the same configuration" do
6
+ assert_same Vanity.configuration, Vanity.configuration
7
+ end
8
+
9
+ it "returns nil if if skipping bang" do
10
+ Vanity.configuration = nil
11
+ assert_nil Vanity.configuration(false)
12
+ end
13
+ end
14
+
15
+ describe "#configure!" do
16
+ it "returns a configuration" do
17
+ assert_kind_of Vanity::Configuration, Vanity.configure!
18
+ end
19
+
20
+ it "returns a new configuration" do
21
+ refute_same Vanity.configure!, Vanity.configure!
22
+ end
23
+ end
24
+
25
+ describe "#reset!" do
26
+ it "creates a new configuration" do
27
+ original_configuration = Vanity.configuration
28
+ refute_same original_configuration, Vanity.reset!
29
+ end
30
+ end
31
+
32
+ describe "#configure" do
33
+ it "configures via a block" do
34
+ Vanity.configure do |config|
35
+ config.collecting = false
36
+ end
37
+
38
+ assert !Vanity.configuration.collecting
39
+ end
40
+ end
41
+
42
+ describe "#context" do
43
+ it "returns the context" do
44
+ Vanity.context = Object.new
45
+ assert_same Vanity.context, Vanity.context
46
+ end
47
+ end
48
+
49
+ describe "#connection" do
50
+ it "returns the same connection" do
51
+ assert_same Vanity.connection, Vanity.connection
52
+ end
53
+
54
+ it "returns nil if if skipping bang" do
55
+ Vanity.connection = nil
56
+ assert_nil Vanity.connection(false)
57
+ end
58
+ end
59
+
60
+ describe "#connect!" do
61
+ it "returns a connection" do
62
+ assert_kind_of Vanity::Connection, Vanity.connect!
63
+ end
64
+
65
+ it "returns a new connection" do
66
+ refute_same Vanity.connect!, Vanity.connect!
67
+ end
68
+ end
69
+
70
+ describe "#disconnect!" do
71
+ it "sets the connection to nil" do
72
+ Vanity.disconnect!
73
+ assert_nil Vanity.connection(false)
74
+ end
75
+
76
+ it "handles nil connections" do
77
+ Vanity.connection = nil
78
+ assert_nil Vanity.disconnect!
79
+ end
80
+ end
81
+
82
+ describe "#reconnect!" do
83
+ it "reconnects with the same configuration" do
84
+ Vanity.disconnect!
85
+ original_specification = Vanity.connection.specification
86
+ Vanity.reconnect!
87
+ assert_equal original_specification, Vanity.connection.specification
88
+ end
89
+
90
+ it "creates a new connection" do
91
+ original_configuration = Vanity.connection
92
+ refute_same original_configuration, Vanity.reconnect!
93
+ end
94
+ end
95
+
96
+ describe "#playground" do
97
+ it "returns the same playground" do
98
+ assert_same Vanity.playground, Vanity.playground
99
+ end
100
+
101
+ it "returns nil if if skipping bang" do
102
+ Vanity.playground = nil
103
+ assert_nil Vanity.playground(false)
104
+ end
105
+ end
106
+
107
+ describe "#load!" do
108
+ it "returns a playground" do
109
+ assert_kind_of Vanity::Playground, Vanity.load!
110
+ end
111
+
112
+ it "returns a new playground" do
113
+ refute_same Vanity.load!, Vanity.load!
114
+ end
115
+ end
116
+
117
+ describe "#unload!" do
118
+ it "sets the playground to nil" do
119
+ Vanity.unload!
120
+ assert_nil Vanity.playground(false)
121
+ end
122
+ end
123
+
124
+ describe "#reload!" do
125
+ it "creates a new playground" do
126
+ original_configuration = Vanity.playground
127
+ refute_same original_configuration, Vanity.reload!
128
+ end
129
+ end
130
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta8
4
+ version: 2.0.0.beta9
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-04 00:00:00.000000000 Z
12
+ date: 2015-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -79,8 +79,6 @@ files:
79
79
  - README.rdoc
80
80
  - Rakefile
81
81
  - bin/vanity
82
- - config/locales/vanity.en.yml
83
- - config/locales/vanity.pt-BR.yml
84
82
  - doc/_config.yml
85
83
  - doc/_layouts/_header.html
86
84
  - doc/_layouts/page.html
@@ -118,6 +116,7 @@ files:
118
116
  - lib/generators/vanity/views_generator.rb
119
117
  - lib/generators/vanity_generator.rb
120
118
  - lib/vanity.rb
119
+ - lib/vanity/adapters.rb
121
120
  - lib/vanity/adapters/abstract_adapter.rb
122
121
  - lib/vanity/adapters/active_record_adapter.rb
123
122
  - lib/vanity/adapters/mock_adapter.rb
@@ -126,6 +125,8 @@ files:
126
125
  - lib/vanity/autoconnect.rb
127
126
  - lib/vanity/commands/list.rb
128
127
  - lib/vanity/commands/report.rb
128
+ - lib/vanity/configuration.rb
129
+ - lib/vanity/connection.rb
129
130
  - lib/vanity/experiment/ab_test.rb
130
131
  - lib/vanity/experiment/alternative.rb
131
132
  - lib/vanity/experiment/base.rb
@@ -135,6 +136,8 @@ files:
135
136
  - lib/vanity/frameworks/rails.rb
136
137
  - lib/vanity/helpers.rb
137
138
  - lib/vanity/images/x.gif
139
+ - lib/vanity/locales/vanity.en.yml
140
+ - lib/vanity/locales/vanity.pt-BR.yml
138
141
  - lib/vanity/metric/active_record.rb
139
142
  - lib/vanity/metric/base.rb
140
143
  - lib/vanity/metric/google_analytics.rb
@@ -153,11 +156,19 @@ files:
153
156
  - lib/vanity/templates/jquery.min.js
154
157
  - lib/vanity/templates/vanity.css
155
158
  - lib/vanity/templates/vanity.js
159
+ - lib/vanity/vanity.rb
156
160
  - lib/vanity/version.rb
157
161
  - test/adapters/redis_adapter_test.rb
158
162
  - test/autoconnect_test.rb
159
163
  - test/cli_test.rb
160
164
  - test/commands/report_test.rb
165
+ - test/configuration_test.rb
166
+ - test/connection_test.rb
167
+ - test/data/redis.yml.url
168
+ - test/data/vanity.yml.activerecord
169
+ - test/data/vanity.yml.mock
170
+ - test/data/vanity.yml.redis
171
+ - test/data/vanity.yml.redis-erb
161
172
  - test/dummy/Rakefile
162
173
  - test/dummy/app/controllers/application_controller.rb
163
174
  - test/dummy/app/helpers/application_helper.rb
@@ -197,6 +208,7 @@ files:
197
208
  - test/playground_test.rb
198
209
  - test/templates_test.rb
199
210
  - test/test_helper.rb
211
+ - test/vanity_test.rb
200
212
  - test/web/rails/dashboard_test.rb
201
213
  - vanity.gemspec
202
214
  homepage: http://vanity.labnotes.org
@@ -205,7 +217,7 @@ licenses:
205
217
  post_install_message: To get started run vanity --help
206
218
  rdoc_options:
207
219
  - --title
208
- - Vanity 2.0.0.beta8
220
+ - Vanity 2.0.0.beta9
209
221
  - --main
210
222
  - README.rdoc
211
223
  - --webcvs
@@ -235,6 +247,13 @@ test_files:
235
247
  - test/autoconnect_test.rb
236
248
  - test/cli_test.rb
237
249
  - test/commands/report_test.rb
250
+ - test/configuration_test.rb
251
+ - test/connection_test.rb
252
+ - test/data/redis.yml.url
253
+ - test/data/vanity.yml.activerecord
254
+ - test/data/vanity.yml.mock
255
+ - test/data/vanity.yml.redis
256
+ - test/data/vanity.yml.redis-erb
238
257
  - test/dummy/Rakefile
239
258
  - test/dummy/app/controllers/application_controller.rb
240
259
  - test/dummy/app/helpers/application_helper.rb
@@ -274,5 +293,6 @@ test_files:
274
293
  - test/playground_test.rb
275
294
  - test/templates_test.rb
276
295
  - test/test_helper.rb
296
+ - test/vanity_test.rb
277
297
  - test/web/rails/dashboard_test.rb
278
298
  has_rdoc: