Skip to content
This repository
Browse code

Experiments can now handle not having start times

  • Loading branch information...
commit 3516cbe2fe6da043a85d0fc63b6b2e2fbaeccf1e 1 parent dd86a36
Andrew Nesbitt authored
2  lib/split/dashboard/views/_experiment.erb
@@ -6,7 +6,7 @@
6 6 </h2>
7 7
8 8 <div class='inline-controls'>
9   - <small><%= experiment.start_time.strftime('%Y-%m-%d') %></small>
  9 + <small><%= experiment.start_time ? experiment.start_time.strftime('%Y-%m-%d') : 'Unknown' %></small>
10 10 <form action="<%= url "/reset/#{experiment.name}" %>" method='post' onclick="return confirmReset()">
11 11 <input type="submit" value="Reset Data">
12 12 </form>
3  lib/split/experiment.rb
@@ -31,7 +31,8 @@ def winner=(winner_name)
31 31 end
32 32
33 33 def start_time
34   - Time.parse(Split.redis.hget(:experiment_start_times, @name))
  34 + t = Split.redis.hget(:experiment_start_times, @name)
  35 + Time.parse(t) if t
35 36 end
36 37
37 38 def alternatives
12 spec/dashboard_spec.rb
@@ -61,4 +61,16 @@ def app
61 61
62 62 last_response.body.should include('<small>2011-07-07</small>')
63 63 end
  64 +
  65 + it "should handle experiments without a start date" do
  66 + experiment_start_time = Time.parse('2011-07-07')
  67 + Time.stub(:now => experiment_start_time)
  68 + experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
  69 +
  70 + Split.redis.hdel(:experiment_start_times, experiment.name)
  71 +
  72 + get '/'
  73 +
  74 + last_response.body.should include('<small>Unknown</small>')
  75 + end
64 76 end
11 spec/experiment_spec.rb
@@ -28,6 +28,17 @@
28 28
29 29 Split::Experiment.find('basket_text').start_time.should == experiment_start_time
30 30 end
  31 +
  32 + it "should handle not having a start time" do
  33 + experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
  34 + Time.stub(:now => experiment_start_time)
  35 + experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
  36 + experiment.save
  37 +
  38 + Split.redis.hdel(:experiment_start_times, experiment.name)
  39 +
  40 + Split::Experiment.find('basket_text').start_time.should == nil
  41 + end
31 42
32 43 it "should not create duplicates when saving multiple times" do
33 44 experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")

0 comments on commit 3516cbe

Please sign in to comment.
Something went wrong with that request. Please try again.