Permalink
Browse files

Experiments can now handle not having start times

  • Loading branch information...
1 parent dd86a36 commit 3516cbe2fe6da043a85d0fc63b6b2e2fbaeccf1e @andrew andrew committed Mar 4, 2012
Showing with 26 additions and 2 deletions.
  1. +1 −1 lib/split/dashboard/views/_experiment.erb
  2. +2 −1 lib/split/experiment.rb
  3. +12 −0 spec/dashboard_spec.rb
  4. +11 −0 spec/experiment_spec.rb
@@ -6,7 +6,7 @@
</h2>
<div class='inline-controls'>
- <small><%= experiment.start_time.strftime('%Y-%m-%d') %></small>
+ <small><%= experiment.start_time ? experiment.start_time.strftime('%Y-%m-%d') : 'Unknown' %></small>
<form action="<%= url "/reset/#{experiment.name}" %>" method='post' onclick="return confirmReset()">
<input type="submit" value="Reset Data">
</form>
View
@@ -31,7 +31,8 @@ def winner=(winner_name)
end
def start_time
- Time.parse(Split.redis.hget(:experiment_start_times, @name))
+ t = Split.redis.hget(:experiment_start_times, @name)
+ Time.parse(t) if t
end
def alternatives
View
@@ -61,4 +61,16 @@ def app
last_response.body.should include('<small>2011-07-07</small>')
end
+
+ it "should handle experiments without a start date" do
+ experiment_start_time = Time.parse('2011-07-07')
+ Time.stub(:now => experiment_start_time)
+ experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
+
+ Split.redis.hdel(:experiment_start_times, experiment.name)
+
+ get '/'
+
+ last_response.body.should include('<small>Unknown</small>')
+ end
end
View
@@ -28,6 +28,17 @@
Split::Experiment.find('basket_text').start_time.should == experiment_start_time
end
+
+ it "should handle not having a start time" do
+ experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
+ Time.stub(:now => experiment_start_time)
+ experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
+ experiment.save
+
+ Split.redis.hdel(:experiment_start_times, experiment.name)
+
+ Split::Experiment.find('basket_text').start_time.should == nil
+ end
it "should not create duplicates when saving multiple times" do
experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")

0 comments on commit 3516cbe

Please sign in to comment.