20171003 - [WIP] Functionality and tests for polls comments
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
class PollsController < ApplicationController
|
||||
include CommentableActions
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
has_filters %w{current expired incoming}
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
|
||||
::Poll::Answer # trigger autoload
|
||||
|
||||
@@ -13,6 +15,9 @@ class PollsController < ApplicationController
|
||||
def show
|
||||
@questions = @poll.questions.for_render.sort_for_list
|
||||
|
||||
@commentable = @poll
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
|
||||
@answers_by_question_id = {}
|
||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||
poll_answers.each do |answer|
|
||||
|
||||
@@ -12,7 +12,7 @@ module FlagsHelper
|
||||
|
||||
def flagged?(flaggable)
|
||||
if flaggable.is_a? Comment
|
||||
@comment_flags[flaggable.id]
|
||||
@comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll"
|
||||
else
|
||||
Flag.flagged?(current_user, flaggable)
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
|
||||
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze
|
||||
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic Poll).freeze
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
@@ -22,6 +22,7 @@ class CommentNotifier
|
||||
end
|
||||
|
||||
def email_on_comment?
|
||||
return false if @comment.commentable.is_a?(Poll)
|
||||
commentable_author = @comment.commentable.author
|
||||
commentable_author != @author && commentable_author.email_on_comment?
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Poll < ActiveRecord::Base
|
||||
include Imageable
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
||||
has_many :booths, through: :booth_assignments
|
||||
has_many :partial_results, through: :booth_assignments
|
||||
@@ -9,8 +10,10 @@ class Poll < ActiveRecord::Base
|
||||
has_many :officer_assignments, through: :booth_assignments
|
||||
has_many :officers, through: :officer_assignments
|
||||
has_many :questions
|
||||
has_many :comments, as: :commentable
|
||||
|
||||
has_and_belongs_to_many :geozones
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
|
||||
92
app/views/polls/questions/show.html.erb
Normal file
92
app/views/polls/questions/show.html.erb
Normal file
@@ -0,0 +1,92 @@
|
||||
<% provide :title do %><%= @question.title %><% end %>
|
||||
|
||||
<div class="expanded no-margin-top dark-heading">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column padding">
|
||||
<%= back_link_to %>
|
||||
|
||||
<h1><%= @question.title %></h1>
|
||||
|
||||
<% if @question.proposal.present? %>
|
||||
<div class="margin-bottom">
|
||||
<%= link_to t('poll_questions.show.original_proposal'), @question.proposal %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if can? :answer, @question %>
|
||||
<%= link_to t('poll_questions.show.answer_this_question'),
|
||||
@question.poll,
|
||||
class: 'large button' %>
|
||||
<% else %>
|
||||
<%= render 'polls/reasons_for_not_answering', poll: @question.poll %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column info">
|
||||
<p>
|
||||
<span class="title">
|
||||
<strong><%= t('poll_questions.show.author') %></strong>
|
||||
</span>
|
||||
<br>
|
||||
<% if @question.author_visible_name.present? %>
|
||||
<%= @question.author_visible_name %>
|
||||
<% else %>
|
||||
<%= link_to @question.author.name, @question.author %>
|
||||
<% end %>
|
||||
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<span class="title">
|
||||
<strong><%= t('poll_questions.show.poll') %></strong>
|
||||
</span>
|
||||
<br>
|
||||
<%= link_to @question.poll.name, @question.poll %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<span class="title">
|
||||
<strong><%= t('poll_questions.show.dates_title') %></strong>
|
||||
</span>
|
||||
<br>
|
||||
<%= poll_dates(@question.poll) %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @question.video_url.present? %>
|
||||
<div class="row margin-top poll-question-show">
|
||||
<div class="small-12 medium-9 column">
|
||||
<div class="video-link">
|
||||
<p>
|
||||
<span class="icon-video"></span>
|
||||
<strong><%= t('proposals.show.title_video_url') %></strong>
|
||||
</p>
|
||||
<%= text_with_links @question.video_url %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h3><%= t('poll_questions.show.more_info') %></h3>
|
||||
<%= @question.description %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="questions-tabs" role="tablist">
|
||||
<%= render "polls/questions/filter_subnav" %>
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-comments">
|
||||
<%= render "shared/comments" %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-documents">
|
||||
<%= render 'documents/documents',
|
||||
documents: @question.documents,
|
||||
max_documents_allowed: Poll::Question.max_documents_allowed %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -79,6 +79,10 @@
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- /. EACH ANSWER DO -->
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-comments">
|
||||
<%= render "shared/comments" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
31
app/views/shared/_comments.html.erb
Normal file
31
app/views/shared/_comments.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@commentable), @comment_tree.comments, @comment_tree.comment_authors, @commentable.comments_count, @comment_flags] do %>
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<h2>
|
||||
<%= t("shared.comments.title") %>
|
||||
<span class="js-comments-count">(<%= @commentable.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @commentable, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
<div data-alert class="callout primary">
|
||||
<%= t("shared.comments.login_to_comment",
|
||||
signin: link_to(t("votes.signin"), new_user_session_path),
|
||||
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @comment_tree.root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', comment: comment %>
|
||||
<% end %>
|
||||
<%= paginate @comment_tree.root_comments %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
7
db/migrate/20171003143034_add_comments_count_to_polls.rb
Normal file
7
db/migrate/20171003143034_add_comments_count_to_polls.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class AddCommentsCountToPolls < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :polls, :comments_count, :integer, default: 0
|
||||
add_column :polls, :author_id, :integer
|
||||
add_column :polls, :hidden_at, :datetime
|
||||
end
|
||||
end
|
||||
@@ -792,6 +792,9 @@ ActiveRecord::Schema.define(version: 20171004151553) do
|
||||
t.boolean "geozone_restricted", default: false
|
||||
t.text "summary"
|
||||
t.text "description"
|
||||
t.integer "comments_count", default: 0
|
||||
t.integer "author_id"
|
||||
t.datetime "hidden_at"
|
||||
end
|
||||
|
||||
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
|
||||
|
||||
@@ -256,5 +256,38 @@ feature 'Polls' do
|
||||
expect(page).to have_link('Han Solo')
|
||||
end
|
||||
|
||||
scenario 'User can write comments' do
|
||||
create(:comment, commentable: poll)
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_css('.comment', count: 1)
|
||||
|
||||
comment = Comment.last
|
||||
within first('.comment') do
|
||||
expect(page).to have_content comment.user.name
|
||||
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
|
||||
expect(page).to have_content comment.body
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'user can reply to comment' do
|
||||
oliver = create(:user, username: 'Oliver Atom')
|
||||
benji = create(:user, username: 'Benji Prince')
|
||||
create(:comment, commentable: poll, user: oliver)
|
||||
|
||||
login_as(oliver)
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content oliver.username
|
||||
end
|
||||
|
||||
scenario 'user can upvote a comment' do
|
||||
|
||||
end
|
||||
|
||||
scenario 'user can downvote a comment' do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user