View questions now is View results and redirects to results
in public view.

Fixed flaky spec that was making the tests fail.

Added missing specs for polls feature as well as poll model.
This commit is contained in:
Juan Salvador Pérez García
2018-07-19 17:15:05 +02:00
parent 2823d53121
commit 4b8cc85c49
12 changed files with 135 additions and 116 deletions

View File

@@ -12,10 +12,6 @@ class Dashboard::PollsController < Dashboard::BaseController
@poll = Poll.new @poll = Poll.new
end end
def show
authorize! :manage_polls, proposal
end
def create def create
authorize! :manage_polls, proposal authorize! :manage_polls, proposal
@@ -36,7 +32,7 @@ class Dashboard::PollsController < Dashboard::BaseController
respond_to do |format| respond_to do |format|
if poll.update(poll_params) if poll.update(poll_params)
format.html { redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") } format.html { redirect_to proposal_dashboard_polls_path(proposal), notice: t("flash.actions.update.poll") }
format.json { respond_with_bip(poll) } format.json { respond_with_bip(poll) }
else else
format.html { render :edit } format.html { render :edit }
@@ -45,11 +41,6 @@ class Dashboard::PollsController < Dashboard::BaseController
end end
end end
def results
authorize! :manage_polls, proposal
@partial_results = poll.partial_results
end
private private
def poll def poll

View File

@@ -21,7 +21,7 @@
<% if poll.incoming? %> <% if poll.incoming? %>
<%= link_to t('.edit_poll'), edit_proposal_dashboard_poll_path(proposal, poll), class: 'button hollow' %> <%= link_to t('.edit_poll'), edit_proposal_dashboard_poll_path(proposal, poll), class: 'button hollow' %>
<% else %> <% else %>
<%= link_to t('.view_responses'), proposal_dashboard_poll_path(proposal, poll), class: 'button' %> <%= link_to t('.view_results'), results_poll_path(poll), class: 'button', target: '_blank' %>
<% end %> <% end %>
</div> </div>
<div class="card-section"> <div class="card-section">

View File

@@ -1,21 +0,0 @@
<h2 class="inline-block">
<%= poll.name %>
</h2>
<div class="clear"></div>
<div class="callout highlight">
<div class="inline-block">
<strong><%= t("admin.polls.index.dates") %></strong>
<br>
<%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %>
</div>
<% if poll.geozone_restricted %>
<div class="inline-block margin-left">
<strong><%= t("admin.polls.index.geozone_restricted") %></strong>
<br>
<%= poll.geozones.pluck(:name).to_sentence %>
</div>
<% end %>
</div>

View File

@@ -1,24 +0,0 @@
<h3><%= t("admin.polls.show.questions_title") %></h3>
<% if poll.questions.empty? %>
<div class="callout primary margin-top">
<%= t('admin.polls.show.no_questions') %>
</div>
<% else %>
<table class="fixed margin">
<thead>
<tr>
<th><%= t('admin.polls.show.table_title') %></th>
</tr>
</thead>
<% poll.questions.each do |question| %>
<tr id="<%= dom_id(question) %>">
<td>
<strong>
<%= question.title %>
</strong>
</td>
</tr>
<% end %>
</table>
<% end %>

View File

@@ -1,30 +0,0 @@
<ul class="menu simple clear" id="assigned-resources-tabs">
<% if action_name == "show" %>
<li class="is-active">
<h2>
<%= t("admin.polls.show.questions_tab") %>
(<%= poll.questions.count %>)
</h2>
</li>
<% else %>
<li>
<%= link_to proposal_dashboard_poll_path(proposal, poll) do %>
<%= t("admin.polls.show.questions_tab") %>
(<%= poll.questions.count %>)
<% end %>
</li>
<% end %>
<% if action_name == "results" %>
<li class="is-active">
<h2>
<%= t("admin.polls.show.results_tab") %>
</h2>
</li>
<% else %>
<li>
<%= link_to t("admin.polls.show.results_tab"), results_proposal_dashboard_poll_path(proposal, poll) %>
</li>
<% end %>
</ul>

View File

@@ -1,18 +0,0 @@
<%= render 'poll_header' %>
<div id="poll-resources">
<%= render "subnav" %>
<h3><%= t("admin.results.index.title") %></h3>
<% if @partial_results.empty? %>
<div class="callout primary margin-top">
<%= t("admin.results.index.no_results") %>
</div>
<% else %>
<%= render "/admin/poll/polls/recount", resource: @poll %>
<%= render "/admin/poll/polls/result" %>
<%= render "/admin/poll/polls/results_by_booth" %>
<%= render "/admin/poll/polls/show_results", resource: @poll %>
<% end %>
</div>

View File

@@ -576,7 +576,7 @@ en:
responses: responses:
one: "%{count} response" one: "%{count} response"
other: "%{count} responses" other: "%{count} responses"
view_responses: View responses view_results: View results
edit_poll: Edit survey edit_poll: Edit survey
show_results: Show results show_results: Show results
show_results_help: If you check this box the results will be public and all users will be able to see them show_results_help: If you check this box the results will be public and all users will be able to see them

View File

@@ -576,7 +576,7 @@ es:
responses: responses:
one: "%{count} respuesta" one: "%{count} respuesta"
other: "%{count} respuestas" other: "%{count} respuestas"
view_responses: Ver respuestas view_results: Ver resultados
edit_poll: Editar encuesta edit_poll: Editar encuesta
show_results: Mostrar resultados show_results: Mostrar resultados
show_results_help: Si marcas esta casilla los resultados serán públicos y todos los usuarios podrán verlos show_results_help: Si marcas esta casilla los resultados serán públicos y todos los usuarios podrán verlos

View File

@@ -21,11 +21,7 @@ resources :proposals do
end end
namespace :dashboard do namespace :dashboard do
resources :polls, except: :destroy do resources :polls, except: [:show, :destroy]
member do
get :results
end
end
end end
member do member do

View File

@@ -40,4 +40,84 @@ feature 'Polls' do
expect(page).to have_content "Upcoming poll" expect(page).to have_content "Upcoming poll"
expect(page).to have_content I18n.l(start_date.to_date) expect(page).to have_content I18n.l(start_date.to_date)
end end
scenario 'Edit poll is allowed for upcoming polls' do
poll = create(:poll, :incoming, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).to have_content('Edit survey')
click_link 'Edit survey'
end
click_button 'Update poll'
expect(page).to have_content 'Poll updated successfully'
end
scenario 'Edit poll is not allowed for current polls' do
poll = create(:poll, :current, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).not_to have_content('Edit survey')
end
end
scenario 'Edit poll is not allowed for expired polls' do
poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).not_to have_content('Edit survey')
end
end
scenario 'View results not available for upcoming polls' do
poll = create(:poll, :incoming, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).not_to have_content('View results')
end
end
scenario 'View results available for current polls' do
poll = create(:poll, :current, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).to have_content('View results')
end
end
scenario 'View results available for expired polls' do
poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
expect(page).to have_content('View results')
end
end
scenario 'View results redirects to results in public zone', js: true do
poll = create(:poll, :expired, related: proposal)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
click_link 'View results'
end
page.driver.browser.switch_to.window page.driver.browser.window_handles.last do
expect(page.current_path).to eq(results_poll_path(poll))
end
end
end end

