From fc8687a707d8c709cddfaa3e9a0247abf215ab5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Fri, 28 Aug 2015 14:15:56 +0200 Subject: [PATCH] adds comments labels per comment fixes #265 --- app/views/comments/_form.html.erb | 11 ++++++----- app/views/comments/new.js.erb | 2 +- spec/features/comments_spec.rb | 20 ++++++++++---------- spec/support/common_actions.rb | 4 ++-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index b73023c7a..71735eaaa 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,6 +1,7 @@
> <%= form_for [@debate, Comment.new], remote: true do |f| %> - <%= f.text_area :body, label: t("comments.form.leave_comment") %> + <%= label_tag "comment-body-#{dom_id(parent)}", t("comments.form.leave_comment") %> + <%= f.text_area :body, id: "comment-body-#{dom_id(parent)}", label: false %> <%= f.hidden_field :commentable_type, value: parent.class %> <%= f.hidden_field :commentable_id, value: parent.id %> @@ -8,14 +9,14 @@ <% if can? :comment_as_moderator, @debate %>
- <%= f.check_box :as_moderator, label: false %> - <%= f.label :as_moderator, t("comments.form.comment_as_moderator"), class: "checkbox" %> + <%= f.check_box :as_moderator, id: "comment-as-moderator-#{dom_id(parent)}", label: false %> + <%= label_tag "comment-as-moderator-#{dom_id(parent)}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
<% end %> <% if can? :comment_as_administrator, @debate %>
- <%= f.check_box :as_administrator, label: false %> - <%= f.label :as_administrator, t("comments.form.comment_as_admin"), class: "checkbox" %> + <%= f.check_box :as_administrator, id: "comment-as-administrator-#{dom_id(parent)}",label: false %> + <%= label_tag "comment-as-administrator-#{dom_id(parent)}", t("comments.form.comment_as_admin"), class: "checkbox" %>
<% end %> <% end %> diff --git a/app/views/comments/new.js.erb b/app/views/comments/new.js.erb index 645129c76..819686e72 100644 --- a/app/views/comments/new.js.erb +++ b/app/views/comments/new.js.erb @@ -1,2 +1,2 @@ -var field_with_errors = "#js-comment-form-<%= dom_id(@parent) %> #comment_body"; +var field_with_errors = "#js-comment-form-<%= dom_id(@parent) %> #comment-body-<%= dom_id(@parent) %>"; App.Comments.display_error(field_with_errors, "<%= j render('comments/errors') %>"); diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 0986412bc..9814a4b33 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -59,7 +59,7 @@ feature 'Comments' do login_as(user) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' within "#comments" do @@ -91,7 +91,7 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' click_button 'Publish reply' end @@ -178,8 +178,8 @@ feature 'Comments' do login_as(moderator.user) visit debate_path(debate) - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-debate_#{debate.id}", with: "I am moderating!" + check "comment-as-moderator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -203,8 +203,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" click_button 'Publish reply' end @@ -237,8 +237,8 @@ feature 'Comments' do login_as(admin.user) visit debate_path(debate) - fill_in "comment_body", with: "I am your Admin!" - check "comment_as_administrator" + fill_in "comment-body-debate_#{debate.id}", with: "I am your Admin!" + check "comment-as-administrator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -262,8 +262,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "Top of the world!" - check "comment_as_administrator" + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" click_button 'Publish reply' end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 591e0cebd..5773293cd 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -30,7 +30,7 @@ module CommonActions login_as(user2) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' expect(page).to have_content 'Have you thought about...?' end @@ -45,7 +45,7 @@ module CommonActions click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + 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.'