Permalink
Browse files

timing stored on search, not on choice. This will also let us see how…

… many searches were done and abandoned with no choice
  • Loading branch information...
1 parent eb715ac commit 1e6169cc424400e1a804e8bb99cab38c66440868 @jrochkind committed Aug 21, 2012
@@ -28,6 +28,10 @@ def index
if @results[engine].failed?
handle_failed_results(choice)
end
+ end
+
+ @results.each_pair do |engine, results|
+ Timing.create(:engine => engine, :miliseconds => results.timing_ms)
end
end
rescue OutOfEngines
@@ -61,9 +65,6 @@ def choice
session[:status_choice] = selection.demographic_status = params[:status]
selection.save!
-
- Timing.create(:engine => params[:option_a], :miliseconds => params[:timing_a])
- Timing.create(:engine => params[:option_b], :miliseconds => params[:timing_b])
redirect_to root_path, :flash => {:submitted => true}
end
@@ -79,8 +80,7 @@ def choices
def validate_choice
unless (params[:option_a].present? && params[:option_b].present? &&
params[:query].present? &&
- (params['preferB'].present? || params['preferA'].present? || params['preferNone'].present?) &&
- params[:timing_a].present? && params[:timing_b].present?)
+ (params['preferB'].present? || params['preferA'].present? || params['preferNone'].present?) )
render :status => 500, :text => "ERROR: missing input. Something is wrong, your choice was not recorded."
@@ -37,9 +37,6 @@
<%= hidden_field_tag 'option_a', @one %>
<%= hidden_field_tag 'option_b', @two %>
- <%= hidden_field_tag "timing_a", @results[@one].timing %>
- <%= hidden_field_tag "timing_b", @results[@two].timing %>
-
<div class="row">
<div class="span12">
<div class="choice-header">
@@ -2,11 +2,15 @@
class BattleControllerTest < ActionController::TestCase
def setup
+ @timing_aa = 1.5
BentoSearch.register_engine("AA") do |conf|
conf.engine = "BentoSearch::MockEngine"
+ conf.timing = @timing_aa
end
+ @timing_bb = 2.5
BentoSearch.register_engine("BB") do |conf|
conf.engine = "BentoSearch::MockEngine"
+ conf.timing = @timing_bb
end
BentoSearch.register_engine("CC") do |conf|
conf.engine = "BentoSearch::MockEngine"
@@ -171,20 +175,23 @@ def choices
end
test "should save timing info" do
+ BattleController.contenders = ["AA", "BB"]
+
+
assert_difference("Timing.count", 2) do
- post :choice, example_post_params
+ post :index, :q => "Cancer"
end
last_two = Timing.last(2)
+ assert( last_two.find do |t|
+ t.engine == "AA"
+ t.miliseconds == (@timing_aa * 1000).to_i
+ end, "timing_a recorded")
assert( last_two.find do |t|
- t.engine == example_post_params[:option_a] &&
- t.miliseconds == example_post_params[:timing_a]
- end, "timing_a recorded")
- assert( last_two.find do |t|
- t.engine == example_post_params[:option_b] &&
- t.miliseconds == example_post_params[:timing_b]
- end, "timing_b recorded")
+ t.engine == "BB"
+ t.miliseconds == (@timing_bb * 1000).to_i
+ end, "timing_b recorded")
end

0 comments on commit 1e6169c

Please sign in to comment.