Implements answering questions
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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" %>
|
||||
1
app/views/polls/questions/answer.js.erb
Normal file
1
app/views/polls/questions/answer.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>');
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user