Skip to content

Commit

Permalink
Add system specs for mentions in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rbngzlv committed Mar 11, 2018
1 parent e0da2b0 commit f157efd
Showing 1 changed file with 40 additions and 0 deletions.
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

0 comments on commit f157efd

Please sign in to comment.