From 6a713a7730ba307519068aed34bcb52ba6d41e23 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Fri, 30 Mar 2012 15:22:19 -0400 Subject: [PATCH] modify no values from 0 to nil in API response --- app/models/question.rb | 6 +++--- spec/integration/questions_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index 77d2933..9d261ac 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -678,7 +678,7 @@ class Question < ActiveRecord::Base else uploaded_choices_count = choices.not_created_by(creator_id).count end - return 0.to_f if uploaded_choices_count == 0 + return nil if uploaded_choices_count == 0 votes.count.to_f / uploaded_choices_count.to_f end @@ -695,7 +695,7 @@ class Question < ActiveRecord::Base def upload_to_participation_ratio swp = sessions_with_participation - return 0.to_f if swp == 0 + return nil if swp == 0 sessions_with_uploaded_ideas.to_f / swp.to_f end @@ -722,7 +722,7 @@ class Question < ActiveRecord::Base def vote_rate tus = total_uniq_sessions - return 0.to_f if tus == 0 + return nil if tus == 0 sessions_with_vote.to_f / tus.to_f end diff --git a/spec/integration/questions_spec.rb b/spec/integration/questions_spec.rb index 4deb132..92a565c 100644 --- a/spec/integration/questions_spec.rb +++ b/spec/integration/questions_spec.rb @@ -261,11 +261,11 @@ describe "Questions" do q = Factory.create(:aoi_question, :site => @api_user) get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml') response.should be_success - response.body.should have_tag("value", :text => "0.0") + response.body.should have_tag("value[nil=true]", :text => "") get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml', :only_active => true) response.should be_success - response.body.should have_tag("value", :text => "0.0") + response.body.should have_tag("value[nil=true]", :text => "") v = Factory.create(:vote_new_user, :question => q) Factory.create(:choice, :creator => v.voter, :question => q) @@ -300,7 +300,7 @@ describe "Questions" do q = Factory.create(:aoi_question, :site => @api_user) get_auth upload_to_participation_ratio_question_path(q, :format => 'xml') response.should be_success - response.body.should have_tag("uploadparticipationratio", :text => "0.0") + response.body.should have_tag("uploadparticipationratio[nil=true]", :text => "") # 10 voting only sessions 10.times { Factory.create(:vote_new_user, :question => q) } @@ -346,7 +346,7 @@ describe "Questions" do it "should return the proper vote rate if no votes" do get_auth vote_rate_question_path(@questions.first, :format => 'xml') response.should be_success - response.body.should have_tag("voterate", :text => "0.0") + response.body.should have_tag("voterate[nil=true]", :text => "") end end -- libgit2 0.21.2