Skip to content

Commit

Permalink
Merge pull request #562 from codeforjapan/update-comments
Browse files Browse the repository at this point in the history
Update decidim-comments v0.27.4
  • Loading branch information
ayuki-joto authored Sep 27, 2023
2 parents 467b8d8 + b99f9e3 commit 8c0ca6f
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 55 deletions.
2 changes: 1 addition & 1 deletion decidim-comments/decidim-comments.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = ["[email protected]", "[email protected]", "[email protected]"]
s.license = "AGPL-3.0"
s.homepage = "https://github.com/decidim/decidim"
s.required_ruby_version = ">= 2.7"
s.required_ruby_version = ">= 3.0"

s.name = "decidim-comments"
s.summary = "Decidim comments module"
Expand Down
22 changes: 11 additions & 11 deletions decidim-comments/spec/commands/create_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Comments

describe "when the form is not valid" do
before do
expect(form).to receive(:invalid?).and_return(true)
allow(form).to receive(:invalid?).and_return(true)
end

it "broadcasts invalid" do
Expand Down Expand Up @@ -49,13 +49,13 @@ module Comments

it "creates a new comment" do
expect(Comment).to receive(:create!).with(
author: author,
{ author: author,
commentable: commentable,
root_commentable: commentable,
body: { en: body },
alignment: alignment,
decidim_user_group_id: user_group_id,
participatory_space: form.current_component.try(:participatory_space)
participatory_space: form.current_component.try(:participatory_space) }
).and_call_original

