Removed resaving articles after changing username (#15704)
This commit is contained in:
parent
9f9594ccdc
commit
7511ee1fe2
2 changed files with 37 additions and 4 deletions
|
|
@ -593,10 +593,6 @@ class User < ApplicationRecord
|
|||
|
||||
self.old_old_username = old_username
|
||||
self.old_username = username_was
|
||||
articles.find_each do |article|
|
||||
article.path = article.path.gsub(username_was, username)
|
||||
article.save
|
||||
end
|
||||
end
|
||||
|
||||
def bust_cache
|
||||
|
|
|
|||
|
|
@ -64,6 +64,43 @@ RSpec.describe Users::Update, type: :service do
|
|||
expect(service.errors_as_sentence).to eq "filename too long - the max is 250 characters."
|
||||
end
|
||||
|
||||
context "when changing username" do
|
||||
let(:new_username) { "#{user.username}_changed" }
|
||||
|
||||
it "sets old_username and old_old_username when username was changed" do
|
||||
old_username = user.username
|
||||
old_old_username = user.old_username
|
||||
described_class.call(user, user: { username: new_username })
|
||||
user.reload
|
||||
expect(user.username).to eq(new_username)
|
||||
expect(user.old_username).to eq(old_username)
|
||||
expect(user.old_old_username).to eq(old_old_username)
|
||||
end
|
||||
|
||||
it "changes user's articles path" do
|
||||
article = create(:article, user: user)
|
||||
old_path = article.path
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
described_class.call(user, user: { username: new_username })
|
||||
end
|
||||
article.reload
|
||||
expect(article.path).not_to eq(old_path)
|
||||
expect(article.path).to eq("/#{new_username}/#{article.slug}")
|
||||
end
|
||||
|
||||
# testing against gsub'ing username
|
||||
it "sets the correct article path when its slug contains username" do
|
||||
article = create(:article, user: user, slug: "#{user.username}-hello")
|
||||
old_path = article.path
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
described_class.call(user, user: { username: new_username })
|
||||
end
|
||||
article.reload
|
||||
expect(article.path).not_to eq(old_path)
|
||||
expect(article.path).to eq("/#{new_username}/#{article.slug}")
|
||||
end
|
||||
end
|
||||
|
||||
context "when conditionally resaving articles" do
|
||||
it "enqueues resave articles job when changing username" do
|
||||
sidekiq_assert_resave_article_worker(user) do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue