Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mentions not working properly #2947

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ controller or added a new module you need to rename `feature` to `component`.
- **decidim-accountability**: Fix parent results progress [\#2954](https://github.com/decidim/decidim/pull/2954)
- **decidim-core**: Fix `Decidim::UserPresenter#nickname` [\#2958](https://github.com/decidim/decidim/pull/2958)
- **decidim-verifications**: Only show authorizations from current organization [\#2959](https://github.com/decidim/decidim/pull/2959)
- **decidim-comments**: Fix mentions not working properly. [\#2947](https://github.com/decidim/decidim/pull/2947)

Please check [0.10-stable](https://github.com/decidim/decidim/blob/0.10-stable/CHANGELOG.md) for previous changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Comments

resolve lambda { |obj, args, ctx|
params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment], "user_group_id" => args[:userGroupId] } }
form = Decidim::Comments::CommentForm.from_params(params)
form = Decidim::Comments::CommentForm.from_params(params).with_context(current_organization: ctx[:current_organization])
Decidim::Comments::CreateComment.call(form, ctx[:current_user], obj) do
on(:ok) do |comment|
return comment
Expand Down
3 changes: 3 additions & 0 deletions decidim-comments/spec/types/commentable_mutation_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module Comments

it "calls CreateComment command" do
params = { "comment" => { "body" => body, "alignment" => alignment, "user_group_id" => nil } }
context = { current_organization: current_organization }
expect(Decidim::Comments::CommentForm).to receive(:from_params).with(params).and_call_original
expect_any_instance_of(Decidim::Comments::CommentForm) # rubocop:disable RSpec/AnyInstance
.to receive(:with_context).with(context).and_call_original
expect(Decidim::Comments::CreateComment).to receive(:call).with(
an_instance_of(Decidim::Comments::CommentForm),
current_user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,45 @@
end
end
end

describe "mentions" do
before do
visit resource_path

within ".add-comment form" do
fill_in "add-comment-#{commentable.commentable_type}-#{commentable.id}", with: content
click_button "Send"
end
end

context "when mentioning a valid user" do
let!(:mentioned_user) { create(:user, :confirmed, organization: organization) }
let(:content) { "A valid user mention: @#{mentioned_user.nickname}" }

it "replaces the mention with a link to the user's profile" do
expect(page).to have_comment_from(user, "A valid user mention: @#{mentioned_user.nickname}")
expect(page).to have_link "@#{mentioned_user.nickname}", href: "/profiles/#{mentioned_user.nickname}"
end
end

context "when mentioning an existing user outside current organization" do
let!(:mentioned_user) { create(:user, :confirmed, organization: create(:organization)) }
let(:content) { "This text mentions a user outside current organization: @#{mentioned_user.nickname}" }

it "ignores the mention" do
expect(page).to have_comment_from(user, "This text mentions a user outside current organization: @#{mentioned_user.nickname}")
expect(page).not_to have_link "@#{mentioned_user.nickname}"
end
end

context "when mentioning a non valid user" do
let(:content) { "This text mentions a @nonexistent user" }

it "ignores the mention" do
expect(page).to have_comment_from(user, "This text mentions a @nonexistent user")
expect(page).not_to have_link "@nonexistent"
end
end
end
end
end