expect do
Expand All @@ -74,7 +74,7 @@ module Comments
user_group_parser = instance_double("kind of UserGroupParser", groups: [])
parsed_metadata = { user: user_parser, user_group: user_group_parser }
parser = instance_double("kind of parser", rewrite: "whatever", metadata: parsed_metadata)
expect(Decidim::ContentProcessor).to receive(:parse).with(
allow(Decidim::ContentProcessor).to receive(:parse).with(
form.body,
current_organization: form.current_organization
).and_return(parser)
Expand All @@ -86,7 +86,7 @@ module Comments
it "sends the notifications" do
creator_double = instance_double(NewCommentNotificationCreator, create: true)

expect(NewCommentNotificationCreator)
allow(NewCommentNotificationCreator)
.to receive(:new)
.with(kind_of(Comment), [], [])
.and_return(creator_double)
Expand Down Expand Up @@ -121,13 +121,13 @@ module Comments

it "creates a new comment with user mention replaced" do
expect(Comment).to receive(:create!).with(
author: author,
{ author: author,
commentable: commentable,
root_commentable: commentable,
body: { en: Decidim::ContentProcessor.parse(body, parser_context).rewrite },
alignment: alignment,
decidim_user_group_id: user_group_id,
participatory_space: form.current_component.try(:participatory_space)
participatory_space: form.current_component.try(:participatory_space) }
).and_call_original

expect do
Expand All @@ -138,7 +138,7 @@ module Comments
it "sends the notifications" do
creator_double = instance_double(NewCommentNotificationCreator, create: true)

expect(NewCommentNotificationCreator)
allow(NewCommentNotificationCreator)
.to receive(:new)
.with(kind_of(Comment), [mentioned_user], [])
.and_return(creator_double)
Expand All @@ -157,13 +157,13 @@ module Comments

it "creates a new comment with user_group mention replaced" do
expect(Comment).to receive(:create!).with(
author: author,
{ author: author,
commentable: commentable,
root_commentable: commentable,
body: { en: Decidim::ContentProcessor.parse(body, parser_context).rewrite },
alignment: alignment,
decidim_user_group_id: user_group_id,
participatory_space: form.current_component.try(:participatory_space)
participatory_space: form.current_component.try(:participatory_space) }
).and_call_original

expect do
Expand All @@ -174,7 +174,7 @@ module Comments
it "sends the notifications" do
creator_double = instance_double(NewCommentNotificationCreator, create: true)

expect(NewCommentNotificationCreator)
allow(NewCommentNotificationCreator)
.to receive(:new)
.with(kind_of(Comment), [], [mentioned_group])
.and_return(creator_double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module Comments
end

it "tells devise not to reset timeout counter" do
expect(request.env["devise.skip_timeoutable"]).to eq(nil)
expect(request.env["devise.skip_timeoutable"]).to be_nil
get :index, xhr: true, params: { commentable_gid: commentable.to_signed_global_id.to_s }
expect(request.env["devise.skip_timeoutable"]).to eq(true)
expect(request.env["devise.skip_timeoutable"]).to be(true)
end

context "when requested without an XHR request" do
Expand Down Expand Up @@ -81,7 +81,7 @@ module Comments
it "creates the comment" do
expect do
post :create, xhr: true, params: { comment: comment_params }
end.to change { Decidim::Comments::Comment.count }.by(1)
end.to change(Decidim::Comments::Comment, :count).by(1)

expect(comment.body.values.first).to eq("This is a new comment")
expect(comment.alignment).to eq(comment_alignment)
Expand Down Expand Up @@ -122,7 +122,7 @@ module Comments
it "creates the comment with the alignment defined as 1" do
expect do
post :create, xhr: true, params: { comment: comment_params }
end.to change { Decidim::Comments::Comment.count }.by(1)
end.to change(Decidim::Comments::Comment, :count).by(1)

expect(comment.alignment).to eq(comment_alignment)
expect(subject).to render_template(:create)
Expand All @@ -135,7 +135,7 @@ module Comments
it "creates the comment with the alignment defined as -1" do
expect do
post :create, xhr: true, params: { comment: comment_params }
end.to change { Decidim::Comments::Comment.count }.by(1)
end.to change(Decidim::Comments::Comment, :count).by(1)

expect(comment.alignment).to eq(comment_alignment)
expect(subject).to render_template(:create)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ module Comments

describe "email_subject" do
it "is correct" do
expect(subject.email_subject).to eq("There is a new comment by #{CGI.escapeHTML(user_group.name)} in #{resource_title}")
expect(subject.email_subject).to eq("There is a new comment by #{escaped_html(user_group.name)} in #{resource_title}")
end
end

describe "email_intro" do
it "is correct" do
expect(subject.email_intro)
.to eq("The group #{CGI.escapeHTML(user_group.name)} has left a comment in #{resource_title}. You can read it in this page:")
.to eq("The group #{escaped_html(user_group.name)} has left a comment in #{resource_title}. You can read it in this page:")
end
end

describe "email_outro" do
it "is correct" do
expect(subject.email_outro)
.to include("You have received this notification because you are following #{CGI.escapeHTML(user_group.name)}")
.to include("You have received this notification because you are following #{escaped_html(user_group.name)}")
end
end

describe "notification_title" do
it "is correct" do
expect(subject.notification_title)
.to start_with("There is a new comment by <a href=\"#{user_group_path}\">#{CGI.escapeHTML(user_group.name)} @#{user_group.nickname}</a> in")
.to start_with("There is a new comment by <a href=\"#{user_group_path}\">#{escaped_html(user_group.name)} @#{user_group.nickname}</a> in")
expect(subject.notification_title)
.to end_with("<a href=\"#{resource_path}?commentId=#{comment.id}#comment_#{comment.id}\">#{resource_title}</a>.")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:event_name) { "decidim.events.comments.user_group_mentioned" }
let(:ca_comment_content) { "<div><p>Un commentaire pour #{author_link}</p></div>" }
let(:en_comment_content) { "<div><p>Comment mentioning some user group, #{author_link}</p></div>" }
let(:author_link) { "<a class=\"user-mention\" href=\"http://#{organization.host}/profiles/#{group.nickname}\">@#{group.nickname}</a>" }
let(:author_link) { "<a class=\"user-mention\" href=\"http://#{organization.host}:#{Capybara.server_port}/profiles/#{group.nickname}\">@#{group.nickname}</a>" }

let(:extra) do
{
Expand All @@ -23,7 +23,7 @@

let(:parsed_body) { Decidim::ContentProcessor.parse("Comment mentioning some user group, @#{group.nickname}", current_organization: organization) }
let(:parsed_ca_body) { Decidim::ContentProcessor.parse("Un commentaire pour @#{group.nickname}", current_organization: organization) }
let(:body) { { en: parsed_body.rewrite, "machine_translations": { "ca": parsed_ca_body.rewrite } } }
let(:body) { { en: parsed_body.rewrite, machine_translations: { ca: parsed_ca_body.rewrite } } }

it_behaves_like "a comment event"

Expand Down Expand Up @@ -74,7 +74,7 @@
describe "translated notifications" do
let(:en_body) { parsed_body.rewrite }

let(:body) { { en: en_body, "machine_translations": { "ca": parsed_ca_body.rewrite } } }
let(:body) { { en: en_body, machine_translations: { ca: parsed_ca_body.rewrite } } }
let(:participatory_process) { create :participatory_process, organization: organization }
let(:component) { create(:component, participatory_space: participatory_process) }
let(:commentable) { create(:dummy_resource, component: component) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
let(:event_name) { "decidim.events.comments.user_mentioned" }
let(:ca_comment_content) { "<div><p>Un commentaire pour #{author_link}</p></div>" }
let(:en_comment_content) { "<div><p>Comment mentioning some user, #{author_link}</p></div>" }
let(:author_link) { "<a class=\"user-mention\" href=\"http://#{organization.host}/profiles/#{author.nickname}\">@#{author.nickname}</a>" }
let(:author_link) { "<a class=\"user-mention\" href=\"http://#{organization.host}:#{Capybara.server_port}/profiles/#{author.nickname}\">@#{author.nickname}</a>" }
let(:parsed_body) { Decidim::ContentProcessor.parse("Comment mentioning some user, @#{author.nickname}", current_organization: organization) }
let(:parsed_ca_body) { Decidim::ContentProcessor.parse("Un commentaire pour @#{author.nickname}", current_organization: organization) }
let(:body) { { en: parsed_body.rewrite, "machine_translations": { "ca": parsed_ca_body.rewrite } } }
let(:body) { { en: parsed_body.rewrite, machine_translations: { ca: parsed_ca_body.rewrite } } }

let(:participatory_process) { create :participatory_process, organization: organization }
let(:component) { create(:component, participatory_space: participatory_process) }
Expand Down Expand Up @@ -64,7 +64,7 @@
describe "translated notifications" do
let(:en_body) { parsed_body.rewrite }

let(:body) { { en: en_body, "machine_translations": { "ca": parsed_ca_body.rewrite } } }
let(:body) { { en: en_body, machine_translations: { ca: parsed_ca_body.rewrite } } }

let(:participatory_process) { create :participatory_process, organization: organization }
let(:component) { create(:component, participatory_space: participatory_process) }
Expand Down
4 changes: 2 additions & 2 deletions decidim-comments/spec/forms/comment_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Comments
it { is_expected.not_to be_valid }

context "with carriage return characters that cause it to exceed" do
let(:body) { "#{("c" * 500)}\r\n#{("c" * 499)}" }
let(:body) { "#{"c" * 500}\r\n#{"c" * 499}" }

it { is_expected.to be_valid }
end
Expand Down Expand Up @@ -98,7 +98,7 @@ module Comments
let(:settings) { double }

it "returns the organization comments_max_length" do
expect(component).to receive(:settings).and_return(settings)
allow(component).to receive(:settings).and_return(settings)
expect(subject.max_length).to eq(organization.comments_max_length)
end
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/spec/helpers/comments_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Comments

expect(cell).to receive(:to_s)

expect(helper)
allow(helper)
.to receive(:cell)
.with(
"decidim/comments/comments",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Decidim
module Comments
describe CommentSerializer do
let(:comment) { create(:comment) }
let(:subject) { described_class.new(comment) }

subject { described_class.new(comment) }

describe "#serialize" do
it "includes the id" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Decidim
module Comments
describe CommentVoteSerializer do
let(:comment) { create(:comment) }
let(:serialized) { subject.serialize }
let(:resource) { create(:comment_vote, comment: comment) }

let(:subject) { described_class.new(resource) }
let(:serialized) { subject.serialize }
subject { described_class.new(resource) }

describe "#serialize" do
it "includes the id" do
Expand Down
13 changes: 12 additions & 1 deletion decidim-comments/spec/lib/decidim/comments/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
module Decidim
module Comments
describe Export do
let(:subject) { described_class }
subject { described_class }
let!(:component) { create(:component, manifest_name: "dummy") }
let!(:dummy_resources) { create_list(:dummy_resource, 2, component: component) }
let!(:comments) { create_list(:comment, 5, commentable: dummy_resources[1], root_commentable: dummy_resources[1]) }
let!(:other_comments) { create_list(:comment, 5) }
let!(:deleted_comment) { create(:comment, :deleted, commentable: dummy_resources[1], root_commentable: dummy_resources[1]) }
let!(:hidden_comment) { create(:comment, :deleted, commentable: dummy_resources[1], root_commentable: dummy_resources[1]) }
let!(:moderation) { create(:moderation, hidden_at: 6.hours.ago, reportable: hidden_comment) }

describe "#comments_for_resource" do
let(:collection) { subject.comments_for_resource(Decidim::DummyResources::DummyResource, component) }
Expand All @@ -21,6 +24,14 @@ module Comments
it "excludes other comments" do
expect(collection).not_to include(*other_comments)
end

it "excludes deleted comments" do
expect(collection).not_to include(deleted_comment)
end

it "excludes hidden comments" do
expect(collection).not_to include(hidden_comment)
end
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions decidim-comments/spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Comments
end

it "is not valid if its parent is a comment and cannot accept new comments" do
expect(comment.root_commentable).to receive(:accepts_new_comments?).and_return false
allow(comment.root_commentable).to receive(:accepts_new_comments?).and_return false
expect(replies[0]).not_to be_valid
end

Expand Down Expand Up @@ -135,13 +135,14 @@ module Comments
describe "#reported_content_url" do
subject { comment.reported_content_url }

let(:url_format) { "http://%{host}/processes/%{slug}/f/%{component_id}/dummy_resources/%{resource_id}#comment_%{comment_id}" }
let(:url_format) { "http://%{host}:%{port}/processes/%{slug}/f/%{component_id}/dummy_resources/%{resource_id}#comment_%{comment_id}" }

it "returns the resource URL" do
expect(subject).to eq(
format(
url_format,
host: commentable.organization.host,
port: Capybara.server_port,
slug: commentable.participatory_space.slug,
component_id: commentable.component.id,
resource_id: commentable.id,
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/spec/models/seed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Comments
describe Seed do
let(:subject) { Decidim::Comments::Seed }
subject { described_class }

describe "#comments_for(resource)" do
it "creates comments for a page if one is given" do
Expand Down
Loading

0 comments on commit 8c0ca6f

Please sign in to comment.