Skip to content

Commit

Permalink
Don't show a second reply button when comment is hidden (#5045)
Browse files Browse the repository at this point in the history
* Don't show a second reply button when comment is hidden

* Add changelog entry
  • Loading branch information
armandfardeau authored and oriolgual committed Apr 10, 2019
1 parent b9e3b73 commit 64cd815
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

**Fixed**:

- **decidim-comments**: Don't show a second reply button when comment is hidden. [#5045](https://github.com/decidim/decidim/pull/5045)
- **decidim-core**: Fix CSS transparencies using customized colors. [\#5071](https://github.com/decidim/decidim/pull/5071)
- **decidim-core**, **decidim-proposals**: Fix: show existing amendments when amendments feature is disabled [\#5070](https://github.com/decidim/decidim/pull/5070)
- **decidim-assemblies**: Fix admin assemblies form. [\#5054](https://github.com/decidim/decidim/pull/5054)
Expand Down
7 changes: 7 additions & 0 deletions decidim-comments/app/models/decidim/comments/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def accepts_new_comments?
root_commentable.accepts_new_comments? && depth < MAX_DEPTH
end

# Public: Override comment threads to exclude hidden ones.
#
# Returns comment.
def comment_threads
super.reject(&:hidden?)
end

# Public: Override Commentable concern method `users_to_notify_on_comment_created`.
# Return the comment author together with whatever ActiveRecord::Relation is returned by
# the `commentable`. This will cause the comment author to be notified when the
Expand Down
15 changes: 15 additions & 0 deletions decidim-comments/spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ module Comments
expect(comment.formatted_body).to eq("<p>bold text <em>neque dicta enim quasi</em> link</p>")
end
end

describe "#comment_threads count" do
let!(:parent) { create(:comment, commentable: commentable) }
let!(:comments) { create_list(:comment, 3, commentable: parent, root_commentable: commentable) }

it "return 3" do
expect(parent.comment_threads.count).to eq 3
end

it "returns 2 when a comment has been moderated" do
Decidim::Moderation.create!(reportable: comments.last, participatory_space: comments.last.participatory_space, hidden_at: 1.day.ago)

expect(parent.comment_threads.count).to eq 2
end
end
end
end
end
10 changes: 10 additions & 0 deletions decidim-comments/spec/types/comment_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ module Comments
FactoryBot.create(:comment, commentable: model)
expect(response).to include("hasComments" => true)
end

context "when comment child has been moderated" do
let(:comment) { create(:comment, commentable: model) }

it "return false" do
Decidim::Moderation.create!(reportable: comment, participatory_space: comment.participatory_space, hidden_at: 1.day.ago)

expect(response).to include("hasComments" => false)
end
end
end

describe "acceptsNewComments" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
visit resource_path

expect(page).to have_selector(".comment__reply")
expect(page).not_to have_selector(".comment__additionalreply")

within "#comments #comment_#{comment.id}" do
click_button "Reply"
Expand All @@ -110,10 +111,27 @@
end

expect(page).to have_selector(".comment-thread .comment--nested")
expect(page).to have_selector(".comment__additionalreply")
expect(page).to have_reply_to(comment, "This is a reply")
end
end

context "when a comment has been moderated" do
let!(:parent) { create(:comment, commentable: commentable) }
let!(:reply) { create(:comment, commentable: parent, root_commentable: commentable) }

it "doesn't show additional reply" do
Decidim::Moderation.create!(reportable: reply, participatory_space: reply.participatory_space, hidden_at: 1.day.ago)

visit current_path

within "#comments #comment_#{parent.id}" do
expect(page).to have_selector(".comment__reply")
expect(page).not_to have_selector(".comment__additionalreply")
end
end
end

describe "arguable option" do
context "when commenting with alignment" do
before do
Expand Down

0 comments on commit 64cd815

Please sign in to comment.