Added spects to check de stats model and view
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
<li class="tabs-title">
|
||||
<%= link_to "#tab-stats" do %>
|
||||
<h3>
|
||||
<%= "Estadísticas" %> <!-- t("polls.show.comments_tab") -->
|
||||
<%= t("polls.show.stats_menu") %> <!-- t("polls.show.comments_tab") -->
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="tabs-title is-active">
|
||||
<%= link_to "#tab-information" do %>
|
||||
<h3>
|
||||
<%= "Información" %>
|
||||
<%= t("polls.show.info_menu") %>
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
@@ -497,6 +497,8 @@ en:
|
||||
read_more: "Read more about %{answer}"
|
||||
read_less: "Read less about %{answer}"
|
||||
participate_in_other_polls: Participate in other polls
|
||||
info_menu: "Information"
|
||||
stats_menu: "Participation statistics"
|
||||
stats:
|
||||
title: "Participation data"
|
||||
total_participation: "Total participation"
|
||||
|
||||
@@ -497,6 +497,8 @@ es:
|
||||
read_more: "Leer más sobre %{answer}"
|
||||
read_less: "Leer menos sobre %{answer}"
|
||||
participate_in_other_polls: Participar en otras votaciones
|
||||
info_menu: "Información"
|
||||
stats_menu: "Estadísticas de participación"
|
||||
stats:
|
||||
title: "Datos de participación"
|
||||
total_participation: "Participación total"
|
||||
|
||||
@@ -357,4 +357,17 @@ feature 'Polls' do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Results and stats" do
|
||||
scenario "See polls statistics", :js do
|
||||
user = create(:user)
|
||||
poll = create(:poll, summary: "Summary", description: "Description")
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
click_link "Participation statistics"
|
||||
|
||||
expect(page).to have_content("Total participation")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
45
spec/models/poll/stats_spec.rb
Normal file
45
spec/models/poll/stats_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Poll::Stats do
|
||||
|
||||
describe "Calculate stats" do
|
||||
it "Generate the correct stats" do
|
||||
poll = create(:poll)
|
||||
booth = create(:poll_booth)
|
||||
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||
create(:poll_voter, poll: poll, origin: 'web')
|
||||
3.times {create(:poll_voter, poll: poll, origin: 'booth')}
|
||||
create(:poll_voter, poll: poll)
|
||||
create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id)
|
||||
stats = Poll::Stats.new(poll).generate
|
||||
|
||||
expect(stats[:total_participants]).to eq(5)
|
||||
expect(stats[:total_participants_web]).to eq(2)
|
||||
expect(stats[:total_participants_booth]).to eq(3)
|
||||
expect(stats[:total_valid_votes]).to eq(4)
|
||||
expect(stats[:total_white_votes]).to eq(1)
|
||||
expect(stats[:total_null_votes]).to eq(0)
|
||||
|
||||
expect(stats[:total_web_valid]).to eq(2)
|
||||
expect(stats[:total_web_white]).to eq(0)
|
||||
expect(stats[:total_web_null]).to eq(0)
|
||||
|
||||
expect(stats[:total_booth_valid]).to eq(2)
|
||||
expect(stats[:total_booth_white]).to eq(1)
|
||||
expect(stats[:total_booth_null]).to eq(0)
|
||||
|
||||
expect(stats[:total_participants_web_percentage]).to eq(40)
|
||||
expect(stats[:total_participants_booth_percentage]).to eq(60)
|
||||
expect(stats[:valid_percentage_web]).to eq(50)
|
||||
expect(stats[:white_percentage_web]).to eq(0)
|
||||
expect(stats[:null_percentage_web]).to eq(0)
|
||||
expect(stats[:valid_percentage_booth]).to eq(50)
|
||||
expect(stats[:white_percentage_booth]).to eq(100)
|
||||
expect(stats[:null_percentage_booth]).to eq(0)
|
||||
expect(stats[:total_valid_percentage]).to eq(80)
|
||||
expect(stats[:total_white_percentage]).to eq(20)
|
||||
expect(stats[:total_null_percentage]).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user