Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll comments #1961

Merged
6 changes: 5 additions & 1 deletion app/controllers/polls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class PollsController < ApplicationController

include PollsHelper

load_and_authorize_resource

has_filters %w{current expired incoming}
has_orders %w{most_voted newest oldest}, only: :show
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only these orders are necessary:
has_orders %w{most_voted newest oldest}, only: :show


::Poll::Answer # trigger autoload

Expand All @@ -15,11 +15,15 @@ def index
def show
@questions = @poll.questions.for_render.sort_for_list
@token = poll_voter_token(@poll, current_user)

@answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
poll_answers.each do |answer|
@answers_by_question_id[answer.question_id] = answer.answer
end

@commentable = @poll
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
end

end
2 changes: 1 addition & 1 deletion app/helpers/flags_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def show_unflag_action?(flaggable)

def flagged?(flaggable)
if flaggable.is_a? Comment
@comment_flags[flaggable.id]
@comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Warning of the PR, please state that this feature is not available.
We'll create a new issue to deal with it later

else
Flag.flagged?(current_user, flaggable)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!


acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
Expand Down
1 change: 1 addition & 0 deletions app/models/comment_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def send_reply_email
end

def email_on_comment?
return false if @comment.commentable.is_a?(Poll)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that emails will not be send, should also be included in the Warning section of the PR

commentable_author = @comment.commentable.author
commentable_author != @author && commentable_author.email_on_comment?
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/poll.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Poll < ActiveRecord::Base
include Imageable

acts_as_paranoid column: :hidden_at
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no requirement to hide Polls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the association, it raises an error

