Create first comment automatically from the annotation

This commit is contained in:
Amaia Castro
2017-01-09 17:03:00 +01:00
parent b8f034d896
commit f43f13e826
6 changed files with 21 additions and 18 deletions

View File

@@ -13,6 +13,12 @@ class Legislation::Annotation < ActiveRecord::Base
validates :draft_version, presence: true
validates :author, presence: true
after_create :create_first_comment
def create_first_comment
comments.create(body: self.text, user: self.author)
end
def title
text[0..50]
end

View File

@@ -23,7 +23,7 @@
<%= 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>
<span class="icon-comments" aria-hidden="true"></span> <span><%= t('.comments_count', count: annotation.comments_count) %></span></a>
<% end %>
</div>
<% end %>

View File

@@ -27,12 +27,6 @@
</div>
</div>
<div class="row">
<div class="small-12 medium-10 column legislation-comment">
<%= @annotation.text %>
</div>
</div>
<%= render 'comments', commentable: @annotation %>
</div>

View File

@@ -233,7 +233,7 @@ en:
other: "%{count} comments"
show:
title: Comment
comments: Replies
comments: Comments
version_chooser:
seeing_version: Commments for version
see_text: See text draft

View File

@@ -233,7 +233,7 @@ es:
other: "%{count} comentarios"
show:
title: Comentario
comments: Respuestas
comments: Comentarios
version_chooser:
seeing_version: Comentarios para la versión
see_text: Ver borrador del texto

View File

@@ -3,14 +3,14 @@ include ActionView::Helpers::DateHelper
feature 'Commenting legislation questions' do
let(:user) { create :user }
let(:legislation_annotation) { create :legislation_annotation }
let(:legislation_annotation) { create :legislation_annotation, author: user }
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)
expect(page).to have_css('.comment', count: 4)
comment = Comment.last
within first('.comment') do
@@ -36,7 +36,7 @@ feature 'Commenting legislation questions' do
end
scenario 'Collapsable comments', :js do
parent_comment = create(:comment, body: "Main comment", commentable: legislation_annotation)
parent_comment = legislation_annotation.comments.first
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)
@@ -143,7 +143,7 @@ feature 'Commenting legislation questions' do
click_link "Next", exact: false
end
expect(page).to have_css('.comment', count: 2)
expect(page).to have_css('.comment', count: 3)
end
feature 'Not logged user' do
@@ -168,7 +168,7 @@ feature 'Commenting legislation questions' do
within "#comments" do
expect(page).to have_content 'Have you thought about...?'
expect(page).to have_content '(1)'
expect(page).to have_content '(2)'
end
end
@@ -184,7 +184,8 @@ feature 'Commenting legislation questions' do
scenario 'Reply', :js do
citizen = create(:user, username: 'Ana')
manuela = create(:user, username: 'Manuela')
comment = create(:comment, commentable: legislation_annotation, user: citizen)
legislation_annotation = create(:legislation_annotation, author: citizen)
comment = legislation_annotation.comments.first
login_as(manuela)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
@@ -204,7 +205,7 @@ feature 'Commenting legislation questions' do
end
scenario 'Errors on reply', :js do
comment = create(:comment, commentable: legislation_annotation, user: user)
comment = legislation_annotation.comments.first
login_as(user)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
@@ -326,7 +327,8 @@ feature 'Commenting legislation questions' do
citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela")
moderator = create(:moderator, user: manuela)
comment = create(:comment, commentable: legislation_annotation, user: citizen)
legislation_annotation = create(:legislation_annotation, author: citizen)
comment = legislation_annotation.comments.first
login_as(manuela)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)
@@ -382,7 +384,8 @@ feature 'Commenting legislation questions' do
citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela")
admin = create(:administrator, user: manuela)
comment = create(:comment, commentable: legislation_annotation, user: citizen)
legislation_annotation = create(:legislation_annotation, author: citizen)
comment = legislation_annotation.comments.first
login_as(manuela)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation)