2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-18 13:39:34 +08:00
|
|
|
RSpec.describe GroupMentionsUpdater do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:post) { Fabricate(:post) }
|
2017-01-18 13:39:34 +08:00
|
|
|
|
2019-03-14 22:47:38 +08:00
|
|
|
before { Jobs.run_immediately! }
|
2018-05-31 15:53:49 +08:00
|
|
|
|
2017-01-18 13:39:34 +08:00
|
|
|
describe ".update" do
|
|
|
|
it "should update valid group mentions" do
|
|
|
|
new_group_name = "awesome_team"
|
|
|
|
old_group_name = "team"
|
|
|
|
|
|
|
|
[
|
|
|
|
["@#{old_group_name} is awesome!", "@#{new_group_name} is awesome!"],
|
|
|
|
["This @#{old_group_name} is awesome!", "This @#{new_group_name} is awesome!"],
|
|
|
|
["Mention us @ @#{old_group_name}", "Mention us @ @#{new_group_name}"],
|
|
|
|
].each do |raw, expected_raw|
|
2018-11-22 16:37:24 +08:00
|
|
|
group =
|
|
|
|
Fabricate(:group, name: old_group_name, mentionable_level: Group::ALIAS_LEVELS[:everyone])
|
|
|
|
|
2017-01-18 13:39:34 +08:00
|
|
|
post.update!(raw: raw)
|
|
|
|
group.update!(name: new_group_name)
|
|
|
|
post.reload
|
|
|
|
|
|
|
|
expect(post.raw_mentions).to eq([new_group_name])
|
|
|
|
expect(post.raw).to eq(expected_raw)
|
|
|
|
|
|
|
|
group.destroy!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not update invalid group mentions" do
|
2018-11-22 16:37:24 +08:00
|
|
|
group = Fabricate(:group, name: "team", mentionable_level: Group::ALIAS_LEVELS[:everyone])
|
|
|
|
|
2017-01-18 13:39:34 +08:00
|
|
|
post.update!(raw: "This is not valid@team.com")
|
|
|
|
|
|
|
|
expect(post.reload.raw_mentions).to eq([])
|
|
|
|
|
|
|
|
group.update!(name: "new_team_name")
|
|
|
|
|
|
|
|
expect(post.reload.raw_mentions).to eq([])
|
|
|
|
end
|
2017-04-04 23:22:39 +08:00
|
|
|
|
|
|
|
it "should ignore validations" do
|
2018-11-22 16:37:24 +08:00
|
|
|
everyone_mention_level = Group::ALIAS_LEVELS[:everyone]
|
|
|
|
|
|
|
|
%w[awesome_team pro_team].each do |name|
|
|
|
|
Fabricate(:group, name: name, mentionable_level: everyone_mention_level)
|
|
|
|
end
|
|
|
|
|
2017-04-04 23:22:39 +08:00
|
|
|
post.update!(raw: "@awesome_team is cool and so is @pro_team")
|
|
|
|
|
|
|
|
SiteSetting.max_mentions_per_post = 1
|
|
|
|
GroupMentionsUpdater.update("cool_team", "awesome_team")
|
|
|
|
|
|
|
|
post.reload
|
|
|
|
expect(post.raw_mentions).to match_array(%w[cool_team pro_team])
|
|
|
|
end
|
2017-01-18 13:39:34 +08:00
|
|
|
end
|
|
|
|
end
|