Merge branch 'master' into polls-admin-polish
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
//= require jquery-ui/widgets/datepicker
|
//= require jquery-ui/widgets/datepicker
|
||||||
//= require jquery-ui/i18n/datepicker-es
|
//= require jquery-ui/i18n/datepicker-es
|
||||||
//= require jquery-ui/widgets/autocomplete
|
//= require jquery-ui/widgets/autocomplete
|
||||||
|
//= require jquery-ui/widgets/sortable
|
||||||
//= require jquery-fileupload/basic
|
//= require jquery-fileupload/basic
|
||||||
//= require foundation
|
//= require foundation
|
||||||
//= require turbolinks
|
//= require turbolinks
|
||||||
@@ -71,6 +72,7 @@
|
|||||||
//= require leaflet
|
//= require leaflet
|
||||||
//= require map
|
//= require map
|
||||||
//= require polls
|
//= require polls
|
||||||
|
//= require sortable
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
App.Comments.initialize();
|
App.Comments.initialize();
|
||||||
@@ -110,6 +112,7 @@ var initialize_modules = function() {
|
|||||||
App.PollsAdmin.initialize();
|
App.PollsAdmin.initialize();
|
||||||
App.Map.initialize();
|
App.Map.initialize();
|
||||||
App.Polls.initialize();
|
App.Polls.initialize();
|
||||||
|
App.Sortable.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
9
app/assets/javascripts/sortable.js.coffee
Normal file
9
app/assets/javascripts/sortable.js.coffee
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
App.Sortable =
|
||||||
|
initialize: ->
|
||||||
|
$(".sortable").sortable
|
||||||
|
update: (event, ui) ->
|
||||||
|
new_order = $(this).sortable('toArray', {attribute: 'data-answer-id'});
|
||||||
|
$.ajax
|
||||||
|
url: $('.sortable').data('js-url'),
|
||||||
|
data: {ordered_list: new_order},
|
||||||
|
type: 'POST'
|
||||||
@@ -18,4 +18,5 @@
|
|||||||
@import 'datepicker_overrides';
|
@import 'datepicker_overrides';
|
||||||
@import 'jquery-ui/autocomplete';
|
@import 'jquery-ui/autocomplete';
|
||||||
@import 'autocomplete_overrides';
|
@import 'autocomplete_overrides';
|
||||||
|
@import 'jquery-ui/sortable';
|
||||||
@import 'leaflet';
|
@import 'leaflet';
|
||||||
|
|||||||
@@ -1596,7 +1596,7 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
&.short {
|
&.short {
|
||||||
height: $line-height * 12;
|
height: rem-calc(300);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
|||||||
render 'admin/poll/questions/answers/documents'
|
render 'admin/poll/questions/answers/documents'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def order_answers
|
||||||
|
::Poll::Question::Answer.order_answers(params[:ordered_list])
|
||||||
|
render nothing: true
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def answer_params
|
def answer_params
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
class PollsController < ApplicationController
|
class PollsController < ApplicationController
|
||||||
|
|
||||||
include PollsHelper
|
include PollsHelper
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
has_filters %w{current expired incoming}
|
has_filters %w{current expired incoming}
|
||||||
|
has_orders %w{most_voted newest oldest}, only: :show
|
||||||
|
|
||||||
::Poll::Answer # trigger autoload
|
::Poll::Answer # trigger autoload
|
||||||
|
|
||||||
@@ -15,11 +15,16 @@ class PollsController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
@questions = @poll.questions.for_render.sort_for_list
|
@questions = @poll.questions.for_render.sort_for_list
|
||||||
@token = poll_voter_token(@poll, current_user)
|
@token = poll_voter_token(@poll, current_user)
|
||||||
|
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
|
||||||
|
|
||||||
@answers_by_question_id = {}
|
@answers_by_question_id = {}
|
||||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||||
poll_answers.each do |answer|
|
poll_answers.each do |answer|
|
||||||
@answers_by_question_id[answer.question_id] = answer.answer
|
@answers_by_question_id[answer.question_id] = answer.answer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@commentable = @poll
|
||||||
|
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module FlagsHelper
|
|||||||
|
|
||||||
def flagged?(flaggable)
|
def flagged?(flaggable)
|
||||||
if flaggable.is_a? Comment
|
if flaggable.is_a? Comment
|
||||||
@comment_flags[flaggable.id]
|
@comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll"
|
||||||
else
|
else
|
||||||
Flag.flagged?(current_user, flaggable)
|
Flag.flagged?(current_user, flaggable)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base
|
|||||||
include HasPublicAuthor
|
include HasPublicAuthor
|
||||||
include Graphqlable
|
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
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class CommentNotifier
|
|||||||
end
|
end
|
||||||
|
|
||||||
def email_on_comment?
|
def email_on_comment?
|
||||||
|
return false if @comment.commentable.is_a?(Poll)
|
||||||
commentable_author = @comment.commentable.author
|
commentable_author = @comment.commentable.author
|
||||||
commentable_author != @author && commentable_author.email_on_comment?
|
commentable_author != @author && commentable_author.email_on_comment?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class Poll < ActiveRecord::Base
|
class Poll < ActiveRecord::Base
|
||||||
include Imageable
|
include Imageable
|
||||||
|
acts_as_paranoid column: :hidden_at
|
||||||
|
include ActsAsParanoidAliases
|
||||||
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
||||||
has_many :booths, through: :booth_assignments
|
has_many :booths, through: :booth_assignments
|
||||||
has_many :partial_results, 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 :officer_assignments, through: :booth_assignments
|
||||||
has_many :officers, through: :officer_assignments
|
has_many :officers, through: :officer_assignments
|
||||||
has_many :questions
|
has_many :questions
|
||||||
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
has_and_belongs_to_many :geozones
|
has_and_belongs_to_many :geozones
|
||||||
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
@@ -24,6 +27,10 @@ class Poll < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
|
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
|
||||||
|
|
||||||
|
def title
|
||||||
|
name
|
||||||
|
end
|
||||||
|
|
||||||
def current?(timestamp = Date.current.beginning_of_day)
|
def current?(timestamp = Date.current.beginning_of_day)
|
||||||
starts_at <= timestamp && timestamp <= ends_at
|
starts_at <= timestamp && timestamp <= ends_at
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Poll::Question < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :answers, class_name: 'Poll::Answer'
|
has_many :answers, class_name: 'Poll::Answer'
|
||||||
has_many :question_answers, class_name: 'Poll::Question::Answer'
|
has_many :question_answers, -> { order 'given_order asc' }, class_name: 'Poll::Question::Answer'
|
||||||
has_many :partial_results
|
has_many :partial_results
|
||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Poll::Question::Answer < ActiveRecord::Base
|
class Poll::Question::Answer < ActiveRecord::Base
|
||||||
include Galleryable
|
include Galleryable
|
||||||
include Documentable
|
include Documentable
|
||||||
documentable max_documents_allowed: 3,
|
documentable max_documents_allowed: 3,
|
||||||
max_file_size: 3.megabytes,
|
max_file_size: 3.megabytes,
|
||||||
@@ -10,8 +10,25 @@ class Poll::Question::Answer < ActiveRecord::Base
|
|||||||
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
validates :given_order, presence: true, uniqueness: { scope: :question_id }
|
||||||
|
|
||||||
|
before_validation :set_order, on: :create
|
||||||
|
|
||||||
def description
|
def description
|
||||||
super.try :html_safe
|
super.try :html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.order_answers(ordered_array)
|
||||||
|
ordered_array.each_with_index do |answer_id, order|
|
||||||
|
find(answer_id).update_attribute(:given_order, (order + 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_order
|
||||||
|
self.given_order = self.class.last_position(question_id) + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.last_position(question_id)
|
||||||
|
where(question_id: question_id).maximum('given_order') || 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,30 +47,32 @@
|
|||||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.videos") %></th>
|
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.videos") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% @question.question_answers.each do |answer| %>
|
<tbody class="sortable" data-js-url="<%= admin_question_answers_order_answers_path(@question.id) %>">
|
||||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
<% @question.question_answers.each do |answer| %>
|
||||||
<td class="align-top"><%= link_to answer.title, admin_answer_path(answer) %></td>
|
<tr id="<%= dom_id(answer) %>" class="poll_question_answer" data-answer-id="<%= answer.id %>">
|
||||||
<td class="align-top break"><%= answer.description %></td>
|
<td class="align-top"><%= link_to answer.title, admin_answer_path(answer) %></td>
|
||||||
<td class="align-top text-center">
|
<td class="align-top break"><%= answer.description %></td>
|
||||||
(<%= answer.images.count %>)
|
<td class="align-top text-center">
|
||||||
<br>
|
(<%= answer.images.count %>)
|
||||||
<%= link_to t("admin.questions.show.answers.images_list"),
|
<br>
|
||||||
admin_answer_images_path(answer) %>
|
<%= link_to t("admin.questions.show.answers.images_list"),
|
||||||
</td>
|
admin_answer_images_path(answer) %>
|
||||||
<td class="align-top text-center">
|
</td>
|
||||||
(<%= answer.documents.count rescue 0 %>)
|
<td class="align-top text-center">
|
||||||
<br>
|
(<%= answer.documents.count rescue 0 %>)
|
||||||
<%= link_to t("admin.questions.show.answers.documents_list"),
|
<br>
|
||||||
admin_answer_documents_path(answer) %>
|
<%= link_to t("admin.questions.show.answers.documents_list"),
|
||||||
</td>
|
admin_answer_documents_path(answer) %>
|
||||||
<td class="align-top text-center">
|
</td>
|
||||||
(<%= answer.videos.count %>)
|
<td class="align-top text-center">
|
||||||
<br>
|
(<%= answer.videos.count %>)
|
||||||
<%= link_to t("admin.questions.show.answers.video_list"),
|
<br>
|
||||||
admin_answer_videos_path(answer) %>
|
<%= link_to t("admin.questions.show.answers.video_list"),
|
||||||
</td>
|
admin_answer_videos_path(answer) %>
|
||||||
</tr>
|
</td>
|
||||||
<% end %>
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<% if @question.video_url.present? %>
|
<% if @question.video_url.present? %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 column margin-top">
|
<div class="small-12 column margin-top">
|
||||||
<%= back_link_to commentable_path(@comment),
|
<%= 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 @commentable.class == Poll %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
24
app/views/polls/_comments.html.erb
Normal file
24
app/views/polls/_comments.html.erb
Normal file
@@ -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} %>
|
||||||
|
<% 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
app/views/polls/_filter_subnav.html.erb
Normal file
14
app/views/polls/_filter_subnav.html.erb
Normal file
@@ -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>
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
<div class="expanded poll-more-info-answers">
|
<div class="expanded poll-more-info-answers">
|
||||||
<div class="row padding">
|
<div class="row padding">
|
||||||
|
|
||||||
<% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
|
<% @poll_questions_answers.each do |answer| %>
|
||||||
<div class="small-12 medium-6 column end" id="answer_<%= answer.id %>"
|
<div class="small-12 medium-6 column end" id="answer_<%= answer.id %>"
|
||||||
data-toggler="medium-6 answer-divider">
|
data-toggler="medium-6 answer-divider">
|
||||||
|
|
||||||
@@ -128,5 +128,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-content" data-tabs-content="proposals-tabs" role="tablist">
|
||||||
|
<%= render "filter_subnav" %>
|
||||||
|
|
||||||
|
<div class="tabs-panel is-active" id="tab-comments">
|
||||||
|
<%= render "comments" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -482,6 +482,8 @@ en:
|
|||||||
already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten."
|
already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten."
|
||||||
back: Back to voting
|
back: Back to voting
|
||||||
cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate."
|
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
|
signin: Sign in
|
||||||
signup: Sign up
|
signup: Sign up
|
||||||
cant_answer_verify_html: "You must %{verify_link} in order to answer."
|
cant_answer_verify_html: "You must %{verify_link} in order to answer."
|
||||||
|
|||||||
@@ -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."
|
already_voted_in_web: "Ya has participado en esta votación. Si vuelves a votar se sobreescribirá tu resultado anterior."
|
||||||
back: Volver a votaciones
|
back: Volver a votaciones
|
||||||
cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar."
|
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
|
signin: iniciar sesión
|
||||||
signup: registrarte
|
signup: registrarte
|
||||||
cant_answer_verify_html: "Por favor %{verify_link} para poder responder."
|
cant_answer_verify_html: "Por favor %{verify_link} para poder responder."
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ Rails.application.routes.draw do
|
|||||||
resources :videos, controller: 'questions/answers/videos'
|
resources :videos, controller: 'questions/answers/videos'
|
||||||
get :documents, to: 'questions/answers#documents'
|
get :documents, to: 'questions/answers#documents'
|
||||||
end
|
end
|
||||||
|
post '/answers/order_answers', to: 'questions/answers#order_answers'
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddGivenOrderToPollQuestionAnswers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :poll_question_answers, :given_order, :integer, default: 1
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20171006145053) do
|
ActiveRecord::Schema.define(version: 20171010143623) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -680,6 +680,7 @@ ActiveRecord::Schema.define(version: 20171006145053) do
|
|||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.integer "question_id"
|
t.integer "question_id"
|
||||||
|
t.integer "given_order", default: 1
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree
|
add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree
|
||||||
@@ -801,6 +802,9 @@ ActiveRecord::Schema.define(version: 20171006145053) do
|
|||||||
t.boolean "geozone_restricted", default: false
|
t.boolean "geozone_restricted", default: false
|
||||||
t.text "summary"
|
t.text "summary"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
|
t.integer "comments_count", default: 0
|
||||||
|
t.integer "author_id"
|
||||||
|
t.datetime "hidden_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
|
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
|
||||||
|
|||||||
@@ -503,8 +503,8 @@ FactoryGirl.define do
|
|||||||
|
|
||||||
factory :poll_question_answer, class: 'Poll::Question::Answer' do
|
factory :poll_question_answer, class: 'Poll::Question::Answer' do
|
||||||
association :question, factory: :poll_question
|
association :question, factory: :poll_question
|
||||||
sequence(:title) { |n| "Question title #{n}" }
|
sequence(:title) { |n| "Answer title #{n}" }
|
||||||
sequence(:description) { |n| "Question description #{n}" }
|
sequence(:description) { |n| "Answer description #{n}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :poll_booth, class: 'Poll::Booth' do
|
factory :poll_booth, class: 'Poll::Booth' do
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ feature 'Answers' do
|
|||||||
|
|
||||||
background do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
login_as (admin.user)
|
login_as admin.user
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Create' do
|
scenario 'Create' do
|
||||||
@@ -24,9 +24,27 @@ feature 'Answers' do
|
|||||||
expect(page).to have_content(description)
|
expect(page).to have_content(description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Create second answer and place after the first one' do
|
||||||
|
question = create(:poll_question)
|
||||||
|
answer = create(:poll_question_answer, title: 'First', question: question, given_order: 1)
|
||||||
|
title = 'Second'
|
||||||
|
description = "Description"
|
||||||
|
|
||||||
|
visit admin_question_path(question)
|
||||||
|
click_link 'Add answer'
|
||||||
|
|
||||||
|
fill_in 'poll_question_answer_title', with: title
|
||||||
|
fill_in 'poll_question_answer_description', with: description
|
||||||
|
|
||||||
|
click_button 'Save'
|
||||||
|
|
||||||
|
expect(page.body.index('First')).to be < page.body.index('Second')
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Update' do
|
scenario 'Update' do
|
||||||
question = create(:poll_question)
|
question = create(:poll_question)
|
||||||
answer = create(:poll_question_answer, question: question, title: "Answer title")
|
answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
|
||||||
|
answer2 = create(:poll_question_answer, question: question, title: "Another title", given_order: 1)
|
||||||
|
|
||||||
visit admin_answer_path(answer)
|
visit admin_answer_path(answer)
|
||||||
|
|
||||||
@@ -46,6 +64,8 @@ feature 'Answers' do
|
|||||||
|
|
||||||
expect(page).to have_content(new_title)
|
expect(page).to have_content(new_title)
|
||||||
expect(page).to_not have_content(old_title)
|
expect(page).to_not have_content(old_title)
|
||||||
|
|
||||||
|
expect(page.body.index(new_title)).to be < page.body.index(answer2.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
522
spec/features/comments/polls_spec.rb
Normal file
522
spec/features/comments/polls_spec.rb
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
include ActionView::Helpers::DateHelper
|
||||||
|
|
||||||
|
feature 'Commenting polls' do
|
||||||
|
let(:user) { create :user }
|
||||||
|
let(:poll) { create :poll }
|
||||||
|
|
||||||
|
scenario 'Index' do
|
||||||
|
3.times { create(:comment, commentable: poll) }
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 3)
|
||||||
|
|
||||||
|
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 'Show' do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
parent_comment = create(:comment, commentable: poll)
|
||||||
|
first_child = create(:comment, commentable: poll, parent: parent_comment)
|
||||||
|
second_child = create(:comment, commentable: poll, parent: parent_comment)
|
||||||
|
|
||||||
|
visit comment_path(parent_comment)
|
||||||
|
|
||||||
|
expect(page).to have_css(".comment", count: 3)
|
||||||
|
expect(page).to have_content parent_comment.body
|
||||||
|
expect(page).to have_content first_child.body
|
||||||
|
expect(page).to have_content second_child.body
|
||||||
|
expect(page).to have_link "Go back to #{poll.name}", href: poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2)
|
||||||
|
expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1)
|
||||||
|
expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Collapsable comments', :js do
|
||||||
|
parent_comment = create(:comment, body: "Main comment", commentable: poll)
|
||||||
|
child_comment = create(:comment, body: "First subcomment", commentable: poll, parent: parent_comment)
|
||||||
|
grandchild_comment = create(:comment, body: "Last subcomment", commentable: poll, parent: child_comment)
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 3)
|
||||||
|
|
||||||
|
find("#comment_#{child_comment.id}_children_arrow").trigger('click')
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 2)
|
||||||
|
expect(page).to_not have_content grandchild_comment.body
|
||||||
|
|
||||||
|
find("#comment_#{child_comment.id}_children_arrow").trigger('click')
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 3)
|
||||||
|
expect(page).to have_content grandchild_comment.body
|
||||||
|
|
||||||
|
find("#comment_#{parent_comment.id}_children_arrow").trigger('click')
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 1)
|
||||||
|
expect(page).to_not have_content child_comment.body
|
||||||
|
expect(page).to_not have_content grandchild_comment.body
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Comment order' do
|
||||||
|
c1 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 100,
|
||||||
|
cached_votes_total: 120, created_at: Time.current - 2)
|
||||||
|
c2 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 10,
|
||||||
|
cached_votes_total: 12, created_at: Time.current - 1)
|
||||||
|
c3 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 1,
|
||||||
|
cached_votes_total: 2, created_at: Time.current)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :most_voted)
|
||||||
|
|
||||||
|
expect(c1.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c3.body)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :newest)
|
||||||
|
|
||||||
|
expect(c3.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c1.body)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :oldest)
|
||||||
|
|
||||||
|
expect(c1.body).to appear_before(c2.body)
|
||||||
|
expect(c2.body).to appear_before(c3.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Creation date works differently in roots and in child comments, when sorting by confidence_score' do
|
||||||
|
old_root = create(:comment, commentable: poll, created_at: Time.current - 10)
|
||||||
|
new_root = create(:comment, commentable: poll, created_at: Time.current)
|
||||||
|
old_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current - 10)
|
||||||
|
new_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :most_voted)
|
||||||
|
|
||||||
|
expect(new_root.body).to appear_before(old_root.body)
|
||||||
|
expect(old_child.body).to appear_before(new_child.body)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :newest)
|
||||||
|
|
||||||
|
expect(new_root.body).to appear_before(old_root.body)
|
||||||
|
expect(new_child.body).to appear_before(old_child.body)
|
||||||
|
|
||||||
|
visit poll_path(poll, order: :oldest)
|
||||||
|
|
||||||
|
expect(old_root.body).to appear_before(new_root.body)
|
||||||
|
expect(old_child.body).to appear_before(new_child.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Turns links into html links' do
|
||||||
|
create :comment, commentable: poll, body: 'Built with http://rubyonrails.org/'
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within first('.comment') do
|
||||||
|
expect(page).to have_content 'Built with http://rubyonrails.org/'
|
||||||
|
expect(page).to have_link('http://rubyonrails.org/', href: 'http://rubyonrails.org/')
|
||||||
|
expect(find_link('http://rubyonrails.org/')[:rel]).to eq('nofollow')
|
||||||
|
expect(find_link('http://rubyonrails.org/')[:target]).to eq('_blank')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Sanitizes comment body for security' do
|
||||||
|
create :comment, commentable: poll,
|
||||||
|
body: "<script>alert('hola')</script> <a href=\"javascript:alert('sorpresa!')\">click me<a/> http://www.url.com"
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within first('.comment') do
|
||||||
|
expect(page).to have_content "click me http://www.url.com"
|
||||||
|
expect(page).to have_link('http://www.url.com', href: 'http://www.url.com')
|
||||||
|
expect(page).not_to have_link('click me')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Paginated comments' do
|
||||||
|
per_page = 10
|
||||||
|
(per_page + 2).times { create(:comment, commentable: poll)}
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: per_page)
|
||||||
|
within("ul.pagination") do
|
||||||
|
expect(page).to have_content("1")
|
||||||
|
expect(page).to have_content("2")
|
||||||
|
expect(page).to_not have_content("3")
|
||||||
|
click_link "Next", exact: false
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css('.comment', count: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature 'Not logged user' do
|
||||||
|
scenario 'can not see comments forms' do
|
||||||
|
create(:comment, commentable: poll)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to have_content 'You must Sign in or Sign up to leave a comment'
|
||||||
|
within('#comments') do
|
||||||
|
expect(page).to_not have_content 'Write a comment'
|
||||||
|
expect(page).to_not have_content 'Reply'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Create', :js do
|
||||||
|
login_as(user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
fill_in "comment-body-poll_#{poll.id}", with: 'Have you thought about...?'
|
||||||
|
click_button 'Publish comment'
|
||||||
|
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content 'Have you thought about...?'
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#tab-comments-label" do
|
||||||
|
expect(page).to have_content 'Comments (1)'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Errors on create', :js do
|
||||||
|
login_as(user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_button 'Publish comment'
|
||||||
|
|
||||||
|
expect(page).to have_content "Can't be blank"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Reply', :js do
|
||||||
|
citizen = create(:user, username: 'Ana')
|
||||||
|
manuela = create(:user, username: 'Manuela')
|
||||||
|
comment = create(:comment, commentable: poll, user: citizen)
|
||||||
|
|
||||||
|
login_as(manuela)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_link "Reply"
|
||||||
|
|
||||||
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
|
fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.'
|
||||||
|
click_button 'Publish reply'
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
expect(page).to have_content 'It will be done next week.'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Errors on reply', :js do
|
||||||
|
comment = create(:comment, commentable: poll, user: user)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_link "Reply"
|
||||||
|
|
||||||
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
|
click_button 'Publish reply'
|
||||||
|
expect(page).to have_content "Can't be blank"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "N replies", :js do
|
||||||
|
parent = create(:comment, commentable: poll)
|
||||||
|
|
||||||
|
7.times do
|
||||||
|
create(:comment, commentable: poll, parent: parent)
|
||||||
|
parent = parent.children.first
|
||||||
|
end
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Flagging as inappropriate", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
comment = create(:comment, commentable: poll)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
page.find("#flag-expand-comment-#{comment.id}").click
|
||||||
|
page.find("#flag-comment-#{comment.id}").click
|
||||||
|
|
||||||
|
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Flag.flagged?(user, comment)).to be
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Undoing flagging as inappropriate", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
comment = create(:comment, commentable: poll)
|
||||||
|
Flag.flag(user, comment)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
page.find("#unflag-expand-comment-#{comment.id}").click
|
||||||
|
page.find("#unflag-comment-#{comment.id}").click
|
||||||
|
|
||||||
|
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Flag.flagged?(user, comment)).to_not be
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Flagging turbolinks sanity check", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
poll = create(:poll, title: "Should we change the world?")
|
||||||
|
comment = create(:comment, commentable: poll)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit polls_path
|
||||||
|
click_link "Should we change the world?"
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
page.find("#flag-expand-comment-#{comment.id}").click
|
||||||
|
expect(page).to have_selector("#flag-comment-#{comment.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Erasing a comment's author" do
|
||||||
|
poll = create(:poll)
|
||||||
|
comment = create(:comment, commentable: poll, body: "this should be visible")
|
||||||
|
comment.user.erase
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
expect(page).to have_content('User deleted')
|
||||||
|
expect(page).to have_content('this should be visible')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature "Moderators" do
|
||||||
|
|
||||||
|
scenario "can create comment as a moderator", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
moderator = create(:moderator)
|
||||||
|
|
||||||
|
login_as(moderator.user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
fill_in "comment-body-poll_#{poll.id}", with: "I am moderating!"
|
||||||
|
check "comment-as-moderator-poll_#{poll.id}"
|
||||||
|
click_button "Publish comment"
|
||||||
|
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content "I am moderating!"
|
||||||
|
expect(page).to have_content "Moderator ##{moderator.id}"
|
||||||
|
expect(page).to have_css "div.is-moderator"
|
||||||
|
expect(page).to have_css "img.moderator-avatar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "can create reply as a moderator", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
citizen = create(:user, username: "Ana")
|
||||||
|
manuela = create(:user, username: "Manuela")
|
||||||
|
moderator = create(:moderator, user: manuela)
|
||||||
|
comment = create(:comment, commentable: poll, user: citizen)
|
||||||
|
|
||||||
|
login_as(manuela)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_link "Reply"
|
||||||
|
|
||||||
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
|
fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!"
|
||||||
|
check "comment-as-moderator-comment_#{comment.id}"
|
||||||
|
click_button 'Publish reply'
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
expect(page).to have_content "I am moderating!"
|
||||||
|
expect(page).to have_content "Moderator ##{moderator.id}"
|
||||||
|
expect(page).to have_css "div.is-moderator"
|
||||||
|
expect(page).to have_css "img.moderator-avatar"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "can not comment as an administrator" do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
moderator = create(:moderator)
|
||||||
|
|
||||||
|
login_as(moderator.user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to_not have_content "Comment as administrator"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature "Administrators" do
|
||||||
|
scenario "can create comment as an administrator", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
admin = create(:administrator)
|
||||||
|
|
||||||
|
login_as(admin.user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
fill_in "comment-body-poll_#{poll.id}", with: "I am your Admin!"
|
||||||
|
check "comment-as-administrator-poll_#{poll.id}"
|
||||||
|
click_button "Publish comment"
|
||||||
|
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content "I am your Admin!"
|
||||||
|
expect(page).to have_content "Administrator ##{admin.id}"
|
||||||
|
expect(page).to have_css "div.is-admin"
|
||||||
|
expect(page).to have_css "img.admin-avatar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "can create reply as an administrator", :js do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
citizen = create(:user, username: "Ana")
|
||||||
|
manuela = create(:user, username: "Manuela")
|
||||||
|
admin = create(:administrator, user: manuela)
|
||||||
|
comment = create(:comment, commentable: poll, user: citizen)
|
||||||
|
|
||||||
|
login_as(manuela)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_link "Reply"
|
||||||
|
|
||||||
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
|
fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!"
|
||||||
|
check "comment-as-administrator-comment_#{comment.id}"
|
||||||
|
click_button 'Publish reply'
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
|
expect(page).to have_content "Top of the world!"
|
||||||
|
expect(page).to have_content "Administrator ##{admin.id}"
|
||||||
|
expect(page).to have_css "div.is-admin"
|
||||||
|
expect(page).to have_css "img.admin-avatar"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "can not comment as a moderator" do
|
||||||
|
skip "Feature not implemented yet, review soon"
|
||||||
|
|
||||||
|
admin = create(:administrator)
|
||||||
|
|
||||||
|
login_as(admin.user)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
expect(page).to_not have_content "Comment as moderator"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature 'Voting comments' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
@manuela = create(:user, verified_at: Time.current)
|
||||||
|
@pablo = create(:user)
|
||||||
|
@poll = create(:poll)
|
||||||
|
@comment = create(:comment, commentable: @poll)
|
||||||
|
|
||||||
|
login_as(@manuela)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Show' do
|
||||||
|
create(:vote, voter: @manuela, votable: @comment, vote_flag: true)
|
||||||
|
create(:vote, voter: @pablo, votable: @comment, vote_flag: false)
|
||||||
|
|
||||||
|
visit poll_path(@poll)
|
||||||
|
|
||||||
|
within("#comment_#{@comment.id}_votes") do
|
||||||
|
within(".in_favor") do
|
||||||
|
expect(page).to have_content "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
within(".against") do
|
||||||
|
expect(page).to have_content "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content "2 votes"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Create', :js do
|
||||||
|
visit poll_path(@poll)
|
||||||
|
|
||||||
|
within("#comment_#{@comment.id}_votes") do
|
||||||
|
find(".in_favor a").click
|
||||||
|
|
||||||
|
within(".in_favor") do
|
||||||
|
expect(page).to have_content "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
within(".against") do
|
||||||
|
expect(page).to have_content "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content "1 vote"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Update', :js do
|
||||||
|
visit poll_path(@poll)
|
||||||
|
|
||||||
|
within("#comment_#{@comment.id}_votes") do
|
||||||
|
find('.in_favor a').click
|
||||||
|
find('.against a').click
|
||||||
|
|
||||||
|
within('.in_favor') do
|
||||||
|
expect(page).to have_content "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
within('.against') do
|
||||||
|
expect(page).to have_content "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content "1 vote"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Trying to vote multiple times', :js do
|
||||||
|
visit poll_path(@poll)
|
||||||
|
|
||||||
|
within("#comment_#{@comment.id}_votes") do
|
||||||
|
find('.in_favor a').click
|
||||||
|
find('.in_favor a').click
|
||||||
|
|
||||||
|
within('.in_favor') do
|
||||||
|
expect(page).to have_content "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
within('.against') do
|
||||||
|
expect(page).to have_content "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content "1 vote"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -371,6 +371,55 @@ feature 'Emails' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "Polls" do
|
||||||
|
|
||||||
|
scenario "Do not send email on poll comment", :js do
|
||||||
|
user1 = create(:user, email_on_comment: true)
|
||||||
|
user2 = create(:user)
|
||||||
|
|
||||||
|
poll = create(:poll, author: user1)
|
||||||
|
reset_mailer
|
||||||
|
|
||||||
|
login_as(user2)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
fill_in "comment-body-poll_#{poll.id}", with: 'Have you thought about...?'
|
||||||
|
click_button 'Publish comment'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Have you thought about...?'
|
||||||
|
|
||||||
|
expect { open_last_email }.to raise_error "No email has been sent!"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Send email on poll comment reply", :js do
|
||||||
|
user1 = create(:user, email_on_comment_reply: true)
|
||||||
|
user2 = create(:user)
|
||||||
|
|
||||||
|
poll = create(:poll)
|
||||||
|
comment = create(:comment, commentable: poll, author: user1)
|
||||||
|
|
||||||
|
login_as(user2)
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
click_link "Reply"
|
||||||
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
|
fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.'
|
||||||
|
click_button 'Publish reply'
|
||||||
|
end
|
||||||
|
expect(page).to have_content 'It will be done next week.'
|
||||||
|
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
expect(email).to have_subject('Someone has responded to your comment')
|
||||||
|
expect(email).to deliver_to(user1)
|
||||||
|
expect(email).to_not have_body_text(poll_path(poll))
|
||||||
|
expect(email).to have_body_text(comment_path(Comment.last))
|
||||||
|
expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions"))
|
||||||
|
expect(email).to have_body_text(account_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context "Users without email" do
|
context "Users without email" do
|
||||||
scenario "should not receive emails", :js do
|
scenario "should not receive emails", :js do
|
||||||
user = create(:user, :verified, email_on_comment: true)
|
user = create(:user, :verified, email_on_comment: true)
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ feature 'Answers' do
|
|||||||
|
|
||||||
scenario "Index" do
|
scenario "Index" do
|
||||||
question = create(:poll_question)
|
question = create(:poll_question)
|
||||||
answer1 = create(:poll_question_answer, question: question)
|
answer1 = create(:poll_question_answer, question: question, given_order: 2)
|
||||||
answer2 = create(:poll_question_answer, question: question)
|
answer2 = create(:poll_question_answer, question: question, given_order: 1)
|
||||||
|
|
||||||
visit admin_question_path(question)
|
visit admin_question_path(question)
|
||||||
|
|
||||||
expect(page).to have_css(".poll_question_answer", count: 2)
|
expect(page).to have_css(".poll_question_answer", count: 2)
|
||||||
|
|
||||||
|
expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
|
||||||
|
|
||||||
within("#poll_question_answer_#{answer1.id}") do
|
within("#poll_question_answer_#{answer1.id}") do
|
||||||
expect(page).to have_content answer1.title
|
expect(page).to have_content answer1.title
|
||||||
expect(page).to have_content answer1.description
|
expect(page).to have_content answer1.description
|
||||||
@@ -54,4 +56,4 @@ feature 'Answers' do
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -78,6 +78,30 @@ feature 'Polls' do
|
|||||||
expect(page).to have_content(proposal_question.title)
|
expect(page).to have_content(proposal_question.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Question answers appear in the given order" do
|
||||||
|
question = create(:poll_question, poll: poll)
|
||||||
|
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2)
|
||||||
|
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1)
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within("div#poll_question_#{question.id}") do
|
||||||
|
expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "More info answers appear in the given order" do
|
||||||
|
question = create(:poll_question, poll: poll)
|
||||||
|
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2)
|
||||||
|
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1)
|
||||||
|
|
||||||
|
visit poll_path(poll)
|
||||||
|
|
||||||
|
within('div.poll-more-info-answers') do
|
||||||
|
expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Non-logged in users' do
|
scenario 'Non-logged in users' do
|
||||||
question = create(:poll_question, poll: poll)
|
question = create(:poll_question, poll: poll)
|
||||||
answer1 = create(:poll_question_answer, question: question, title: 'Han Solo')
|
answer1 = create(:poll_question_answer, question: question, title: 'Han Solo')
|
||||||
|
|||||||
Reference in New Issue
Block a user