Skip to content

Commit

Permalink
Fix comment activity cell (#4413)
Browse files Browse the repository at this point in the history
* Fix CommentActivityCell with comment as commentable

* Add CHANGELOG
  • Loading branch information
oriolgual committed Oct 31, 2018
1 parent 19e0f95 commit a9c71ce
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ end
- **decidim-core**: Fix events for polymorphic authors [\#4387](https://github.com/decidim/decidim/pull/4387)
- **decidim-meetings**: Fix order of upcoming meetings [\#4398](https://github.com/decidim/decidim/pull/4398)
- **decidim-core**: Ignore deleted users follows [\#4401](https://github.com/decidim/decidim/pull/4401)
- **decidim-comments**: Fix comment activity cell when commentable is a comment [\#4413](https://github.com/decidim/decidim/pull/4413)

**Removed**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ module Decidim
module Comments
# A cell to display when a comment has been created.
class CommentActivityCell < ActivityCell
delegate :commentable, to: :comment
delegate :root_commentable, to: :comment

def renderable?
comment.present? && commentable.present?
comment.present? && root_commentable.present?
end

def resource_link_text
comment.body
end

def resource_link_path
resource_locator(commentable).path(url_params)
resource_locator(root_commentable).path(url_params)
end

def title
I18n.t(
"decidim.comments.last_activity.new_comment_at_html",
link: link_to(
translated_attribute(commentable.title),
resource_locator(commentable).path
translated_attribute(root_commentable.title),
resource_locator(root_commentable).path
)
)
end
Expand Down
13 changes: 13 additions & 0 deletions decidim-comments/lib/decidim/comments/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
commentable { build(:dummy_resource) }
root_commentable { commentable }
body { Faker::Lorem.paragraph }

trait :comment_on_comment do
author { build(:user, organization: root_commentable.organization) }
commentable do
build(
:comment,
author: author,
root_commentable: root_commentable,
commentable: root_commentable
)
end
root_commentable { build(:dummy_resource) }
end
end

factory :comment_vote, class: "Decidim::Comments::CommentVote" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ module Decidim::Comments
it "renders the card" do
html = cell("decidim/comments/comment_activity", action_log).call
expect(html).to have_css(".card__content")
expect(html).to have_content("New comment at #{comment.commentable.title}")
expect(html).to have_content("New comment at #{comment.root_commentable.title}")
expect(html).to have_content(comment.body)
end

context "when the commentable is missing" do
before do
comment.commentable.delete
comment.root_commentable.delete
end

it "does not render" do
expect(described_class.new(action_log)).not_to be_renderable
end
end

context "when the commentable is a comment" do
let!(:comment) { create(:comment, :comment_on_comment) }

it "renders the card" do
html = cell("decidim/comments/comment_activity", action_log).call
expect(html).to have_css(".card__content")
expect(html).to have_content("New comment at #{comment.root_commentable.title}")
expect(html).to have_content(comment.body)
end
end
end
end
end

0 comments on commit a9c71ce

Please sign in to comment.