diff --git a/app/controllers/dashboard/polls_controller.rb b/app/controllers/dashboard/polls_controller.rb
index 360f99f60..9f38c3459 100644
--- a/app/controllers/dashboard/polls_controller.rb
+++ b/app/controllers/dashboard/polls_controller.rb
@@ -12,10 +12,6 @@ class Dashboard::PollsController < Dashboard::BaseController
@poll = Poll.new
end
- def show
- authorize! :manage_polls, proposal
- end
-
def create
authorize! :manage_polls, proposal
@@ -36,7 +32,7 @@ class Dashboard::PollsController < Dashboard::BaseController
respond_to do |format|
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) }
else
format.html { render :edit }
@@ -45,11 +41,6 @@ class Dashboard::PollsController < Dashboard::BaseController
end
end
- def results
- authorize! :manage_polls, proposal
- @partial_results = poll.partial_results
- end
-
private
def poll
diff --git a/app/views/dashboard/polls/_poll.html.erb b/app/views/dashboard/polls/_poll.html.erb
index f437428ac..b3a4eadeb 100644
--- a/app/views/dashboard/polls/_poll.html.erb
+++ b/app/views/dashboard/polls/_poll.html.erb
@@ -21,7 +21,7 @@
<% if poll.incoming? %>
<%= link_to t('.edit_poll'), edit_proposal_dashboard_poll_path(proposal, poll), class: 'button hollow' %>
<% 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 %>
diff --git a/app/views/dashboard/polls/_poll_header.html.erb b/app/views/dashboard/polls/_poll_header.html.erb
deleted file mode 100644
index 7bc148ca5..000000000
--- a/app/views/dashboard/polls/_poll_header.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
- <%= poll.name %>
-
-
-
-
-
-
- <%= t("admin.polls.index.dates") %>
-
- <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %>
-
-
- <% if poll.geozone_restricted %>
-
- <%= t("admin.polls.index.geozone_restricted") %>
-
- <%= poll.geozones.pluck(:name).to_sentence %>
-
- <% end %>
-
diff --git a/app/views/dashboard/polls/_questions.html.erb b/app/views/dashboard/polls/_questions.html.erb
deleted file mode 100644
index 16355e84d..000000000
--- a/app/views/dashboard/polls/_questions.html.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-
<%= t("admin.polls.show.questions_title") %>
-
-<% if poll.questions.empty? %>
-
- <%= t('admin.polls.show.no_questions') %>
-
-<% else %>
-
-
-
- | <%= t('admin.polls.show.table_title') %> |
-
-
- <% poll.questions.each do |question| %>
-
- |
-
- <%= question.title %>
-
- |
-
- <% end %>
-
-<% end %>
diff --git a/app/views/dashboard/polls/_subnav.html.erb b/app/views/dashboard/polls/_subnav.html.erb
deleted file mode 100644
index bad924c2a..000000000
--- a/app/views/dashboard/polls/_subnav.html.erb
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
diff --git a/app/views/dashboard/polls/results.html.erb b/app/views/dashboard/polls/results.html.erb
deleted file mode 100644
index 4074ee875..000000000
--- a/app/views/dashboard/polls/results.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<%= render 'poll_header' %>
-
-
- <%= render "subnav" %>
-
-
<%= t("admin.results.index.title") %>
-
- <% if @partial_results.empty? %>
-
- <%= t("admin.results.index.no_results") %>
-
- <% 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 %>
-
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index 519a9981a..a535c45fc 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -576,7 +576,7 @@ en:
responses:
one: "%{count} response"
other: "%{count} responses"
- view_responses: View responses
+ view_results: View results
edit_poll: Edit survey
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
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index e4823db03..8c310c8de 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -576,7 +576,7 @@ es:
responses:
one: "%{count} respuesta"
other: "%{count} respuestas"
- view_responses: Ver respuestas
+ view_results: Ver resultados
edit_poll: Editar encuesta
show_results: Mostrar resultados
show_results_help: Si marcas esta casilla los resultados serán públicos y todos los usuarios podrán verlos
diff --git a/config/routes/proposal.rb b/config/routes/proposal.rb
index e933e32f1..a0674cb9f 100644
--- a/config/routes/proposal.rb
+++ b/config/routes/proposal.rb
@@ -21,11 +21,7 @@ resources :proposals do
end
namespace :dashboard do
- resources :polls, except: :destroy do
- member do
- get :results
- end
- end
+ resources :polls, except: [:show, :destroy]
end
member do
diff --git a/spec/features/dashboard/polls_spec.rb b/spec/features/dashboard/polls_spec.rb
index 258aeff9f..6ca915652 100644
--- a/spec/features/dashboard/polls_spec.rb
+++ b/spec/features/dashboard/polls_spec.rb
@@ -40,4 +40,84 @@ feature 'Polls' do
expect(page).to have_content "Upcoming poll"
expect(page).to have_content I18n.l(start_date.to_date)
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
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index a4e1d246d..a0f6a7c90 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -1029,12 +1029,12 @@ describe Budget::Investment do
investment.heading = heading2
investment.store_reclassified_votes("heading_changed")
- reclassified_vote = Budget::ReclassifiedVote.first
-
expect(Budget::ReclassifiedVote.count).to eq(3)
- expect(reclassified_vote.investment_id).to eq(investment.id)
- expect(reclassified_vote.user_id).to eq(Budget::Ballot.first.user.id)
- expect(reclassified_vote.reason).to eq("heading_changed")
+ Budget::ReclassifiedVote.find_each do |reclassified_vote|
+ expect(reclassified_vote.investment_id).to eq(investment.id)
+ 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
diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb
index d9ebaa4cd..09c6e2f51 100644
--- a/spec/models/poll/poll_spec.rb
+++ b/spec/models/poll/poll_spec.rb
@@ -33,6 +33,51 @@ describe Poll do
poll.ends_at = 2.months.ago
expect(poll).not_to be_valid
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
describe "#opened?" do