View File

@@ -1029,12 +1029,12 @@ describe Budget::Investment do
investment.heading = heading2 investment.heading = heading2
investment.store_reclassified_votes("heading_changed") investment.store_reclassified_votes("heading_changed")
reclassified_vote = Budget::ReclassifiedVote.first
expect(Budget::ReclassifiedVote.count).to eq(3) expect(Budget::ReclassifiedVote.count).to eq(3)
expect(reclassified_vote.investment_id).to eq(investment.id) Budget::ReclassifiedVote.find_each do |reclassified_vote|
expect(reclassified_vote.user_id).to eq(Budget::Ballot.first.user.id) expect(reclassified_vote.investment_id).to eq(investment.id)
expect(reclassified_vote.reason).to eq("heading_changed") expect(reclassified_vote.reason).to eq("heading_changed")
expect(Budget::Ballot.where(user_id: reclassified_vote.user_id)).not_to be_empty
end
end end
end end

View File

@@ -33,6 +33,51 @@ describe Poll do
poll.ends_at = 2.months.ago poll.ends_at = 2.months.ago
expect(poll).not_to be_valid expect(poll).not_to be_valid
end end
it 'no overlapping polls for proposal polls are allowed' do
end
end
describe 'proposal polls specific validations' do
let(:proposal) { create(:proposal) }
let(:poll) { build(:poll, related: proposal) }
it 'is valid when overlapping but different proposals' do
other_proposal = create(:proposal)
_other_poll = create(:poll, related: other_proposal, starts_at: poll.starts_at, ends_at: poll.ends_at)
expect(poll).to be_valid
end
it 'is valid when same proposal but not overlapping' do
_other_poll = create(:poll, related: proposal, starts_at: poll.ends_at + 1.day, ends_at: poll.ends_at + 8.days)
expect(poll).to be_valid
end
it 'is not valid when overlaps from the beginning' do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at - 8.days, ends_at: poll.starts_at)
expect(poll).not_to be_valid
end
it 'is not valid when overlaps from the end' do
_other_poll = create(:poll, related: proposal, starts_at: poll.ends_at, ends_at: poll.ends_at + 8.days)
expect(poll).not_to be_valid
end
it 'is not valid when overlaps with same interval' do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at, ends_at: poll.ends_at)
expect(poll).not_to be_valid
end
it 'is not valid when overlaps with interval contained' do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at + 1.day, ends_at: poll.ends_at - 1.day)
expect(poll).not_to be_valid
end
it 'is not valid when overlaps with interval containing' do
_other_poll = create(:poll, related: proposal, starts_at: poll.starts_at - 8.days, ends_at: poll.ends_at + 8.days)
expect(poll).not_to be_valid
end
end end
describe "#opened?" do describe "#opened?" do