Commit 6a713a7730ba307519068aed34bcb52ba6d41e23
1 parent
48f5de5f
Exists in
master
and in
1 other branch
modify no values from 0 to nil in API response
Showing
2 changed files
with
7 additions
and
7 deletions
Show diff stats
app/models/question.rb
@@ -678,7 +678,7 @@ class Question < ActiveRecord::Base | @@ -678,7 +678,7 @@ class Question < ActiveRecord::Base | ||
678 | else | 678 | else |
679 | uploaded_choices_count = choices.not_created_by(creator_id).count | 679 | uploaded_choices_count = choices.not_created_by(creator_id).count |
680 | end | 680 | end |
681 | - return 0.to_f if uploaded_choices_count == 0 | 681 | + return nil if uploaded_choices_count == 0 |
682 | votes.count.to_f / uploaded_choices_count.to_f | 682 | votes.count.to_f / uploaded_choices_count.to_f |
683 | end | 683 | end |
684 | 684 | ||
@@ -695,7 +695,7 @@ class Question < ActiveRecord::Base | @@ -695,7 +695,7 @@ class Question < ActiveRecord::Base | ||
695 | 695 | ||
696 | def upload_to_participation_ratio | 696 | def upload_to_participation_ratio |
697 | swp = sessions_with_participation | 697 | swp = sessions_with_participation |
698 | - return 0.to_f if swp == 0 | 698 | + return nil if swp == 0 |
699 | sessions_with_uploaded_ideas.to_f / swp.to_f | 699 | sessions_with_uploaded_ideas.to_f / swp.to_f |
700 | end | 700 | end |
701 | 701 | ||
@@ -722,7 +722,7 @@ class Question < ActiveRecord::Base | @@ -722,7 +722,7 @@ class Question < ActiveRecord::Base | ||
722 | 722 | ||
723 | def vote_rate | 723 | def vote_rate |
724 | tus = total_uniq_sessions | 724 | tus = total_uniq_sessions |
725 | - return 0.to_f if tus == 0 | 725 | + return nil if tus == 0 |
726 | sessions_with_vote.to_f / tus.to_f | 726 | sessions_with_vote.to_f / tus.to_f |
727 | end | 727 | end |
728 | 728 |
spec/integration/questions_spec.rb
@@ -261,11 +261,11 @@ describe "Questions" do | @@ -261,11 +261,11 @@ describe "Questions" do | ||
261 | q = Factory.create(:aoi_question, :site => @api_user) | 261 | q = Factory.create(:aoi_question, :site => @api_user) |
262 | get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml') | 262 | get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml') |
263 | response.should be_success | 263 | response.should be_success |
264 | - response.body.should have_tag("value", :text => "0.0") | 264 | + response.body.should have_tag("value[nil=true]", :text => "") |
265 | 265 | ||
266 | get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml', :only_active => true) | 266 | get_auth votes_per_uploaded_choice_question_path(q, :format => 'xml', :only_active => true) |
267 | response.should be_success | 267 | response.should be_success |
268 | - response.body.should have_tag("value", :text => "0.0") | 268 | + response.body.should have_tag("value[nil=true]", :text => "") |
269 | 269 | ||
270 | v = Factory.create(:vote_new_user, :question => q) | 270 | v = Factory.create(:vote_new_user, :question => q) |
271 | Factory.create(:choice, :creator => v.voter, :question => q) | 271 | Factory.create(:choice, :creator => v.voter, :question => q) |
@@ -300,7 +300,7 @@ describe "Questions" do | @@ -300,7 +300,7 @@ describe "Questions" do | ||
300 | q = Factory.create(:aoi_question, :site => @api_user) | 300 | q = Factory.create(:aoi_question, :site => @api_user) |
301 | get_auth upload_to_participation_ratio_question_path(q, :format => 'xml') | 301 | get_auth upload_to_participation_ratio_question_path(q, :format => 'xml') |
302 | response.should be_success | 302 | response.should be_success |
303 | - response.body.should have_tag("uploadparticipationratio", :text => "0.0") | 303 | + response.body.should have_tag("uploadparticipationratio[nil=true]", :text => "") |
304 | 304 | ||
305 | # 10 voting only sessions | 305 | # 10 voting only sessions |
306 | 10.times { Factory.create(:vote_new_user, :question => q) } | 306 | 10.times { Factory.create(:vote_new_user, :question => q) } |
@@ -346,7 +346,7 @@ describe "Questions" do | @@ -346,7 +346,7 @@ describe "Questions" do | ||
346 | it "should return the proper vote rate if no votes" do | 346 | it "should return the proper vote rate if no votes" do |
347 | get_auth vote_rate_question_path(@questions.first, :format => 'xml') | 347 | get_auth vote_rate_question_path(@questions.first, :format => 'xml') |
348 | response.should be_success | 348 | response.should be_success |
349 | - response.body.should have_tag("voterate", :text => "0.0") | 349 | + response.body.should have_tag("voterate[nil=true]", :text => "") |
350 | end | 350 | end |
351 | end | 351 | end |
352 | 352 |