Skip to content

A platform for community discussion. Free, open, simple.

FIX: Update search index after renaming user within posts

Gerhard Schlager8232aba74339
diff --git a/app/jobs/regular/update_username.rb b/app/jobs/regular/update_username.rb
index 6298a639b1e..f6138c83ba1 100644
--- a/app/jobs/regular/update_username.rb
+++ b/app/jobs/regular/update_username.rb
@@ -24,6 +24,8 @@ module Jobs
# update without running validations and hooks
post.update_columns(raw: post.raw, cooked: post.cooked)
+
+ SearchIndexer.index(post, force: true)
end
end
diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rb
index aaa15af5a01..ad0fac18313 100644
--- a/spec/services/username_changer_spec.rb
+++ b/spec/services/username_changer_spec.rb
@@ -120,6 +120,14 @@ describe UsernameChanger do
expect(post.cooked).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a></p>))
end
+ it 'removes the username from the search index' do
+ SearchIndexer.enable
+ create_post_and_change_username(raw: "Hello @foo")
+
+ results = Search.execute('foo', min_search_term_length: 1)
+ expect(results.posts).to be_empty
+ end
+
it 'ignores case when replacing mentions' do
post = create_post_and_change_username(raw: "There's no difference between @foo and @Foo")