ActionView::Template::Error (undefined local variable or method `with_hidden' for #<Poll::ActiveRecord_Relation:0x007ff01d39d0b8>):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove both:

  acts_as_paranoid column: :hidden_at
  include ActsAsParanoidAliases

add_column :polls, :hidden_at, :datetime from migration

include ActsAsParanoidAliases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zamuro this won't be neccesary, its not a requirement to make the Poll hidden

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When removing hidden_at from migration and these two lines:


  5) Polls Show user b can access to comments from user a
     Failure/Error: belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true
     
     ActionView::Template::Error:
       undefined local variable or method `with_hidden' for #<Poll::ActiveRecord_Relation:0x0055f8a558f4a0>
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:136:in `method_missing'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:99:in `method_missing'
     # ./app/models/comment.rb:22:in `block in <class:Comment>'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/builder/association.rb:65:in `instance_exec'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/builder/association.rb:65:in `block in initialize'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:191:in `instance_exec'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:191:in `eval_scope'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:155:in `block (2 levels) in add_constraints'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:154:in `each'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:154:in `block in add_constraints'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:141:in `each'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:141:in `each_with_index'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:141:in `add_constraints'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:39:in `scope'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association_scope.rb:5:in `scope'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association.rb:97:in `association_scope'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association.rb:86:in `scope'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/singular_association.rb:42:in `get_records'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/singular_association.rb:57:in `find_target'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association.rb:138:in `load_target'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/association.rb:53:in `reload'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/singular_association.rb:9:in `reader'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/bullet-5.5.1/lib/bullet/active_record42.rb:215:in `reader'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/associations/builder/association.rb:115:in `commentable'
     # ./app/views/comments/_comment.html.erb:2:in `_app_views_comments__comment_html_erb___2900209252357399508_47263206653840'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:145:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:166:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:333:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:143:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:309:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/renderer.rb:51:in `render_partial'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/helpers/rendering_helper.rb:35:in `render'
     # ./app/views/shared/_comments.html.erb:25:in `block (2 levels) in _app_views_shared__comments_html_erb___3346234190162093915_47263181704260'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:46:in `each'
     # ./app/views/shared/_comments.html.erb:24:in `block in _app_views_shared__comments_html_erb___3346234190162093915_47263181704260'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/helpers/cache_helper.rb:117:in `cache'
     # ./app/views/shared/_comments.html.erb:1:in `_app_views_shared__comments_html_erb___3346234190162093915_47263181704260'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:145:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:166:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:333:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:143:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/partial_renderer.rb:309:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/renderer.rb:51:in `render_partial'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/helpers/rendering_helper.rb:35:in `render'
     # ./app/views/polls/show.html.erb:46:in `_app_views_polls_show_html_erb__504409128911861219_47263182546540'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:145:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:166:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:333:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/template.rb:143:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/template_renderer.rb:14:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/renderer.rb:46:in `render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/renderer/renderer.rb:27:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/rendering.rb:100:in `_render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/streaming.rb:217:in `_render_template'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/rendering.rb:83:in `render_to_body'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/abstract_controller/rendering.rb:25:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/rendering.rb:16:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/core_ext/benchmark.rb:12:in `ms'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:43:in `render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/abstract_controller/base.rb:198:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/rendering.rb:10:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:117:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:505:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/abstract_controller/callbacks.rb:19:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/rescue.rb:29:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/notifications.rb:164:in `instrument'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/abstract_controller/base.rb:137:in `process'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionview-4.2.9/lib/action_view/rendering.rb:30:in `process'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal.rb:196:in `dispatch'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_controller/metal.rb:237:in `block in action'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/routing/route_set.rb:43:in `serve'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/journey/router.rb:43:in `block in serve'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/journey/router.rb:30:in `each'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/journey/router.rb:30:in `serve'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/routing/route_set.rb:817:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/turnout-2.4.0/lib/rack/turnout.rb:25:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:407:in `call_app!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:265:in `mock_call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:184:in `call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:167:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:407:in `call_app!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:265:in `mock_call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:184:in `call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:167:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:407:in `call_app!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:265:in `mock_call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:184:in `call!'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:167:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-attack-5.0.1/lib/rack/attack.rb:147:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/bullet-5.5.1/lib/bullet/rack.rb:12:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/warden-1.2.7/lib/warden/manager.rb:36:in `block in call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/warden-1.2.7/lib/warden/manager.rb:35:in `catch'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/warden-1.2.7/lib/warden/manager.rb:35:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/etag.rb:24:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/conditionalget.rb:25:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/flash.rb:260:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:225:in `context'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:220:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/cookies.rb:560:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/query_cache.rb:36:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rollbar-2.14.1/lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rollbar-2.14.1/lib/rollbar.rb:145:in `scoped'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rollbar-2.14.1/lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rollbar-2.14.1/lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/railties-4.2.9/lib/rails/rack/logger.rb:38:in `call_app'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/railties-4.2.9/lib/rails/rack/logger.rb:20:in `block in call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/tagged_logging.rb:68:in `block in tagged'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/tagged_logging.rb:26:in `tagged'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/tagged_logging.rb:68:in `tagged'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/railties-4.2.9/lib/rails/rack/logger.rb:20:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/ahoy_matey-1.6.0/lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/quiet_assets-1.1.0/lib/quiet_assets.rb:27:in `call_with_quiet_assets'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/request_store-1.3.2/lib/request_store/middleware.rb:9:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/request_id.rb:21:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/methodoverride.rb:22:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/runtime.rb:18:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/activesupport-4.2.9/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/lock.rb:17:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/actionpack-4.2.9/lib/action_dispatch/middleware/static.rb:120:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/sendfile.rb:113:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/railties-4.2.9/lib/rails/engine.rb:518:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/railties-4.2.9/lib/rails/application.rb:165:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/urlmap.rb:66:in `block in call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/urlmap.rb:50:in `each'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-1.6.8/lib/rack/urlmap.rb:50:in `call'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/rack_test/browser.rb:64:in `process'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/rack_test/browser.rb:36:in `process_and_follow_redirects'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/rack_test/browser.rb:22:in `visit'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/rack_test/driver.rb:44:in `visit'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/session.rb:269:in `visit'
     # /home/manuel/.rvm/gems/ruby-2.3.2/gems/capybara-2.14.4/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
     # ./spec/features/polls/polls_spec.rb:238:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NameError:
     #   undefined local variable or method `with_hidden' for #<Poll::ActiveRecord_Relation:0x0055f8a558f4a0>
     #   /home/manuel/.rvm/gems/ruby-2.3.2/gems/activerecord-4.2.9/lib/active_record/relation/delegation.rb:136:in `method_missing'

which comes from comment model:

  belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines, involve the Gem https://github.com/rubysherpas/paranoia
Which is used, to hide records from DB without actually erasing them.

Polls, do not need to have this functionality.
Please remove these two lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are required by comments model, and while removing it, raises errors in polls comments claiming it needs hidden_at field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in #1961 (comment)

has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :booths, through: :booth_assignments
has_many :partial_results, through: :booth_assignments
Expand All @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Poll does not have an author. It is always the Government.
Please remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When removed, polls show view raises an error requiring "author_id" field

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove this as well as the author_id column, and find any commentable.autor usage and put a unless @comment.commentable.is_a?(Poll) check after it


validates :name, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="row">
<div class="small-12 column margin-top">
<%= back_link_to commentable_path(@comment),
t("comments.show.return_to_commentable") + @comment.commentable.title %>
t("comments.show.return_to_commentable") + @comment.commentable.title unless @comment != "Poll" %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State this in the Warning section too, please

</div>
</div>

Expand Down
24 changes: 24 additions & 0 deletions app/views/polls/_comments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@poll), @comment_tree.comments, @comment_tree.comment_authors, @poll.comments_count, @comment_flags] do %>
<div class="row comments">
<div id="comments" class="small-12 column">
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>

<% if user_signed_in? %>
<%= render 'comments/form', {commentable: @poll, parent_id: nil, toggeable: false} %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've a @commentable variable already instead of using @poll

<% else %>
<br>

<div data-alert class="callout primary">
<%= t("polls.show.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>
<% end %>
14 changes: 14 additions & 0 deletions app/views/polls/_filter_subnav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="small-12 column">
<ul class="tabs" data-tabs id="polls-tabs">
<li class="tabs-title is-active">
<%= link_to "#tab-comments" do %>
<h3>
<%= t("polls.show.comments_tab") %>
<span class="js-comments-count">(<%= @poll.comments_count %>)</span>
</h3>
<% end %>
</li>
</ul>
</div>
</div>
9 changes: 9 additions & 0 deletions app/views/polls/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,14 @@
</div>
<% end %>
</div>

</div>
</div>

<div class="tabs-content" data-tabs-content="proposals-tabs" role="tablist">
Copy link
Collaborator

@decabeza decabeza Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be data-tabs-content="polls-tabs" and adds to class="tabs-content"a margin-top class 😉

<%= render "filter_subnav" %>

<div class="tabs-panel is-active" id="tab-comments">
<%= render "comments" %>
</div>
</div>
2 changes: 2 additions & 0 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ en:
already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten."
back: Back to voting
cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate."
comments_tab: Comments
login_to_comment: You must %{signin} or %{signup} to leave a comment.
signin: Sign in
signup: Sign up
cant_answer_verify_html: "You must %{verify_link} in order to answer."
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ es:
already_voted_in_web: "Ya has participado en esta votación. Si vuelves a votar se sobreescribirá tu resultado anterior."
back: Volver a votaciones
cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar."
comments_tab: Comentarios
login_to_comment: Necesitas %{signin} o %{signup} para comentar.
signin: iniciar sesión
signup: registrarte
cant_answer_verify_html: "Por favor %{verify_link} para poder responder."
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20171003143034_add_comments_count_to_polls.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove these two lines:

add_column :polls, :author_id, :integer
add_column :polls, :hidden_at, :datetime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two fields are required by comments model. When removing it from polls (and removing the columns from the migration), raises an error asking for either "hidden_at" or "author_id".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry @zamuro you are right!
There is probably a way to bypass this, but it's a situation we have accepted in the past.
Don't worry about it 🙏 👍

end
end
3 changes: 3 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,9 @@
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hidden_at is part of the unnecesary ActsAsParanoidAliases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update schema after removing the previous columns from the migration file.

end

add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
Expand Down