diff --git a/app/views/status_messages/_poll.mobile.haml b/app/views/status_messages/_poll.mobile.haml index 30dec659f..466c6b55c 100644 --- a/app/views/status_messages/_poll.mobile.haml +++ b/app/views/status_messages/_poll.mobile.haml @@ -10,7 +10,7 @@ .result-head - percentage = 0 - if poll.participation_count > 0 - - percentage = (answer.vote_count / poll.participation_count * 100).round + - percentage = (answer.vote_count.to_f / poll.participation_count * 100).round .percentage.pull-right = "#{percentage}%" .answer diff --git a/spec/integration/mobile_posts_spec.rb b/spec/integration/mobile_posts_spec.rb index 058b06948..d743e61f7 100644 --- a/spec/integration/mobile_posts_spec.rb +++ b/spec/integration/mobile_posts_spec.rb @@ -11,6 +11,15 @@ describe PostsController, type: :request do expect(response.body).to match(/div class='poll'/) expect(response.body).to match(/#{sm.poll.poll_answers.first.answer}/) end + + it "displays the correct percentage for the answers" do + alice.participate_in_poll!(sm, sm.poll.poll_answers.first) + bob.participate_in_poll!(sm, sm.poll.poll_answers.last) + get "/posts/#{sm.id}", format: :mobile + + expect(response.status).to eq(200) + expect(response.body).to match(/div class='percentage pull-right'>\n50%/) + end end context "with a location" do