From 1f9945d0aac761e0591302e5e401df7b91a02264 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Nov 2016 13:36:00 +0100 Subject: [PATCH] Implements answering questions --- app/controllers/polls/questions_controller.rb | 2 +- app/views/{poll => polls}/questions/_answers.html.erb | 2 +- app/views/polls/questions/answer.js.erb | 1 + app/views/polls/show.html.erb | 4 ++-- config/routes.rb | 2 +- spec/features/polls_spec.rb | 6 +++--- 6 files changed, 9 insertions(+), 8 deletions(-) rename app/views/{poll => polls}/questions/_answers.html.erb (94%) create mode 100644 app/views/polls/questions/answer.js.erb diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index bebb7ab4a..dcf459485 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -1,7 +1,7 @@ class Polls::QuestionsController < ApplicationController load_and_authorize_resource :poll - load_and_authorize_resource :question, through: :poll + load_and_authorize_resource :question, class: 'Poll::Question', through: :poll def answer partial_result = @question.partial_results.find_or_initialize_by(author: current_user, diff --git a/app/views/poll/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb similarity index 94% rename from app/views/poll/questions/_answers.html.erb rename to app/views/polls/questions/_answers.html.erb index 94eed7045..ee76706fc 100644 --- a/app/views/poll/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -8,7 +8,7 @@ <% else %> <%= link_to answer, - answer_poll_question_path(poll_id: question.poll_id, question_id: question.id, answer: answer), + answer_poll_question_path(poll_id: question.poll_id, id: question.id, answer: answer), method: :post, remote: true, class: "button secondary hollow" %> diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb new file mode 100644 index 000000000..aabbd8d89 --- /dev/null +++ b/app/views/polls/questions/answer.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>'); diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 6282b112f..ad7818a78 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -30,7 +30,7 @@ <%= question.title %>
- <%= render 'poll/questions/answers', question: question %> + <%= render 'polls/questions/answers', question: question %>
<% end %> @@ -47,7 +47,7 @@ <%= question.title %>
- <%= render 'poll/questions/answers', question: question %> + <%= render 'polls/questions/answers', question: question %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2e0283152..95e5a87b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,7 +86,7 @@ Rails.application.routes.draw do end resources :polls, only: [:show, :index] do - resources :questions, only: [] do + resources :questions, only: [], controller: 'polls/questions' do post :answer, on: :member end end diff --git a/spec/features/polls_spec.rb b/spec/features/polls_spec.rb index 4276c91f0..9270d5696 100644 --- a/spec/features/polls_spec.rb +++ b/spec/features/polls_spec.rb @@ -157,10 +157,10 @@ feature 'Polls' do expect(page).to have_link('Chewbacca') end - xscenario 'Level 2 users who have already answered' do + scenario 'Level 2 users who have already answered' do question = create(:poll_question, poll: poll, geozone_ids:[geozone.id], valid_answers: 'Han Solo, Chewbacca') user = create(:user, :level_two, geozone: geozone) - create(:question_answer, question: question, author: user, answer: 'Chewbacca') + create(:poll_partial_result, question: question, author: user, answer: 'Chewbacca') login_as user visit poll_path(poll) @@ -169,7 +169,7 @@ feature 'Polls' do expect(page).to have_content('Chewbacca') end - xscenario 'Level 2 users answering', :js do + scenario 'Level 2 users answering', :js do create(:poll_question, poll: poll, geozone_ids: [geozone.id], valid_answers: 'Han Solo, Chewbacca') user = create(:user, :level_two, geozone: geozone) login_as user