Legislation annotations/comments page
This commit is contained in:
@@ -7,9 +7,20 @@ class Legislation::AnnotationsController < ApplicationController
|
||||
load_and_authorize_resource :draft_version, through: :process
|
||||
load_and_authorize_resource
|
||||
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
@commentable = @annotation
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
set_comment_flags(@comment_tree.comments)
|
||||
end
|
||||
|
||||
def create
|
||||
@annotation = Legislation::Annotation.new(annotation_params)
|
||||
@annotation.user = current_user
|
||||
@annotation.author = current_user
|
||||
if @annotation.save
|
||||
render json: @annotation.to_json
|
||||
end
|
||||
@@ -23,10 +34,11 @@ class Legislation::AnnotationsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def annotation_params
|
||||
params
|
||||
.require(:annotation)
|
||||
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
|
||||
.merge(legislation_draft_version_id: params[:legislation_draft_version_id])
|
||||
end
|
||||
def annotation_params
|
||||
params
|
||||
.require(:annotation)
|
||||
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
|
||||
.merge(legislation_draft_version_id: params[:legislation_draft_version_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -10,4 +10,8 @@ module LegislationHelper
|
||||
def legislation_question_path(question)
|
||||
legislation_process_question_path(question.process, question)
|
||||
end
|
||||
|
||||
def legislation_annotation_path(annotation)
|
||||
legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ module Abilities
|
||||
can :mark_featured, Debate
|
||||
can :unmark_featured, Debate
|
||||
|
||||
can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question]
|
||||
can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation]
|
||||
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :create, :index, :summary], ::Valuator
|
||||
@@ -49,7 +49,7 @@ module Abilities
|
||||
can [:manage], ::Legislation::Process
|
||||
can [:manage], ::Legislation::DraftVersion
|
||||
can [:manage], ::Legislation::Question
|
||||
cannot :comment_as_moderator, ::Legislation::Question
|
||||
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Abilities
|
||||
def initialize(user)
|
||||
self.merge Abilities::Moderation.new(user)
|
||||
|
||||
can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question]
|
||||
can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class Comment < ActiveRecord::Base
|
||||
|
||||
validates :body, presence: true
|
||||
validates :user, presence: true
|
||||
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question"]
|
||||
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question", "Legislation::Annotation"]
|
||||
|
||||
validate :validate_body_length
|
||||
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
class Legislation::Annotation < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
serialize :ranges, Array
|
||||
|
||||
belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id'
|
||||
belongs_to :user
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
has_many :comments, as: :commentable
|
||||
|
||||
validates :text, presence: true
|
||||
validates :quote, presence: true
|
||||
validates :draft_version, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
def title
|
||||
text[0..50]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class Legislation::Answer < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :answers, counter_cache: true
|
||||
belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', inverse_of: :answers, counter_cache: true
|
||||
belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers
|
||||
|
||||
@@ -5,6 +5,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id'
|
||||
|
||||
validates :title, presence: true
|
||||
validates :body, presence: true
|
||||
|
||||
29
app/views/legislation/annotations/_comments.html.erb
Normal file
29
app/views/legislation/annotations/_comments.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<% cache [locale_and_user_status, @current_order, commentable_cache_key(commentable), @comment_tree.comments, @comment_tree.comment_authors, commentable.comments_count, @comment_flags] do %>
|
||||
<div class="row comments">
|
||||
<div id="comments" class="small-12 column">
|
||||
<h3>
|
||||
<%= t("legislation.annotations.show.comments") %>
|
||||
<span class="js-comments-count">(<%= commentable.comments_count %>)</span>
|
||||
</h3>
|
||||
|
||||
<%= 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("debates.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 %>
|
||||
16
app/views/legislation/annotations/_version_chooser.html.erb
Normal file
16
app/views/legislation/annotations/_version_chooser.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div class="row draft-chooser">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h3><%= t('.seeing_version') %></h3>
|
||||
<div class="select-box">
|
||||
<%= form_tag go_to_version_legislation_process_draft_versions_path(process), method: :get, id: "draft_version_go_to_version" do %>
|
||||
<%= select_tag "draft_version_id", options_from_collection_for_select(process.draft_versions.published, 'id', 'display_title', draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %>
|
||||
<%= hidden_field_tag "redirect_action", "annotations" %>
|
||||
<%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<span><%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %></span>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= link_to t('.see_text'), legislation_process_draft_version_annotations_path(process, draft_version), title: t('.see_text'), class: "button strong" %>
|
||||
</div>
|
||||
</div>
|
||||
35
app/views/legislation/annotations/index.html.erb
Normal file
35
app/views/legislation/annotations/index.html.erb
Normal file
@@ -0,0 +1,35 @@
|
||||
<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %>
|
||||
|
||||
<%= render 'legislation/processes/header', process: @process, header: :small %>
|
||||
|
||||
<div class="column row">
|
||||
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
|
||||
|
||||
<div class="draft-panels small-12 column row">
|
||||
<%= render 'version_chooser', process: @process, draft_version: @draft_version %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 column legislation-comments">
|
||||
|
||||
<% @annotations.each do |annotation| %>
|
||||
<div class="comment">
|
||||
<strong><%= t('.comments_about') %></strong>
|
||||
<span class="pull-right">
|
||||
<%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{annotation.id}") do %>
|
||||
<span><%= t('.see_in_context') %></span> <span class="icon-expand" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<div class="comment-section">
|
||||
<%= annotation.quote %>
|
||||
</div>
|
||||
<%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %>
|
||||
<span class="icon-comments" aria-hidden="true"></span> <span><%= t('.comments_count', count: annotation.comments_count + 1) %></span></a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
42
app/views/legislation/annotations/show.html.erb
Normal file
42
app/views/legislation/annotations/show.html.erb
Normal file
@@ -0,0 +1,42 @@
|
||||
<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %>
|
||||
|
||||
<%= render 'legislation/processes/header', process: @process, header: :small %>
|
||||
|
||||
<div class="column row">
|
||||
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
|
||||
|
||||
<div class="draft-panels small-12 column row">
|
||||
<%= render 'version_chooser', process: @process, draft_version: @draft_version %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-12 column legislation-comment">
|
||||
<div class="annotation-comment">
|
||||
<strong><%= t('legislation.annotations.index.comments_about') %></strong>
|
||||
<div class="comment-section">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-10 column legislation-comment">
|
||||
<%= @annotation.quote %>
|
||||
</div>
|
||||
<div class="small-12 medium-2 column legislation-comment">
|
||||
<span class="pull-right">
|
||||
<%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{@annotation.id}") do %>
|
||||
<span><%= t('legislation.annotations.index.see_in_context') %></span> <span class="icon-expand" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-10 column legislation-comment">
|
||||
<%= @annotation.text %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render 'comments', commentable: @annotation %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -68,7 +68,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -223,6 +223,20 @@ en:
|
||||
text_sign_up: sign up
|
||||
title: How I can comment this document?
|
||||
legislation:
|
||||
annotations:
|
||||
index:
|
||||
title: Comments
|
||||
comments_about: Comments about
|
||||
see_in_context: See in context
|
||||
comments_count:
|
||||
one: "%{count} comment"
|
||||
other: "%{count} comments"
|
||||
show:
|
||||
title: Comment
|
||||
comments: Replies
|
||||
version_chooser:
|
||||
seeing_version: Commments for version
|
||||
see_text: See text draft
|
||||
draft_versions:
|
||||
changes:
|
||||
title: Changes
|
||||
|
||||
@@ -223,6 +223,20 @@ es:
|
||||
text_sign_up: registrarte
|
||||
title: "¿Cómo puedo comentar este documento?"
|
||||
legislation:
|
||||
annotations:
|
||||
index:
|
||||
title: Comentarios
|
||||
see_in_context: Ver en contexto
|
||||
comments_about: Comentarios sobre
|
||||
comments_count:
|
||||
one: "%{count} comentario"
|
||||
other: "%{count} comentarios"
|
||||
show:
|
||||
title: Comentario
|
||||
comments: Respuestas
|
||||
version_chooser:
|
||||
seeing_version: Comentarios para la versión
|
||||
see_text: Ver borrador del texto
|
||||
draft_versions:
|
||||
changes:
|
||||
title: Cambios
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCommentsCountToLegislationAnnotation < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :legislation_annotations, :comments_count, :integer, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameUserToAuthorInLegislationAnnotations < ActiveRecord::Migration
|
||||
def change
|
||||
rename_column :legislation_annotations, :user_id, :author_id
|
||||
end
|
||||
end
|
||||
11
db/schema.rb
11
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170103125835) do
|
||||
ActiveRecord::Schema.define(version: 20170105212047) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -233,15 +233,16 @@ ActiveRecord::Schema.define(version: 20170103125835) do
|
||||
t.text "ranges"
|
||||
t.text "text"
|
||||
t.integer "legislation_draft_version_id"
|
||||
t.integer "user_id"
|
||||
t.integer "author_id"
|
||||
t.datetime "hidden_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "comments_count", default: 0
|
||||
end
|
||||
|
||||
add_index "legislation_annotations", ["author_id"], name: "index_legislation_annotations_on_author_id", using: :btree
|
||||
add_index "legislation_annotations", ["hidden_at"], name: "index_legislation_annotations_on_hidden_at", using: :btree
|
||||
add_index "legislation_annotations", ["legislation_draft_version_id"], name: "index_legislation_annotations_on_legislation_draft_version_id", using: :btree
|
||||
add_index "legislation_annotations", ["user_id"], name: "index_legislation_annotations_on_user_id", using: :btree
|
||||
|
||||
create_table "legislation_answers", force: :cascade do |t|
|
||||
t.integer "legislation_question_id"
|
||||
|
||||
@@ -407,7 +407,7 @@ FactoryGirl.define do
|
||||
|
||||
factory :legislation_annotation, class: 'Legislation::Annotation' do
|
||||
draft_version factory: :legislation_draft_version
|
||||
user
|
||||
author factory: :user
|
||||
quote "ipsum"
|
||||
text "Loremp ipsum dolor"
|
||||
ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]
|
||||
|
||||
508
spec/features/comments/legislation_annotations_spec.rb
Normal file
508
spec/features/comments/legislation_annotations_spec.rb
Normal file
@@ -0,0 +1,508 @@
|
||||
require 'rails_helper'
|
||||
include ActionView::Helpers::DateHelper
|
||||
|
||||
feature 'Commenting legislation questions' do
|
||||
let(:user) { create :user }
|
||||
let(:legislation_annotation) { create :legislation_annotation }
|
||||
|
||||
scenario 'Index' do
|
||||
3.times { create(:comment, commentable: legislation_annotation) }
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
parent_comment = create(:comment, commentable: legislation_annotation)
|
||||
first_child = create(:comment, commentable: legislation_annotation, parent: parent_comment)
|
||||
second_child = create(:comment, commentable: legislation_annotation, 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 #{legislation_annotation.title}", href: legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
end
|
||||
|
||||
scenario 'Collapsable comments', :js do
|
||||
parent_comment = create(:comment, body: "Main comment", commentable: legislation_annotation)
|
||||
child_comment = create(:comment, body: "First subcomment", commentable: legislation_annotation, parent: parent_comment)
|
||||
grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_annotation, parent: child_comment)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2)
|
||||
c2 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1)
|
||||
c3 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted)
|
||||
|
||||
expect(c1.body).to appear_before(c2.body)
|
||||
expect(c2.body).to appear_before(c3.body)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest)
|
||||
|
||||
expect(c3.body).to appear_before(c2.body)
|
||||
expect(c2.body).to appear_before(c1.body)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, 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, even when sorting by confidence_score' do
|
||||
old_root = create(:comment, commentable: legislation_annotation, created_at: Time.current - 10)
|
||||
new_root = create(:comment, commentable: legislation_annotation, created_at: Time.current)
|
||||
old_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current - 10)
|
||||
new_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted)
|
||||
|
||||
expect(new_root.body).to appear_before(old_root.body)
|
||||
expect(old_child.body).to appear_before(new_child.body)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest)
|
||||
|
||||
expect(new_root.body).to appear_before(old_root.body)
|
||||
expect(new_child.body).to appear_before(old_child.body)
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, 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: legislation_annotation, body: 'Built with http://rubyonrails.org/'
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation, body: "<script>alert('hola')</script> <a href=\"javascript:alert('sorpresa!')\">click me<a/> http://www.url.com"
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation)}
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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 legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Have you thought about...?'
|
||||
click_button 'Publish comment'
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content 'Have you thought about...?'
|
||||
expect(page).to have_content '(1)'
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Errors on create', :js do
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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: legislation_annotation)
|
||||
|
||||
7.times do
|
||||
create(:comment, commentable: legislation_annotation, parent: parent)
|
||||
parent = parent.children.first
|
||||
end
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
||||
end
|
||||
|
||||
scenario "Flagging as inappropriate", :js do
|
||||
comment = create(:comment, commentable: legislation_annotation)
|
||||
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
comment = create(:comment, commentable: legislation_annotation)
|
||||
Flag.flag(user, comment)
|
||||
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
legislation_annotation = create(:legislation_annotation, text: "Should we change the world?")
|
||||
comment = create(:comment, commentable: legislation_annotation)
|
||||
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
legislation_annotation = create(:legislation_annotation)
|
||||
comment = create(:comment, commentable: legislation_annotation, body: 'this should be visible')
|
||||
comment.user.erase
|
||||
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content('User deleted')
|
||||
expect(page).to have_content('this should be visible')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Submit button is disabled after clicking', :js do
|
||||
legislation_annotation = create(:legislation_annotation)
|
||||
login_as(user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Testing submit button!'
|
||||
click_button 'Publish comment'
|
||||
|
||||
# The button's text should now be "..."
|
||||
# This should be checked before the Ajax request is finished
|
||||
expect(page).to_not have_button 'Publish comment'
|
||||
|
||||
expect(page).to have_content('Testing submit button!')
|
||||
end
|
||||
|
||||
feature "Moderators" do
|
||||
scenario "can create comment as a moderator", :js do
|
||||
moderator = create(:moderator)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am moderating!"
|
||||
check "comment-as-moderator-legislation_annotation_#{legislation_annotation.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
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
moderator = create(:moderator, user: manuela)
|
||||
comment = create(:comment, commentable: legislation_annotation, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
moderator = create(:moderator)
|
||||
|
||||
login_as(moderator.user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
expect(page).to_not have_content "Comment as administrator"
|
||||
end
|
||||
end
|
||||
|
||||
feature "Administrators" do
|
||||
scenario "can create comment as an administrator", :js do
|
||||
admin = create(:administrator)
|
||||
|
||||
login_as(admin.user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am your Admin!"
|
||||
check "comment-as-administrator-legislation_annotation_#{legislation_annotation.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
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
admin = create(:administrator, user: manuela)
|
||||
comment = create(:comment, commentable: legislation_annotation, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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
|
||||
admin = create(:administrator)
|
||||
|
||||
login_as(admin.user)
|
||||
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
|
||||
|
||||
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)
|
||||
@legislation_annotation = create(:legislation_annotation)
|
||||
@comment = create(:comment, commentable: @legislation_annotation)
|
||||
|
||||
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 legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation)
|
||||
|
||||
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 legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation)
|
||||
|
||||
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 legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation)
|
||||
|
||||
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
|
||||
|
||||
xscenario 'Trying to vote multiple times', :js do
|
||||
visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation)
|
||||
|
||||
within("#comment_#{@comment.id}_votes") do
|
||||
find('.in_favor a').click
|
||||
within('.in_favor') do
|
||||
expect(page).to have_content "1"
|
||||
end
|
||||
|
||||
find('.in_favor a').click
|
||||
within('.in_favor') do
|
||||
expect(page).to_not have_content "2"
|
||||
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
|
||||
@@ -160,4 +160,27 @@ feature 'Legislation Draft Versions' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Annotations page" do
|
||||
background do
|
||||
@draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
|
||||
@annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote")
|
||||
@annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote")
|
||||
end
|
||||
scenario "See all annotations for a draft version" do
|
||||
visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version)
|
||||
|
||||
expect(page).to have_content "first quote"
|
||||
expect(page).to have_content "second quote"
|
||||
end
|
||||
|
||||
scenario "See one annotation with replies for a draft version" do
|
||||
visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2)
|
||||
|
||||
expect(page).to_not have_content "first quote"
|
||||
expect(page).to have_content "second quote"
|
||||
expect(page).to_not have_content "my annotation"
|
||||
expect(page).to have_content "my other annotation"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user