adds specs for stats

This commit is contained in:
rgarcia
2016-06-16 17:59:56 +02:00
parent 0abc9c8376
commit f9a2f5d5dc
6 changed files with 89 additions and 10 deletions

View File

@@ -10,14 +10,18 @@
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<p class="featured"> <p class="featured">
<%= t("admin.stats.direct_messages.total") %><br> <%= t("admin.stats.direct_messages.total") %><br>
<span class="number"><%= @direct_messages.count %></span> <span class="number" id="direct_messages_count">
<%= @direct_messages.count %>
</span>
</p> </p>
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<p class="featured"> <p class="featured">
<%= t("admin.stats.direct_messages.users_who_have_sent_message") %><br> <%= t("admin.stats.direct_messages.users_who_have_sent_message") %><br>
<span class="number"><%= @users_who_have_sent_message.count %></span> <span class="number" id="users_who_have_sent_message_count">
<%= @users_who_have_sent_message.count %>
</span>
</p> </p>
</div> </div>
</div> </div>

View File

@@ -10,14 +10,18 @@
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<p class="featured"> <p class="featured">
<%= t("admin.stats.proposal_notifications.total") %><br> <%= t("admin.stats.proposal_notifications.total") %><br>
<span class="number"><%= @proposal_notifications.count %></span> <span class="number" id="proposal_notifications_count">
<%= @proposal_notifications.count %>
</span>
</p> </p>
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<p class="featured"> <p class="featured">
<%= t("admin.stats.proposal_notifications.proposals_with_notifications") %><br> <%= t("admin.stats.proposal_notifications.proposals_with_notifications") %><br>
<span class="number"><%= @proposals_with_notifications.count %></span> <span class="number" id="proposals_with_notifications_count">
<%= @proposals_with_notifications.count %>
</span>
</p> </p>
</div> </div>
</div> </div>
@@ -28,8 +32,10 @@
<div id="proposal_notifications"> <div id="proposal_notifications">
<% @proposal_notifications.each do |notification| %> <% @proposal_notifications.each do |notification| %>
<p><%= link_to notification.proposal.title, proposal_path(notification.proposal) %></p> <div class="proposal_notification">
<p><%= notification.title %></p> <p><%= link_to notification.proposal.title, proposal_path(notification.proposal) %></p>
<p><%= notification.body %></p> <p><%= notification.title %></p>
<p><%= notification.body %></p>
</div>
<% end %> <% end %>
</div> </div>

View File

@@ -288,6 +288,15 @@ en:
votes: Total votes votes: Total votes
spending_proposals_title: Spending Proposals spending_proposals_title: Spending Proposals
visits_title: Visits visits_title: Visits
direct_messages: Direct messages
proposal_notifications: Proposal notifications
direct_messages:
title: Direct messages
users_who_have_sent_message: Users that have sent a private message
proposal_notifications:
title: Proposal notifications
total: Total
proposals_with_notifications: Proposals with notifications
tags: tags:
create: Create Topic create: Create Topic
destroy: Destroy Topic destroy: Destroy Topic

View File

@@ -292,7 +292,7 @@ es:
title: Mensajes directos title: Mensajes directos
users_who_have_sent_message: Usuarios que han enviado un mensaje privado users_who_have_sent_message: Usuarios que han enviado un mensaje privado
proposal_notifications: proposal_notifications:
title: Mensajes directos title: Notificaciones de propuestas
total: Total total: Total
proposals_with_notifications: Propuestas con notificaciones proposals_with_notifications: Propuestas con notificaciones
tags: tags:

View File

@@ -327,8 +327,8 @@ FactoryGirl.define do
end end
factory :proposal_notification do factory :proposal_notification do
title "Thank you for supporting my proposal" sequence(:title) { |n| "Thank you for supporting my proposal #{n}" }
body "Please let others know so we can make it happen" sequence(:body) { |n| "Please let others know so we can make it happen #{n}" }
proposal proposal
end end

View File

@@ -70,4 +70,64 @@ feature 'Stats' do
expect(page).to have_content "Level 2 User (1)" expect(page).to have_content "Level 2 User (1)"
end end
context "Proposal notifications" do
scenario "Summary stats" do
proposal = create(:proposal)
create(:proposal_notification, proposal: proposal)
create(:proposal_notification, proposal: proposal)
create(:proposal_notification)
visit admin_stats_path
click_link "Proposal notifications"
within("#proposal_notifications_count") do
expect(page).to have_content "3"
end
within("#proposals_with_notifications_count") do
expect(page).to have_content "2"
end
end
scenario "Index" do
3.times { create(:proposal_notification) }
visit admin_stats_path
click_link "Proposal notifications"
expect(page).to have_css(".proposal_notification", count: 3)
ProposalNotification.all.each do |proposal_notification|
expect(page).to have_content proposal_notification.title
expect(page).to have_content proposal_notification.body
end
end
end
context "Direct messages" do
scenario "Summary stats" do
sender = create(:user, :level_two)
create(:direct_message, sender: sender)
create(:direct_message, sender: sender)
create(:direct_message)
visit admin_stats_path
click_link "Direct messages"
within("#direct_messages_count") do
expect(page).to have_content "3"
end
within("#users_who_have_sent_message_count") do
expect(page).to have_content "2"
end
end
end
end end