Implements answering questions

This commit is contained in:
kikito
2016-11-14 13:36:00 +01:00
parent 598b1b9c01
commit 1f9945d0aa
6 changed files with 9 additions and 8 deletions

View File

@@ -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,

View File

@@ -8,7 +8,7 @@
</span>
<% 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" %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>');

View File

@@ -30,7 +30,7 @@
<%= question.title %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'poll/questions/answers', question: question %>
<%= render 'polls/questions/answers', question: question %>
</div>
</div>
<% end %>
@@ -47,7 +47,7 @@
<%= question.title %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'poll/questions/answers', question: question %>
<%= render 'polls/questions/answers', question: question %>
</div>
</div>
<% end %>

View File

@@ -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

View File

@@ -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