diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 0313b7e36..d62363946 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -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 diff --git a/app/views/legislation/annotations/index.html.erb b/app/views/legislation/annotations/index.html.erb index ad9d0a52a..ead25ae3b 100644 --- a/app/views/legislation/annotations/index.html.erb +++ b/app/views/legislation/annotations/index.html.erb @@ -23,7 +23,7 @@ <%= annotation.quote %> <%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %> - <%= t('.comments_count', count: annotation.comments_count + 1) %> + <%= t('.comments_count', count: annotation.comments_count) %> <% end %> <% end %> diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index 05caf8ef6..6bf499f52 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -27,12 +27,6 @@ -
-
- <%= @annotation.text %> -
-
- <%= render 'comments', commentable: @annotation %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3830e2b78..1556c4403 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index de031d959..bf79276c4 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 diff --git a/spec/features/comments/legislation_annotations_spec.rb b/spec/features/comments/legislation_annotations_spec.rb index 6e86d97d3..eb72036e2 100644 --- a/spec/features/comments/legislation_annotations_spec.rb +++ b/spec/features/comments/legislation_annotations_spec.rb @@ -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)