diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 0c802e17f..f6f155106 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -7,7 +7,7 @@ class PollsController < ApplicationController end def show - + @questions = @poll.questions.sort_for_list.for_render end end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 75f78fb15..59ff11a70 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -23,6 +23,7 @@ class Poll::Question < ActiveRecord::Base scope :sort_for_list, -> { order('proposal_id IS NULL', :created_at)} scope :for_render, -> { includes(:author, :proposal) } + scope :by_geozone, -> (geozone_id) { joins(:geozones).where(geozones: {id: geozone_id}) } def description super.try :html_safe @@ -45,4 +46,6 @@ class Poll::Question < ActiveRecord::Base end end + + end diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index e9eeb7ca2..71870cedf 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -1,5 +1,10 @@ <%= @poll.name %> -<%= @poll.questions.sort_for_list.each do |question| %> - <%= question.title %> +<% @questions.each do |question| %> +
+ <%= question.title %> + <%= question.valid_answers.each do |valid_answer| %> + <%= link_to valid_answer %> + <% end %> +
<% end %> diff --git a/spec/features/polls_spec.rb b/spec/features/polls_spec.rb index a873c22f4..f206407d2 100644 --- a/spec/features/polls_spec.rb +++ b/spec/features/polls_spec.rb @@ -21,7 +21,12 @@ feature 'Polls' do expect(page).to have_content(poll.name) questions.each do |question| - expect(page).to have_content(question.title) + within("#poll_question_#{question.id}") do + expect(page).to have_content(question.title) + question.valid_answers.each do |answer| + expect(page).to have_link(answer) + end + end end end end